具有模糊性 AUTO 的 Elasticsearch 查询无法按预期工作

标签 elasticsearch fuzzy-search

来自关于模糊性的 Elasticsearch documentation:

AUTO

Generates an edit distance based on the length of the term. Low and high distance arguments may be optionally provided AUTO:[low],[high]. If not specified, the default values are 3 and 6, equivalent to AUTO:3,6 that make for lengths:

0..2 Must match exactly

3..5 One edit allowed

>5 Two edits allowed

但是,当我尝试在搜索查询中指定低距离和高距离参数时,结果不是我所期望的。

我正在使用具有以下索引映射的 Elasticsearch 6.6.0:

{
    "fuzzy_test": {
        "mappings": {
            "_doc": {
                "properties": {
                    "description": {
                       "type": "text"
                    },
                    "id": {
                        "type": "keyword"
                    }
                }
            }
        }
    }
}

插入一个简单的文档:

{
    "id": "1",
    "description": "hello world"
}

以及以下搜索查询:

{
    "size": 10,
    "timeout": "30s",
    "query": {
        "match": {
            "description": {
                "query": "helqo",
                "fuzziness": "AUTO:7,10"
            }
        }
    }
}

我假设 fuzziness:AUTO:7,10 意味着对于长度 <= 6 的输入术语,将只返回完全匹配的文档。但是,这是我的查询结果:

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 0.23014566,
        "hits": [
            {
                "_index": "fuzzy_test",
                "_type": "_doc",
                "_id": "OQtUu2oBABnEwrgM3Ejr",
                "_score": 0.23014566,
                "_source": {
                    "id": "1",
                    "description": "hello world"
                }
            }
        ]
    }
}

最佳答案

这很奇怪,但似乎该错误仅存在于 Elasticsearch 6.6.0 版本中。我已经尝试过 6.4.2 和 6.6.2,它们都工作得很好。

关于具有模糊性 AUTO 的 Elasticsearch 查询无法按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56150332/

相关文章:

elasticsearch - 正则表达式与词组的短语

python - 比 FuzzyWuzzy 更好的方法?

elasticsearch - 模糊性不符合Elasticsearch的预期

java - 将来自不同社交网络的 friend 列表合并到一个列表中的好算法?

elasticsearch - 按别名删除索引

ruby-on-rails - 多模型单索引方法 - 通过轮胎进行 Elasticsearch

elasticsearch - ElasticSearch中的半完全(完全)匹配

elasticsearch - 如何只从数组中获得最佳成绩?

JavaScript/列表.js : Implement a fuzzy search

elasticsearch - Elasticsearch模糊查询-最大编辑不能按预期工作