【问题标题】:How to add fuzziness to search as you type field in Elasticsearch?如何在 Elasticsearch 中键入字段时为搜索添加模糊性?
【发布时间】:2020-08-28 00:35:15
【问题描述】:

当您在 Elasticsearch 上键入字段类型时,我一直在尝试为我的搜索添加一些模糊性,但从未得到所需的查询。任何人有任何想法来实现这个?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    Fuzzy Query 返回包含与搜索词相似的词的文档,由 Levenshtein 编辑距离测量。

    模糊度参数可以指定为:

    AUTO -- 它根据词条的长度生成一个编辑距离。 长度:

    0..2 -- 必须完全匹配

    3..5 -- 允许一次编辑大于 5 -- 允许两次编辑

    使用索引数据和搜索查询添加工作示例。

    索引数据:

    {
      "title":"product"
    }
    {
      "title":"prodct"
    }
    

    搜索查询:

        {
        "query": {
            "fuzzy": {
                "title": {
                    "value": "prodc",
                    "fuzziness":2,
                    "transpositions":true,
                     "boost": 5
                }
            }
        }
    }
    

    搜索结果:

    "hits": [
      {
        "_index": "test",
        "_type": "_doc",
        "_id": "1",
        "_score": 2.0794415,
        "_source": {
          "title": "product"
        }
      },
      {
        "_index": "test",
        "_type": "_doc",
        "_id": "2",
        "_score": 2.0794415,
        "_source": {
          "title": "produt"
        }
      }
    ]
    

    参考这些博客以获得关于模糊查询的详细解释

    https://www.elastic.co/blog/found-fuzzy-search

    https://qbox.io/blog/elasticsearch-optimization-fuzziness-performance

    更新 1: 参考这个ES official documentation

    fuzziness、prefix_length、max_expansions、rewrite 和 下列术语支持模糊转置参数 用于构造术语查询,但对 从最后一个词构造的前缀查询。

    有一些未解决的问题和讨论链接指出 - 模糊性不适用于 bool_prefix multi_match (search-as-you-type)

    https://github.com/elastic/elasticsearch/issues/56229

    https://discuss.elastic.co/t/fuzziness-not-work-with-bool-prefix-multi-match-search-as-you-type/229602/3

    【讨论】:

    • 将它与新的“搜索即输入”字段结合起来的最佳方式是什么?
    猜你喜欢
    • 1970-01-01
    • 2020-06-14
    • 1970-01-01
    • 2021-03-27
    • 1970-01-01
    • 1970-01-01
    • 2016-07-26
    • 2017-06-18
    • 2016-11-08
    相关资源
    最近更新 更多