【发布时间】:2021-02-16 22:06:36
【问题描述】:
我正在尝试按地理距离对具有嵌套地理点映射的索引进行排序。
这是我的简化映射:
'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 排序的资源(检查每个位置,然后检查位置是否接近给定的纬度/经度)
【问题讨论】:
-
你能添加一些示例文档和预期的搜索结果吗?
-
您得到的结果与您的预期相比如何?
-
我添加了文档示例。我根本没有排序结果...
-
@TotoNaBendo 您希望在什么基础上将结果排序为
A,C,B?如果你想按升序排列,它应该是C,A,B? -
@Bhavya 天哪,我的错误,我更新了排序过滤器
标签: elasticsearch