-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Endpoint to test Grok pattern (#104394)
* Add extract match ranges functionality to Grok. * TestGrokPatternAction and Request * TestGrokPattern response * Update docs/changelog/104394.yaml * Polish validation error message * Improve test_grok_pattern API * Add explicit CharSet * Add endpoint to operator constants * Add TransportTestGrokPatternActionTests * REST API spec * One more TransportTestGrokPatternActionTest * Fix API spec * Refactor REST API spec * Polish code * Replace TransportTestGrokPatternActionTests by a YAML REST test * Add ecs_compatibility * Always return arrays in the API * Documentation * YAML test for ecs_compatibility * Rename doc fileø * serverless scope * Fix docs (hopefully) * Update docs/reference/rest-api/index.asciidoc Co-authored-by: István Zoltán Szabó <[email protected]> * Add "text structure APIs" header in docs TOC * Move file * Remove test grok from main index * typo * Nested APIs underneath text structure --------- Co-authored-by: István Zoltán Szabó <[email protected]>
- Loading branch information
1 parent
cf67f5d
commit 5dec83f
Showing
15 changed files
with
614 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 104394 | ||
summary: Endpoint to find positions of Grok pattern matches | ||
area: Machine Learning | ||
type: enhancement | ||
issues: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[role="xpack"] | ||
[[text-structure-apis]] | ||
== Text structure APIs | ||
|
||
You can use the following APIs to find text structures: | ||
|
||
* <<find-structure>> | ||
* <<test-grok-pattern>> | ||
|
||
include::find-structure.asciidoc[leveloffset=+2] | ||
include::test-grok-pattern.asciidoc[leveloffset=+2] |
95 changes: 95 additions & 0 deletions
95
docs/reference/text-structure/apis/test-grok-pattern.asciidoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
[role="xpack"] | ||
[[test-grok-pattern]] | ||
= Test Grok pattern API | ||
|
||
++++ | ||
<titleabbrev>Test Grok pattern</titleabbrev> | ||
++++ | ||
|
||
Tests a Grok pattern on lines of text, see also <<grok,Grokking grok>>. | ||
|
||
[discrete] | ||
[[test-grok-pattern-request]] | ||
== {api-request-title} | ||
|
||
`GET _text_structure/test_grok_pattern` + | ||
|
||
`POST _text_structure/test_grok_pattern` + | ||
|
||
[discrete] | ||
[[test-grok-pattern-desc]] | ||
== {api-description-title} | ||
|
||
The test Grok pattern API allows you to execute a Grok pattern on one | ||
or more lines of text. It returns whether the lines match the pattern | ||
together with the offsets and lengths of the matched substrings. | ||
|
||
[discrete] | ||
[[test-grok-pattern-query-parms]] | ||
== {api-query-parms-title} | ||
|
||
`ecs_compatibility`:: | ||
(Optional, string) The mode of compatibility with ECS compliant Grok patterns. | ||
Use this parameter to specify whether to use ECS Grok patterns instead of | ||
legacy ones when the structure finder creates a Grok pattern. Valid values | ||
are `disabled` and `v1`. The default value is `disabled`. | ||
|
||
[discrete] | ||
[[test-grok-pattern-request-body]] | ||
== {api-request-body-title} | ||
|
||
`grok_pattern`:: | ||
(Required, string) | ||
The Grok pattern to run on the lines of text. | ||
|
||
`text`:: | ||
(Required, array of strings) | ||
The lines of text to run the Grok pattern on. | ||
|
||
[discrete] | ||
[[test-grok-pattern-example]] | ||
== {api-examples-title} | ||
|
||
[source,console] | ||
-------------------------------------------------- | ||
GET _text_structure/test_grok_pattern | ||
{ | ||
"grok_pattern": "Hello %{WORD:first_name} %{WORD:last_name}", | ||
"text": [ | ||
"Hello John Doe", | ||
"this does not match" | ||
] | ||
} | ||
-------------------------------------------------- | ||
|
||
The API returns the following response: | ||
|
||
[source,console-result] | ||
---- | ||
{ | ||
"matches": [ | ||
{ | ||
"matched": true, | ||
"fields": { | ||
"first_name": [ | ||
{ | ||
"match": "John", | ||
"offset": 6, | ||
"length": 4 | ||
} | ||
], | ||
"last_name": [ | ||
{ | ||
"match": "Doe", | ||
"offset": 11, | ||
"length": 3 | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"matched": false | ||
} | ||
] | ||
} | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
rest-api-spec/src/main/resources/rest-api-spec/api/text_structure.test_grok_pattern.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"text_structure.test_grok_pattern": { | ||
"documentation": { | ||
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/test-grok-pattern-api.html", | ||
"description": "Tests a Grok pattern on some text." | ||
}, | ||
"stability": "stable", | ||
"visibility": "public", | ||
"headers": { | ||
"accept": ["application/json"], | ||
"content_type": ["application/json"] | ||
}, | ||
"url": { | ||
"paths": [ | ||
{ | ||
"path": "/_text_structure/test_grok_pattern", | ||
"methods": ["GET", "POST"] | ||
} | ||
] | ||
}, | ||
"params": { | ||
"ecs_compatibility": { | ||
"type": "string", | ||
"description": "Optional parameter to specify the compatibility mode with ECS Grok patterns - may be either 'v1' or 'disabled'" | ||
} | ||
}, | ||
"body": { | ||
"description": "The Grok pattern and text.", | ||
"required": true | ||
} | ||
} | ||
} |
Oops, something went wrong.