gpt4 book ai didi

elasticsearch - Elasticsearch查询的字段给出结果的子集

转载 作者:行者123 更新时间:2023-12-02 22:31:53 24 4
gpt4 key购买 nike

我是Elasticsearch的新手。这是我的文档的样子:

_source : 
{

"name": "this is my title",
"address" : "1300 S Belmont Road"
"ID= : 54000"
}

当我运行此查询时:

查询1:
"query": {
"filtered": {
"query": {
"query_string": {
"query": "*Belmont*",
"fields": ["name^5", "address^4","ID^3"]
}
},
"filter": {...}
}
}

我得到51个结果

查询2:

但这给出了123个结果:
"query": {
"filtered": {
"query": {
"query_string": {
"query": "*Belmont*",
}
},
"filter": {...}
}
}

为什么我在查询1中的所有字段上都运行查询,为什么查询仍给出不同的结果

映射:

地址和名称均为字符串,且均为“not_analyzed”

最佳答案

这是因为_all field的工作方式。您的第一个查询是在指定的字段中查找*Belmont*,其中特定的分析器采用。它在内部转换为 bool(boolean) 查询,并分别与每个字段匹配。

由于地址是not_analyzed,因此将按原样存储1300 S Belmont Road,但是_all字段将使用标准分析器(例如1300,s和belmont等)使用空格分隔的单词。

The _all field is a special catch-all field which concatenates the values of all of the other fields into one big string, using space as a delimiter, which is then analyzed and indexed, but not stored.



因此您的第二个查询将在 _all字段上运行,并为您提供更多结果。

同样,您的第一个查询 不会"address" : "1300 S Belmont Road"匹配,因为默认情况下,使用 wildcard时它将是 lowercased,因此它将搜索belmont并找不到它。您可以使用 lowercase_expanded_terms更改此行为,该默认情况下为true。试试这个
"query": {
"filtered": {
"query": {
"query_string": {
"query": "*Belmont*",
"fields": ["name^5", "address^4","ID^3"],
"lowercase_expanded_terms" : false
}
},
"filter": {...}
}
}

您可能会获得更多结果,具体取决于您存储名称和地址的方式。

希望这可以帮助!

关于elasticsearch - Elasticsearch查询的字段给出结果的子集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34706611/

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