【发布时间】:2021-09-21 18:51:51
【问题描述】:
我在 Elasticsearch 中创建了以下索引:
PUT /my-index
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "whitespace",
"filter": ["lowercase", "3_5_edgegrams"]
}
},
"filter": {
"3_5_edgegrams": {
"type": "edge_ngram",
"min_gram": 3,
"max_gram": 10
}
}
}
},
"mappings": {
"properties": {
"name": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}
然后我插入了以下文档:
{
"name": "Nuvus Gro Corp"
}
当我进行以下查询时(我们称之为fuzzy_query):
GET /my-index/_search
{
"query": {
"fuzzy": {
"name": {
"value": "qnuv"
}
}
}
}
我得到了上述文档的匹配项。
当我进行查询时(我们将查询称为match_with_fuzziness):
GET /my-index/_search
{
"query": {
"match": {
"name": {
"query": "qnuv",
"fuzziness": "AUTO"
}
}
}
}
我没有得到匹配。如果我进行以下查询:
GET /my-index/_search
{
"query": {
"match": {
"name": {
"query": "nuvq",
"fuzziness": "AUTO"
}
}
}
}
我又得到了一场比赛。我不明白为什么当我进行match_with_fuzziness 查询时我没有得到任何匹配项。
编辑:我用 Kibana Profiler 分析了查询,根据分析器,match_with_fuzziness 是 SynonymQuery Synonym(name:qnu name:qnuv) 查询,而 fuzzy_query 是 BoostQuery (name:nuv)^0.6666666
【问题讨论】:
标签: elasticsearch string-matching