尝试创建一个搜索,该搜索将带回距某些地理位置约500m的位置结果。
我需要根据源中的位置是否为空来过滤此搜索的结果。
我尝试过这样的事情:
"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"
}
]
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句