的解決方案包括使用geo_shape
s指數restraunts文件。您需要到餐廳文檔型號如下:
PUT restaurants
{
"mappings": {
"restaurant": {
"properties": {
"name": {
"type": "text"
},
"location": {
"type": "geo_point"
},
"delivery_area": {
"type": "geo_shape",
"tree": "quadtree",
"precision": "1m"
}
}
}
}
}
然後,您可以索引你的餐館如下:
POST /restaurants/restaurant/1
{
"name": "My Food place",
"location": [-45.0, 45.0], <-- lon, lat !!!
"delivery_area": {
"type": "circle",
"coordinates" : [-45.0, 45.0], <-- lon, lat !!!
"radius" : "10km"
}
}
每家餐廳都將因此與集中在它的位置,並用圓圈形狀有關適當的半徑。
最後,當用戶想要知道哪些餐廳可在她目前的位置交付,您可以發出以下geo_shape
query:
POST /restaurants/_search
{
"query":{
"bool": {
"filter": {
"geo_shape": {
"delivery_area": {
"shape": {
"type": "point",
"coordinates" : [<user_lon>, <user_lat>]
},
"relation": "contains"
}
}
}
}
}
}
在此查詢中,我們檢索的餐館,其delivery_area
形狀包含該用戶當前位於point
。
來源
2017-05-10 13:20:47
Val
距離並不總是10km,這取決於餐廳自己的偏好。 – florind