gpt4 book ai didi

带过滤器的 ElasticSearch function_score 查询

转载 作者:行者123 更新时间:2023-11-29 02:50:45 26 4
gpt4 key购买 nike

尝试创建一个搜索,以返回距特定地理点约 500 米的位置结果。

我需要根据位置在源中是否为空来过滤此搜索的结果。

我试过这样的事情:

"filtered" : {
"filter": {
"missing" : { "field" : "location" }
}
}

这是我得到的搜索 JSON:

 {"query": {
"function_score": {
"query": {
"bool": {
"must": [
{
"match": {"fieldA": "value"}
},
{
"match": { "fieldB": "value"}
}
]
}
},
"functions": [{
"gauss": {
"location": {
"origin": "'.$lat.','.$lon.'",
"scale": "500m",
"offset": "0km",
"decay": 0.33
}
}
}]
}
}
}

我尝试将过滤器放在查询中的不同位置,但它对我不起作用,所以我知道我在查询的结构方面做了一些根本性的错误。将来我想添加更多评分逻辑和其他过滤器,但找不到此类查询的好例子。

我应该怎么做才能让它发挥作用?

最佳答案

您可以使用带有 geo_distance 的过滤查询来先过滤掉结果。您还可以在 function_score 中使用“权重”来显式增加“匹配”查询的距离:

{
"query": {
"function_score": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"match": {
"fieldA": "value"
}
},
{
"match": {
"fieldB": "value"
}
}
]
}
},
"filter": {
"geo_distance" : {
"distance" : "500m",
"location" : "'.$lat.','.$lon.'"
}
}
}
},
"functions": [
{
"gauss": {
"location": {
"origin": "'.$lat.','.$lon.'",
"scale": "500m",
"offset": "0km",
"decay": 0.33
}
},
"weight": "3"
}
]
}
}
}

关于带过滤器的 ElasticSearch function_score 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28384970/

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