-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add keyword repeat token filter docs #8149 #8475
Merged
kolchfa-aws
merged 5 commits into
opensearch-project:main
from
AntonEliatra:adding-keyword_repeat-token-filter-docs
Dec 3, 2024
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8088723
add keyword repeat token filter docs #8149
AntonEliatra 8b73d2f
Doc review
kolchfa-aws f7ffb7a
Apply suggestions from code review
kolchfa-aws 2859819
Merge branch 'main' into adding-keyword_repeat-token-filter-docs
kolchfa-aws 2be728b
Merge branch 'main' into adding-keyword_repeat-token-filter-docs
kolchfa-aws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,160 @@ | ||
--- | ||
layout: default | ||
title: Keyword repeat | ||
parent: Token filters | ||
nav_order: 210 | ||
--- | ||
|
||
# Keyword repeat token filter | ||
|
||
The `keyword_repeat` token filter emits the keyword version of a token into a token stream. This filter is typically used when you want to retain both the original token and its modified version after further token transformations, such as stemming or synonym expansion. The duplicated tokens allow the original, unchanged version of the token to remain in the final analysis alongside the modified versions. | ||
|
||
The `keyword_repeat` token filter should be placed before stemming filters. Stemming is not applied to every token, thus you may have duplicate tokens in the same position after stemming. To remove duplicate tokens, use the `remove_duplicates` token filter after the stemmer. | ||
{: .note} | ||
|
||
|
||
## Example | ||
|
||
The following example request creates a new index named `my_index` and configures an analyzer with a `keyword_repeat` filter: | ||
|
||
```json | ||
PUT /my_index | ||
{ | ||
"settings": { | ||
"analysis": { | ||
"filter": { | ||
"my_kstem": { | ||
"type": "kstem" | ||
}, | ||
"my_lowercase": { | ||
"type": "lowercase" | ||
} | ||
}, | ||
"analyzer": { | ||
"my_custom_analyzer": { | ||
"type": "custom", | ||
"tokenizer": "standard", | ||
"filter": [ | ||
"my_lowercase", | ||
"keyword_repeat", | ||
"my_kstem" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
## Generated tokens | ||
|
||
Use the following request to examine the tokens generated using the analyzer: | ||
|
||
```json | ||
POST /my_index/_analyze | ||
{ | ||
"analyzer": "my_custom_analyzer", | ||
"text": "Stopped quickly" | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
The response contains the generated tokens: | ||
|
||
```json | ||
{ | ||
"tokens": [ | ||
{ | ||
"token": "stopped", | ||
"start_offset": 0, | ||
"end_offset": 7, | ||
"type": "<ALPHANUM>", | ||
"position": 0 | ||
}, | ||
{ | ||
"token": "stop", | ||
"start_offset": 0, | ||
"end_offset": 7, | ||
"type": "<ALPHANUM>", | ||
"position": 0 | ||
}, | ||
{ | ||
"token": "quickly", | ||
"start_offset": 8, | ||
"end_offset": 15, | ||
"type": "<ALPHANUM>", | ||
"position": 1 | ||
}, | ||
{ | ||
"token": "quick", | ||
"start_offset": 8, | ||
"end_offset": 15, | ||
"type": "<ALPHANUM>", | ||
"position": 1 | ||
} | ||
] | ||
} | ||
``` | ||
|
||
You can further examine the impact of the `keyword_repeat` token filter by adding the following parameters to the `_analyze` query: | ||
|
||
```json | ||
POST /my_index/_analyze | ||
{ | ||
"analyzer": "my_custom_analyzer", | ||
"text": "Stopped quickly", | ||
"explain": true, | ||
"attributes": "keyword" | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
The response includes detailed information, such as tokenization, filtering, and the application of specific token filters: | ||
|
||
```json | ||
{ | ||
"detail": { | ||
"custom_analyzer": true, | ||
"charfilters": [], | ||
"tokenizer": { | ||
"name": "standard", | ||
"tokens": [ | ||
{"token": "OpenSearch","start_offset": 0,"end_offset": 10,"type": "<ALPHANUM>","position": 0}, | ||
{"token": "helped","start_offset": 11,"end_offset": 17,"type": "<ALPHANUM>","position": 1}, | ||
{"token": "many","start_offset": 18,"end_offset": 22,"type": "<ALPHANUM>","position": 2}, | ||
{"token": "employers","start_offset": 23,"end_offset": 32,"type": "<ALPHANUM>","position": 3} | ||
] | ||
}, | ||
"tokenfilters": [ | ||
{ | ||
"name": "lowercase", | ||
"tokens": [ | ||
{"token": "opensearch","start_offset": 0,"end_offset": 10,"type": "<ALPHANUM>","position": 0}, | ||
{"token": "helped","start_offset": 11,"end_offset": 17,"type": "<ALPHANUM>","position": 1}, | ||
{"token": "many","start_offset": 18,"end_offset": 22,"type": "<ALPHANUM>","position": 2}, | ||
{"token": "employers","start_offset": 23,"end_offset": 32,"type": "<ALPHANUM>","position": 3} | ||
] | ||
}, | ||
{ | ||
"name": "keyword_marker_filter", | ||
"tokens": [ | ||
{"token": "opensearch","start_offset": 0,"end_offset": 10,"type": "<ALPHANUM>","position": 0,"keyword": true}, | ||
{"token": "helped","start_offset": 11,"end_offset": 17,"type": "<ALPHANUM>","position": 1,"keyword": false}, | ||
{"token": "many","start_offset": 18,"end_offset": 22,"type": "<ALPHANUM>","position": 2,"keyword": false}, | ||
{"token": "employers","start_offset": 23,"end_offset": 32,"type": "<ALPHANUM>","position": 3,"keyword": false} | ||
] | ||
}, | ||
{ | ||
"name": "kstem_filter", | ||
"tokens": [ | ||
{"token": "opensearch","start_offset": 0,"end_offset": 10,"type": "<ALPHANUM>","position": 0,"keyword": true}, | ||
{"token": "help","start_offset": 11,"end_offset": 17,"type": "<ALPHANUM>","position": 1,"keyword": false}, | ||
{"token": "many","start_offset": 18,"end_offset": 22,"type": "<ALPHANUM>","position": 2,"keyword": false}, | ||
{"token": "employer","start_offset": 23,"end_offset": 32,"type": "<ALPHANUM>","position": 3,"keyword": false} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 10: Should "outputs" be "emits" (as in index.md)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way is fine; I'll change for consistency.