From 54c9711a2ce0cc3a4f7bda1ac01df252b0634ee3 Mon Sep 17 00:00:00 2001 From: Anton Rubin Date: Tue, 3 Sep 2024 12:57:03 +0100 Subject: [PATCH] adding limit token filter docs Signed-off-by: Anton Rubin --- _analyzers/token-filters/limit.md | 88 +++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 _analyzers/token-filters/limit.md diff --git a/_analyzers/token-filters/limit.md b/_analyzers/token-filters/limit.md new file mode 100644 index 0000000000..105fa1b407 --- /dev/null +++ b/_analyzers/token-filters/limit.md @@ -0,0 +1,88 @@ +--- +layout: default +title: Limit +parent: Token filters +nav_order: 250 +--- + +# Limit token filter + +The `limit` token filter in OpenSearch is used to limit the number of tokens that are passed through the analysis chain. + +## Parameters + +The `limit` token filter in OpenSearch can be configured with the following parameters: + +- `max_token_count`: Maximum number of tokens that will be generated. Default is `1` (Integer, _Optional_) +- `consume_all_tokens`: Use all token, even if result exceeds `max_token_count`. Default is `false` (Boolean, _Optional_) + + +## Example + +The following example request creates a new index named `my_index` and configures an analyzer with `limit` filter: + +```json +PUT my_index +{ + "settings": { + "analysis": { + "analyzer": { + "three_token_limit": { + "tokenizer": "standard", + "filter": [ "custom_token_limit" ] + } + }, + "filter": { + "custom_token_limit": { + "type": "limit", + "max_token_count": 3 + } + } + } + } +} +``` +{% include copy-curl.html %} + +## Generated tokens + +Use the following request to examine the tokens generated using the created analyzer: + +```json +GET /my_index/_analyze +{ + "analyzer": "three_token_limit", + "text": "OpenSearch is a powerful and flexible search engine." +} +``` +{% include copy-curl.html %} + +The response contains the generated tokens: + +```json +{ + "tokens": [ + { + "token": "OpenSearch", + "start_offset": 0, + "end_offset": 10, + "type": "", + "position": 0 + }, + { + "token": "is", + "start_offset": 11, + "end_offset": 13, + "type": "", + "position": 1 + }, + { + "token": "a", + "start_offset": 14, + "end_offset": 15, + "type": "", + "position": 2 + } + ] +} +```