forked from opensearch-project/documentation-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding flatten-graph token filter docs opensearch-project#8060
Signed-off-by: Anton Rubin <[email protected]>
- Loading branch information
1 parent
9bad864
commit 2ebccb4
Showing
1 changed file
with
106 additions
and
0 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,106 @@ | ||
--- | ||
layout: default | ||
title: Flatten graph | ||
parent: Token filters | ||
nav_order: 150 | ||
--- | ||
|
||
# Flatten graph token filter | ||
|
||
The `flatten_graph` token filter is used to handle complex token relationships that occur when multiple tokens are generated at the same position in a "graph" structure. This is particularly useful for synonym processing or other token alterations where tokens need to be restructured in a simplified format, making it compatible with operations that can’t handle more complex token structures. | ||
|
||
## Example | ||
|
||
The following example request creates a new index named `test_index` and configures an analyzer with a `flatten_graph` filter: | ||
|
||
```json | ||
PUT /test_index | ||
{ | ||
"settings": { | ||
"analysis": { | ||
"analyzer": { | ||
"my_index_analyzer": { | ||
"type": "custom", | ||
"tokenizer": "standard", | ||
"filter": [ | ||
"my_custom_filter", | ||
"flatten_graph" | ||
] | ||
} | ||
}, | ||
"filter": { | ||
"my_custom_filter": { | ||
"type": "word_delimiter_graph", | ||
"catenate_all": true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
## Generated tokens | ||
|
||
Use the following request to examine the tokens generated using the analyzer: | ||
|
||
```json | ||
POST /test_index/_analyze | ||
{ | ||
"analyzer": "my_index_analyzer", | ||
"text": "OpenSearch helped many employers" | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
The response contains the generated tokens: | ||
|
||
```json | ||
{ | ||
"tokens": [ | ||
{ | ||
"token": "OpenSearch", | ||
"start_offset": 0, | ||
"end_offset": 10, | ||
"type": "<ALPHANUM>", | ||
"position": 0, | ||
"positionLength": 2 | ||
}, | ||
{ | ||
"token": "Open", | ||
"start_offset": 0, | ||
"end_offset": 4, | ||
"type": "<ALPHANUM>", | ||
"position": 0 | ||
}, | ||
{ | ||
"token": "Search", | ||
"start_offset": 4, | ||
"end_offset": 10, | ||
"type": "<ALPHANUM>", | ||
"position": 1 | ||
}, | ||
{ | ||
"token": "helped", | ||
"start_offset": 11, | ||
"end_offset": 17, | ||
"type": "<ALPHANUM>", | ||
"position": 2 | ||
}, | ||
{ | ||
"token": "many", | ||
"start_offset": 18, | ||
"end_offset": 22, | ||
"type": "<ALPHANUM>", | ||
"position": 3 | ||
}, | ||
{ | ||
"token": "employers", | ||
"start_offset": 23, | ||
"end_offset": 32, | ||
"type": "<ALPHANUM>", | ||
"position": 4 | ||
} | ||
] | ||
} | ||
``` |