-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* adding predicate token filter docs #8272 Signed-off-by: Anton Rubin <[email protected]> * Doc review Signed-off-by: Fanit Kolchina <[email protected]> * Apply suggestions from code review Co-authored-by: Nathan Bower <[email protected]> Signed-off-by: kolchfa-aws <[email protected]> --------- Signed-off-by: Anton Rubin <[email protected]> Signed-off-by: Fanit Kolchina <[email protected]> Signed-off-by: kolchfa-aws <[email protected]> Co-authored-by: Fanit Kolchina <[email protected]> Co-authored-by: kolchfa-aws <[email protected]> Co-authored-by: Nathan Bower <[email protected]> (cherry picked from commit 3f6fe1c) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
0e5b6aa
commit 3645c49
Showing
2 changed files
with
83 additions
and
1 deletion.
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
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,82 @@ | ||
--- | ||
layout: default | ||
title: Predicate token filter | ||
parent: Token filters | ||
nav_order: 340 | ||
--- | ||
|
||
# Predicate token filter | ||
|
||
The `predicate_token_filter` evaluates whether tokens should be kept or discarded, depending on the conditions defined in a custom script. The tokens are evaluated in the analysis predicate context. This filter supports only inline Painless scripts. | ||
|
||
## Parameters | ||
|
||
The `predicate_token_filter` has one required parameter: `script`. This parameter provides a condition that is used to evaluate whether the token should be kept. | ||
|
||
## Example | ||
|
||
The following example request creates a new index named `predicate_index` and configures an analyzer with a `predicate_token_filter`. The filter specifies to only output tokens if they are longer than 7 characters: | ||
|
||
```json | ||
PUT /predicate_index | ||
{ | ||
"settings": { | ||
"analysis": { | ||
"filter": { | ||
"my_predicate_filter": { | ||
"type": "predicate_token_filter", | ||
"script": { | ||
"source": "token.term.length() > 7" | ||
} | ||
} | ||
}, | ||
"analyzer": { | ||
"predicate_analyzer": { | ||
"tokenizer": "standard", | ||
"filter": [ | ||
"lowercase", | ||
"my_predicate_filter" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
## Generated tokens | ||
|
||
Use the following request to examine the tokens generated using the analyzer: | ||
|
||
```json | ||
POST /predicate_index/_analyze | ||
{ | ||
"text": "The OpenSearch community is growing rapidly", | ||
"analyzer": "predicate_analyzer" | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
The response contains the generated tokens: | ||
|
||
```json | ||
{ | ||
"tokens": [ | ||
{ | ||
"token": "opensearch", | ||
"start_offset": 4, | ||
"end_offset": 14, | ||
"type": "<ALPHANUM>", | ||
"position": 1 | ||
}, | ||
{ | ||
"token": "community", | ||
"start_offset": 15, | ||
"end_offset": 24, | ||
"type": "<ALPHANUM>", | ||
"position": 2 | ||
} | ||
] | ||
} | ||
``` |