【问题标题】:Elasticsearch fuzzyness doesn't always matchElasticsearch 模糊性并不总是匹配
【发布时间】:2018-10-01 13:33:51
【问题描述】:

我们将 elasticsearch 用于 globalsearch 和 quicksearch,并具有通用配置。

全局搜索可以搜索多种类型,而快速搜索只能搜索一种类型(这是通用组件使用的)。

quicksearch 应该搜索的类型之一称为workorder。我有几个工单,其中两个是这样存储的:

{
    "_source": {
        "name": "70187"
    }
}

{
    "_source": {
        "name": "60255"
    }
}

但是,我从模糊中得到了一些意想不到的行为:

  • 当我搜索6025时,它可以匹配60255
  • 当我搜索7018 时,它无法匹配70187

我使用这个配置:

{
    "query": {
        "bool": {
            "should": [
                {
                    "multi_match": {
                        "fields": [
                            "name",
                            "last_name",
                            "first_name"
                        ],
                        "fuzziness": 1,
                        "max_expansions": 1,
                        "query": 6025,
                        "type": "most_fields"
                    }
                },
                {
                    "multi_match": {
                        "fields": [
                            "name",
                            "last_name",
                            "first_name"
                        ],
                        "max_expansions": 1,
                        "query": 6025,
                        "type": "most_fields"
                    }
                },
                {
                    "multi_match": {
                        "fields": [
                            "content",
                            "description"
                        ],
                        "max_expansions": 1,
                        "query": 6025,
                        "slop": 5,
                        "type": "best_fields"
                    }
                },
                {
                    "multi_match": {
                        "boost": 15,
                        "fields": [
                            "_id",
                            "reference",
                            "mobilenumber",
                            "phonenumber",
                            "batchnumber",
                            "number"
                        ],
                        "max_expansions": 1,
                        "query": 6025,
                        "type": "best_fields"
                    }
                }
            ]
        }
    }
}

为什么要这样做?我该如何解决?

编辑(1)

我忘了提到我正在运行 ElasticSearch 5.6。

编辑(2)

显然,仅使用我提到的两条记录,我就能很好地找到两个工单。我删除了我正在使用的索引。

在添加另外两个现有工单后,我能够仅用四条记录重现问题。

添加的两条记录是:

{
    "name" : "70186"
}

{
    "name" : "68012"
}

如果很重要,这四个记录的ID是:

  • 70186:9
  • 70187:10
  • 60255:11
  • 68012:12

编辑(3)

重现步骤:https://gist.github.com/DevMcC/fe890dcbcba806da8086c4811a0db776

【问题讨论】:

  • 我复制了您的案例,并通过搜索7018 找到了70187。请随意提供您问题的准确再现,以便我们进一步调查。
  • 啊,这真是太糟糕了。我呃,没有提到我正在运行 ElasticSearch 5.6,在那个版本上仍然能够找到70187? (我会更新我的问题以包括我正在运行的版本)
  • 是的,我可以在 5.6.2 上使用
  • 嘿@Val 我看到编辑#2:D?
  • 不,我可以通过搜索7018 找到7018670187 这两个记录。再次,请提供确切的娱乐步骤,以便我们可以比较苹果和苹果

标签: elasticsearch elasticsearch-5 fuzzy-search


【解决方案1】:

在 Elasticsearch fuzziness 中你应该传递参数

 "prefix_length":1 // 0,1,2...

创建扩展时保持不变的起始字符数。默认为 0。

模糊查询会在指定的编辑距离内创建搜索词的所有可能变体或扩展集。

在你的情况下 -

"fuzziness": 1,
GET /_search
{
  "query": {
    "fuzzy": {
      "user.id": {
        "value": "ki",
        "fuzziness": "AUTO",
        "max_expansions": 50,
        "prefix_length": 0,
        "transpositions": true,
        "rewrite": "constant_score"
      }
    }
  }
}

【讨论】:

    猜你喜欢
    • 2019-05-08
    • 1970-01-01
    • 2011-11-01
    • 2018-03-22
    • 2014-08-13
    • 2018-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多