API теста шаблона Grok
Тестирует шаблон Grok на строках текста, см. также Grokking grok.
Запрос
GET _text_structure/test_grok_pattern
POST _text_structure/test_grok_pattern
Описание
API теста шаблона Grok позволяет выполнить шаблон Grok на одной или нескольких строках текста. Оно возвращает соответствие строк шаблону вместе со смещениями и длинами совпадающих подстрок.
Параметры запроса
-
ecs_compatibility - (Необязательный, строка) Режим совместимости с шаблонами Grok, совместимыми с ECS. Используйте этот параметр, чтобы указать, использовать ли шаблоны Grok ECS вместо устаревших, когда структура поиска создаёт шаблон Grok. Допустимые значения —
disabledиv1. Значение по умолчанию —disabled.
Тело запроса
-
grok_pattern - (Обязательный, строка) Шаблон Grok, который нужно запустить на строках текста.
-
text - (Обязательный, массив строк) Строки текста, на которых нужно запустить шаблон Grok.
Примеры
resp = client.text_structure.test_grok_pattern(
grok_pattern="Hello %{WORD:first_name} %{WORD:last_name}",
text=[
"Hello John Doe",
"this does not match"
],
)
print(resp) response = client.text_structure.test_grok_pattern(
body: {
grok_pattern: 'Hello %{WORD:first_name} %{WORD:last_name}',
text: [
'Hello John Doe',
'this does not match'
]
}
)
puts response const response = await client.textStructure.testGrokPattern({
grok_pattern: "Hello %{WORD:first_name} %{WORD:last_name}",
text: ["Hello John Doe", "this does not match"],
});
console.log(response); GET _text_structure/test_grok_pattern
{
"grok_pattern": "Hello %{WORD:first_name} %{WORD:last_name}",
"text": [
"Hello John Doe",
"this does not match"
]
} API возвращает следующий ответ:
{
"matches": [
{
"matched": true,
"fields": {
"first_name": [
{
"match": "John",
"offset": 6,
"length": 4
}
],
"last_name": [
{
"match": "Doe",
"offset": 11,
"length": 3
}
]
}
},
{
"matched": false
}
]
}
© 2023-2025 Elasticsearch
As of September 2024, Elasticsearch is available under a choice of three licenses: the Server Side Public License (SSPL), the Elastic License, or the AGPLv3 (OSI approved).
Elasticsearch and the Elasticsearch logo are trademarks of Elasticsearch B.V., registered in the U.S. and in other countries.
https://www.elastic.co/guide/en/elasticsearch/reference/8.17/test-grok-pattern.html