Link Search Menu Expand Document Documentation Menu

截断标记过滤器

截断标记过滤器用于缩短超出指定长度的标记。它会将标记裁剪到最大字符数,确保超出此限制的标记被截断。

参数

截断标记过滤器可以使用以下参数进行配置。

参数 必需/可选 数据类型 描述
length 可选 整数 指定生成的标记的最大长度。默认为 10

示例

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

PUT /truncate_example
{
  "settings": {
    "analysis": {
      "filter": {
        "truncate_filter": {
          "type": "truncate",
          "length": 5
        }
      },
      "analyzer": {
        "truncate_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "truncate_filter"
          ]
        }
      }
    }
  }
}

生成的词元

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

GET /truncate_example/_analyze
{
  "analyzer": "truncate_analyzer",
  "text": "OpenSearch is powerful and scalable"
}

响应包含生成的词元

{
  "tokens": [
    {
      "token": "opens",
      "start_offset": 0,
      "end_offset": 10,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "is",
      "start_offset": 11,
      "end_offset": 13,
      "type": "<ALPHANUM>",
      "position": 1
    },
    {
      "token": "power",
      "start_offset": 14,
      "end_offset": 22,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "and",
      "start_offset": 23,
      "end_offset": 26,
      "type": "<ALPHANUM>",
      "position": 3
    },
    {
      "token": "scala",
      "start_offset": 27,
      "end_offset": 35,
      "type": "<ALPHANUM>",
      "position": 4
    }
  ]
}
剩余 350 字符

有问题?

想做贡献?