Link Search Menu Expand Document Documentation Menu

Limit 分词过滤器

limit 分词过滤器用于限制通过分析链的分词数量。

参数

limit 分词过滤器可配置以下参数。

参数 必需/可选 数据类型 描述
max_token_count 可选 整数 要生成的分词的最大数量。默认为 1
consume_all_tokens 可选 布尔型 (专家级设置)使用分词器生成的所有分词,即使结果超出 max_token_count。设置此参数后,输出仍仅包含 max_token_count 指定数量的分词。但是,分词器生成的所有分词都会被处理。默认为 false

示例

以下示例请求创建了一个名为 my_index 的新索引,并配置了一个带有 limit 过滤器的分析器

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
        }
      }
    }
  }
}

生成的词元

使用以下请求检查使用该分析器生成的词元

GET /my_index/_analyze
{
  "analyzer": "three_token_limit",
  "text": "OpenSearch is a powerful and flexible search engine."
}

响应包含生成的词元

{
  "tokens": [
    {
      "token": "OpenSearch",
      "start_offset": 0,
      "end_offset": 10,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "is",
      "start_offset": 11,
      "end_offset": 13,
      "type": "<ALPHANUM>",
      "position": 1
    },
    {
      "token": "a",
      "start_offset": 14,
      "end_offset": 15,
      "type": "<ALPHANUM>",
      "position": 2
    }
  ]
}
剩余 350 字符

有问题?

想要贡献?