即使是不成熟的尝试,也胜于胎死腹中的策略。

求个地址位置过滤语法。

匿名 | 发布于2018年04月06日 | 阅读数:1871

小弟新学 ElasticSearch . 有个这样的问题。
某地有很多的餐馆,每个餐馆有他自己本身所在的经纬度,也有其送餐的服务范围。其服务范围目前为圆形,以餐馆自己的经纬度为圆心,每家餐馆可以设定一个半径公里数,作为其服务范围。
那么,作为餐馆的地址经纬度,可以使用 geo_point 来定义,服务范围呢?geo_shape ?
{
"restaurant": {
"mappings": {
"maininfo": {
"properties": {
"res_id": {
"type": "integer"
},
"res_name": {
"type": "text"
},
"location": {
"type": "geo_point"
},
"service_area": {
"type": "geo_shape"
}
}
}
}
}
}
这是我目前的 mapping , 其中的 location 为餐馆的地址,service_area 为服务范围。
这样定义行么?
 
目前定义的餐馆大概是这样。
{
"res_id": 1,
"res_name": "北京饭店",
"location": "39.908742,116.409808",
"service_area": {
"type": "circle",
"coordinates": [
116.409808,
39.908742
],
"radius": "30000m"
},
}
上述描述对么?

现在的问题是,填入数据后,我想查询某个点(同样一个经纬度数据,就是我站的位置,比如[ 39.9086,116.4099]),周边到底有哪些餐馆可以为我服务(在服务范围内)的。那个查询,要怎么写?
已邀请:

yayg2008

赞同来自:

参考https://www.elastic.co/guide/c ... .html,希望有帮助。

JackGe

赞同来自:

查询语句示例{
  "query": {
    "geo_shape": {
            "service_area": {
              "relation": "intersects",
              "shape": {
                "coordinates": [
                  116.409808, 
                  39.908742
                ],
                "type": "point"
              }
            }
          }
  }
}
可以参考http://cwiki.apachecn.org/page ... 05150

要回复问题请先登录注册