gpt4 book ai didi

elasticsearch - 当使用短语时,elasticsearch查询字符串未执行预期的模糊查询

转载 作者:行者123 更新时间:2023-12-02 22:43:54 26 4
gpt4 key购买 nike

在query_string中为elasticsearch使用一个短语时,我没有得到预期的结果。

假设我有一个标题,“约翰·韦恩去曼哈顿”。我已经用“标准”分析器索引了标题字段,以下是我的查询。带有或不带有模糊指示符(〜)的东西,除非我正确拼写了“John Wayne”,否则它将什么也找不到。没有“john wane”或类似结果。

"query": {

"query_string": {
"fields": ["title^2"],
"query": "\"john wayne\"~1",
"default_operator": "AND",
"phrase_slop": 0,
"minimum_should_match": "100%"
}
}

我试过改变波浪号后的数字以增加模糊性,但仍然没有匹配项。

有任何想法吗?

最佳答案

对短语进行模糊搜索实际上是“邻近”搜索。而不是测量字母之间的levenshtein距离,而是查询中术语之间的接近度。

您的查询应该返回结果,如果是:

"query" : "john wane~1" 

有关差异的更多信息,请参见此处:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_fuzziness

编辑:

这是休闲的具体示例:

创建一些文档
curl -XPUT "http://localhost:9200/test/test/1" -d'
{
"message" : "My best friend is John Wayne, who is yours?"
}'

curl -XPUT "http://localhost:9200/test/test/2" -d'
{
"message" : "My best friend is John Marion Wayne, who is yours?"
}'

curl -XPUT "http://localhost:9200/test/test/3" -d'
{
"message" : "My best friend is John Marion Mitchell Wayne, who is yours?"
}'

样本朴素查询,非词组:
curl -XGET "http://localhost:9200/_search" -d'
{
"query" : {
"query_string": {
"query": "john AND wane~1"
}
}
}'

如何使用跨度进行短语查询。注意,由于未分析术语查询,因此这些术语是小写的。另外,您可以调整跨度斜率以控制每个术语应彼此接近的程度。
curl -XGET "http://localhost:9200/_search" -d'
{
"query" : {
"span_near" : {
"clauses" : [
{ "span_term" : { "message" : "john" } },
{ "span_term" : { "message" : "wayne" } }
],
"slop" : 0,
"in_order" : true
}
}
}'

现在,这里是您正在寻找的真正物品。
curl -XGET "http://localhost:9200/_search" -d'
{
"query" : {
"span_near" : {
"clauses" : [
{
"span_multi" : {
"match" : {
"fuzzy" : {
"message" : {
"value" : "john",
"fuzziness" : "1"
}
}
}
}
},
{
"span_multi" : {
"match" : {
"fuzzy" : {
"message" : {
"value" : "wane",
"fuzziness" : "1"
}
}
}
}
}
],
"slop" : 0,
"in_order" : true
}
}
}'

关于elasticsearch - 当使用短语时,elasticsearch查询字符串未执行预期的模糊查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24334188/

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