gpt4 book ai didi

elasticsearch - 模糊无法正常运行(一词搜索,请参见示例)

转载 作者:行者123 更新时间:2023-12-03 02:04:22 25 4
gpt4 key购买 nike

考虑以下结果:

curl -XGET 'http://localhost:9200/megacorp/employee/_search' -d 
'{ "query" :
{"match":
{"last_name": "Smith"}
}
}'

结果:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.30685282,
"hits": [
{
"_index": "megacorp",
"_type": "employee",
"_id": "1",
"_score": 0.30685282,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing on the weekends.",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "megacorp",
"_type": "employee",
"_id": "2",
"_score": 0.30685282,
"_source": {
"first_name": "Jane",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
}
]
}
}

现在,当我执行以下查询时:
curl -XGET 'http://localhost:9200/megacorp/employee/_search' -d 
'{ "query" :
{"fuzzy":
{"last_name":
{"value":"Smitt",
"fuzziness": 1
}
}
}
}'

尽管“Smith”和“Smitt”的Levenshtein距离为1,但不会返回任何结果。结果为“Smit”的结果相同。如果我将 fuzziness的值设置为2,则会得到结果。我在这里想念什么?

最佳答案

我假设您要查询的last_name字段是经过分析的字符串。被索引的术语将是smith而不是Smith

Returns NO results despite the Levenshtein distance of "Smith" and "Smitt" being 1.


fuzzy查询不分析项,因此实际上,您的Levenshtein距离不是1而是2:
  • Smitt->史密斯
  • 史密斯->史密斯

  • 尝试使用此映射,并且模糊度= 1的查询将起作用:
    PUT /megacorp/employee/_mapping
    {
    "employee":{
    "properties":{
    "last_name":{
    "type":"string",
    "index":"not_analyzed"
    }
    }
    }
    }

    希望这可以帮助

    关于elasticsearch - 模糊无法正常运行(一词搜索,请参见示例),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28161480/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com