尝试创建一个搜索,该搜索将返回距离某个地理位置约500米的位置结果.
我需要根据源中的位置是否为空来过滤此搜索的结果.
我尝试过这样的事情:
"filtered" : {
"filter": {
"missing" : { "field" : "location" }
}
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的搜索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
}
}
}]
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试将过滤器放在查询的不同位置,但它对我不起作用,所以我知道我正在做一些从根本上错误的查询结构.在将来我想添加更多的评分逻辑和其他过滤器,但找不到这样的查询的好例子.
我该怎么做才能让它发挥作用?
Duc*_*ong 17
您可以使用带有geo_distance的过滤查询来首先过滤掉结果.您还可以在function_score中使用"weight"来显式提升"匹配"查询的距离:
{
"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"
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6812 次 |
| 最近记录: |