【发布时间】:2020-03-22 12:56:21
【问题描述】:
我的要求是检查一个特定的 geoPoint 是否落在圆的半径内。
我正在使用 geoShape : circle 来存储位置。我的文件如下:
PUT location_test/doc/1
{
"location" : {
"type" : "circle",
"coordinates" : [73.7769,18.5642],
"radius": "10mi"
}
}
查询如下:
GET location_test/_search
{
"query": {
"bool": {
"must": [
{
"geo_shape": {
"location": {
"shape": {
"type": "point",
"coordinates": [
73.877097,
18.455303
],
"relation": "contains"
}
}
}
}
]
}
}
}
此查询非常适用于单个圆形地理形状。
但是现在我想检查一个特定的 geoPoint 是否落在多个圆的半径内。
我们能不能把我们的文件写成这样:
{
"location": [
{
"type": "circle",
"coordinates": [
73.7769,
18.5642
],
"radius": "10mi"
},
{
"type": "circle",
"coordinates": [
-118.240853,
34.052997
],
"radius": "10mi"
}
]
}
并进行查询以检查 geoPoint 是否落在哪个圆圈中。
或者还有其他方法可以实现吗?
编辑 使用地理点数组对特定地理点的文档进行排序是一种好习惯吗?
Mapping :
{
"mappings": {
"doc": {
"properties": {
"locationPoint": {
"type": "geo_point"
}
}
}
}
}
PUT location_test2/doc/1
{
"locationPoint": ["34.075433, -118.307228","36.336356,-119.304597"]
}
PUT location_test2/doc/2
{
"locationPoint": ["34.075433, -118.307228"]
}
GET location_test2/_search
{
"sort": [
{
"_geo_distance": {
"locationPoint": "34.075433, -118.307228",
"order": "asc"
}
}
]
}
【问题讨论】:
标签: elasticsearch