gpt4 book ai didi

elasticsearch - 按嵌套的地理距离属性排序

转载 作者:行者123 更新时间:2023-12-03 01:09:49 25 4
gpt4 key购买 nike

我正在尝试使用嵌套的地理位置映射按地理距离对索引进行排序。
这是我的简化映射:

'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
我想按geo_point排序资源(检查每个位置,然后检查位置是否接近给定的lat / lon)

最佳答案

您可以使用function_score实现您的目标。
例如,查询如下:
注意:代码在js中;

"_geo_distance": {
"place.location.geo.coordinates": [
this._geo.lon,
this._geo.lat
],
"order": "asc",
"unit": "km",
"distance_type": "plane"
}
然后在 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类似于:
'function_score': {
"score_mode": "multiply",
'query': {
"dis_max": {
"tie_breaker": 0.7,
"boost": 1.9,
"queries": this._query
},
},
'boost': 0.06,
'boost_mode': 'sum',
}

关于elasticsearch - 按嵌套的地理距离属性排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64676233/

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