我正在尝试按地理距离排序带有嵌套地理点Map的索引。
以下是我的简化Map:
'organizations' => [
'_doc' => [
'properties' => [
'locations' => [
'type' => 'nested',
'properties' => [
'point' => [
'type' => 'geo_point',
'ignore_malformed' => true
]
]
]
]
]
]
在这里,每个组织可以有多个地点。
文件:
PUT /organizations ,
[
{
name: "A",
locations: [
{
point: {
lat: 1.5,
lon: 2
}
},
{
point: {
lat: 1,
lon: 0
}
}
]
},
{
name: "B",
locations: [
{
point: {
lat: 4.2,
lon: 3
}
}
]
},
{
name: "C",
locations: [
{
point: {
lat: 0.4,
lon: 1
}
}
]
}
];
下面是我的查询(php数组):
[
"query" => [
"query_string" => [
"query" => "*"
]
]
"sort" => [
0 => [
"_geo_distance" => [
"locations.point" => "1, 0.1"
"order" => "asc"
"unit" => "km"
"nested_path" => "locations"
]
]
]
]
预期结果:
1 => name : A
2 => name : C
3 => bame : B
我想按地理位置获取资源(检查每个位置,然后检查位置是否接近给定的纬度/经度)
1条答案
按热度按时间pokxtpni1#
你可以使用
function_score
.例如,查询如下:
注:代码在
js
;然后在
function_score
添加script_score
```function_score["script_score"] = {
"script": {
"source":
1000/doc['place.location.geo.coordinates'].planeDistance(${this._geo.lat},${this._geo.lon})
}
'function_score': {
"score_mode": "multiply",
'query': {
"dis_max": {
"tie_breaker": 0.7,
"boost": 1.9,
"queries": this._query
},
},
'boost': 0.06,
'boost_mode': 'sum',
}