【问题标题】:Space handling in Elastic SearchElastic Search 中的空间处理
【发布时间】:2020-12-31 18:52:37
【问题描述】:

如果我正在搜索的文档(例如商家名称)中没有空格,并且用户通过在其中添加空格进行搜索,则结果不会显示在弹性搜索中。如何改进以获得结果? 例如: 商户名称为“DeliBites” 用户通过输入“Deli Bites”进行搜索,则上述商家不会出现在结果中。只有当我只输入“Deli”或“Deli”后跟空格或“Deli”时,商家才会出现在建议中。

【问题讨论】:

  • 已经有一段时间了,如果您可以投票并接受有帮助的答案,那就太好了。
  • 已经有一段时间了,如果您可以投票并接受有帮助的答案,那就太好了。

标签: elasticsearch whitespace


【解决方案1】:

添加另一个选项,您还可以使用edge n-gram tokenizer,它在大多数情况下都可以使用,它易于设置和使用。

关于您的数据的工作示例

索引定义

{
  "settings": {
    "analysis": {
      "filter": {
        "autocomplete_filter": {
          "type": "ngram",
          "min_gram": 1,
          "max_gram": 10
        }
      },
      "analyzer": {
        "autocomplete": { 
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "autocomplete_filter"
          ]
        }
      }
    },
    "index.max_ngram_diff" : 10
  },
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "autocomplete", 
        "search_analyzer": "standard" 
      }
    }
  }
}

索引示例文档

{
    "title" : "DeliBites"
}

搜索查询

{
    "query": {
        "match": {
            "title": {
                "query": "Deli Bites"
            }
        }
    }
}

以及搜索结果

 "hits": [
            {
                "_index": "65489013",
                "_type": "_doc",
                "_id": "1",
                "_score": 0.95894027,
                "_source": {
                    "title": "DeliBites"
                }
            }
        ]

【讨论】:

    【解决方案2】:

    我建议使用同义词标记过滤器。

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

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

    您应该有一本字典,可以包含您要搜索的所有单词。 像这样:

    DelitBites => 熟食

    ipod => i pod

    在实施同义词之前,请确保您了解它的所有方面。

    https://www.elastic.co/blog/boosting-the-power-of-elasticsearch-with-synonyms

    【讨论】:

      猜你喜欢
      • 2020-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-18
      • 1970-01-01
      • 2022-07-11
      • 2017-06-11
      • 2019-09-11
      相关资源
      最近更新 更多