-
Notifications
You must be signed in to change notification settings - Fork 575
updating standard analyzer docs #9747
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
Open
AntonEliatra
wants to merge
4
commits into
opensearch-project:main
Choose a base branch
from
AntonEliatra:updating-standard-analyzer-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
---|---|---|
|
@@ -7,17 +7,20 @@ | |
|
||
# Standard analyzer | ||
|
||
The `standard` analyzer is the default analyzer used when no other analyzer is specified. It is designed to provide a basic and efficient approach to generic text processing. | ||
The `standard` analyzer is the built-in default analyzer used for general-purpose full-text search in OpenSearch. It is designed to provide consistent, language-agnostic text processing by efficiently breaking down text into searchable terms. | ||
|
||
This analyzer consists of the following tokenizers and token filters: | ||
The `standard` analyzer performs the following operations: | ||
|
||
- `standard` tokenizer: Removes most punctuation and splits text on spaces and other common delimiters. | ||
- `lowercase` token filter: Converts all tokens to lowercase, ensuring case-insensitive matching. | ||
- `stop` token filter: Removes common stopwords, such as "the", "is", and "and", from the tokenized output. | ||
- **Tokenization**: It uses the [`standard`]({{site.url}}{{site.baseurl}}/analyzers/tokenizers/standard/) tokenizer, which splits text into words based on Unicode text segmentation rules, handling spaces, punctuation, and common delimiters. | ||
- **Lowercasing**: It applies the [`lowercase`]({{site.url}}{{site.baseurl}}/analyzers/token-filters/lowercase/) token filter to convert all tokens to lowercase, ensuring consistent matching regardless of input case. | ||
Check failure on line 15 in _analyzers/supported-analyzers/standard.md
|
||
|
||
## Example | ||
This combination makes the `standard` analyzer ideal for indexing a wide range of natural language content without needing language-specific customizations. | ||
|
||
Use the following command to create an index named `my_standard_index` with a `standard` analyzer: | ||
--- | ||
|
||
## Example: Creating an index with the standard analyzer | ||
|
||
You can assign the `standard` analyzer to a text field when creating an index: | ||
|
||
```json | ||
PUT /my_standard_index | ||
|
@@ -26,41 +29,44 @@ | |
"properties": { | ||
"my_field": { | ||
"type": "text", | ||
"analyzer": "standard" | ||
"analyzer": "standard" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
--- | ||
|
||
## Parameters | ||
|
||
You can configure a `standard` analyzer with the following parameters. | ||
The `standard` analyzer supports the following optional parameters: | ||
|
||
Parameter | Required/Optional | Data type | Description | ||
:--- | :--- | :--- | :--- | ||
`max_token_length` | Optional | Integer | Sets the maximum length of the produced token. If this length is exceeded, the token is split into multiple tokens at the length configured in `max_token_length`. Default is `255`. | ||
`stopwords` | Optional | String or list of strings | A string specifying a predefined list of stopwords (such as `_english_`) or an array specifying a custom list of stopwords. Default is `_none_`. | ||
`stopwords_path` | Optional | String | The path (absolute or relative to the config directory) to the file containing a list of stop words. | ||
| Parameter | Data type | Default | Description | | ||
|:----------|:-----|:--------|:------------| | ||
| `max_token_length` | Integer | `255` | Sets the maximum length of a token before it is split. | | ||
| `stopwords` | String or list of strings | None | A list of stopwords or a predefined stopword set like `_english_` to remove during analysis. | | ||
| `stopwords_path` | String | None | Path to a file containing stopwords to be used during analysis. | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you verify once if both |
||
|
||
Use only one of the parameters `stopwords` or `stopwords_path`. If both are used, no error is returned but only `stopwords` parameter is applied. | ||
{: .note} | ||
|
||
## Configuring a custom analyzer | ||
## Example: Analyzer with parameters | ||
|
||
Use the following command to configure an index with a custom analyzer that is equivalent to the `standard` analyzer: | ||
The following example creates index `products` and configures `max_token_length` and `stopwords`: | ||
|
||
```json | ||
PUT /my_custom_index | ||
PUT /animals | ||
{ | ||
"settings": { | ||
"analysis": { | ||
"analyzer": { | ||
"my_custom_analyzer": { | ||
"type": "custom", | ||
"tokenizer": "standard", | ||
"filter": [ | ||
"lowercase", | ||
"stop" | ||
"my_manual_stopwords_analyzer": { | ||
"type": "standard", | ||
"max_token_length": 10, | ||
"stopwords": [ | ||
"the", "is", "and", "but", "an", "a", "it" | ||
] | ||
} | ||
} | ||
|
@@ -70,28 +76,47 @@ | |
``` | ||
{% include copy-curl.html %} | ||
|
||
## Generated tokens | ||
|
||
Use the following request to examine the tokens generated using the analyzer: | ||
Use the following `_analyze` API to see how the `my_manual_stopwords_analyzer` processes text: | ||
|
||
```json | ||
POST /my_custom_index/_analyze | ||
POST /animals/_analyze | ||
{ | ||
"analyzer": "my_custom_analyzer", | ||
"text": "The slow turtle swims away" | ||
"analyzer": "my_manual_stopwords_analyzer", | ||
"text": "The Turtle is Large but it is Slow" | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
The response contains the generated tokens: | ||
The returned tokens are: | ||
|
||
- separated based on spacing | ||
- lowercased | ||
- stopwords removed | ||
|
||
```json | ||
{ | ||
"tokens": [ | ||
{"token": "slow","start_offset": 4,"end_offset": 8,"type": "<ALPHANUM>","position": 1}, | ||
{"token": "turtle","start_offset": 9,"end_offset": 15,"type": "<ALPHANUM>","position": 2}, | ||
{"token": "swims","start_offset": 16,"end_offset": 21,"type": "<ALPHANUM>","position": 3}, | ||
{"token": "away","start_offset": 22,"end_offset": 26,"type": "<ALPHANUM>","position": 4} | ||
{ | ||
"token": "turtle", | ||
"start_offset": 4, | ||
"end_offset": 10, | ||
"type": "<ALPHANUM>", | ||
"position": 1 | ||
}, | ||
{ | ||
"token": "large", | ||
"start_offset": 14, | ||
"end_offset": 19, | ||
"type": "<ALPHANUM>", | ||
"position": 3 | ||
}, | ||
{ | ||
"token": "slow", | ||
"start_offset": 30, | ||
"end_offset": 34, | ||
"type": "<ALPHANUM>", | ||
"position": 7 | ||
} | ||
] | ||
} | ||
``` |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
layout: default | ||
title: Data Types | ||
title: Data types | ||
parent: SQL and PPL | ||
nav_order: 7 | ||
--- | ||
|
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Did we miss adding detail about stop words or is it part of tokenization or lowercasing itself.
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.
@sandeshkr419 but the stop words are not removed in standard analyzer, is that what you mean?