【问题标题】:Elastic length filter弹性长度过滤器
【发布时间】:2021-07-23 17:46:06
【问题描述】:

我正在尝试利用 ElasticSearch 中的 length 过滤器

https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-length-tokenfilter.html

在提供的示例中,它只是删除了匹配的标记。

但是当我使用它时,它会将标记替换为_

有人遇到过这个问题吗?

我想我可以添加一个字符过滤器。但也许有一些未记录的功能?

例子:

字符串i eat icecream

如果我应用length 过滤器和min = 3, max=10,我得到的令牌是:

_ eat icecream 而不是eat icecream

【问题讨论】:

  • 你能用一个例子来解释你的问题吗?
  • 我用示例编辑了答案

标签: elasticsearch


【解决方案1】:

使用您的字符串 "i eat icecream" 并使用长度标记过滤器对其进行分析,我得到以下结果(在 Elasticsearch 版本 7.x 上测试)

GET /_analyze
{
  "tokenizer": "whitespace",
  "filter": [
    {
      "type": "length",
      "min": 3,
      "max": 10
    }
  ],
  "text": "i eat icecream"
}

生成的令牌是

{
  "tokens": [
    {
      "token": "eat",
      "start_offset": 2,
      "end_offset": 5,
      "type": "word",
      "position": 1
    },
    {
      "token": "icecream",
      "start_offset": 6,
      "end_offset": 14,
      "type": "word",
      "position": 2
    }
  ]
}

【讨论】:

  • @galdikas 您使用的是哪个版本的弹性搜索?你能分享你的索引映射吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多