创建索引
PUT /company-locations
{
"mappings": {
"properties": {
"id":{
"type": "keyword"
},
"name": {
"type": "text"
},
"addressPoint": {
"type": "geo_point"
}
}
}
}
新增数据
- 支持数组和经纬度格式 ```java PUT /company-locations/_doc/1 { “name”: “NetEast”, “addressPoint”: { “lat”: 40.7222, “lon”: 73.989 } }
PUT /company-locations/_doc/3 { “name”: “BaiDu”, “addressPoint”: { “lat”: 40.719, “lon”: 73.983 } } PUT /company-locations/_doc/2 { “name”: “Sina”, “addressPoint”: “40.323,63.784” } PUT /company-locations/_doc/4 { “name”: “Ora”, “addressPoint”: [40.323,87.784] }
<a name="YzQOw"></a>
#### 搜索
```java
# 查询距离内的
GET /company-locations/_search
{
"query": {
"bool": {
"must": [
{
"match_all": {}
}
],
"filter": {
"geo_distance": {
"distance": "100km",
"addressPoint": {
"lat": 40.73,
"lon": 74.1
}
}
}
}
}
}
# 查询某个矩形内的
GET /company-locations/_search
{
"query": {
"bool": {
"must": {
"match_all":{}
},
"filter": {
"geo_bounding_box": {
"addressPoint": {
"top_left": {
"lat": 40.73,
"lon": 71.12
},
"bottom_right": {
"lat": 40.717,
"lon": -73.99
}
}
}
}
}
}
}