写在前面:Elasticsearch提供强大的空间处理功能,本文只是完成了他的空间查询功能
使用工具:elasticsearch_head
1、新建设备type
请求地址:http://10.163.130.220:9200/sbindex/sbtype/_mapping/
请求类型:PUT
所有字段:SBID,SDMC,DZ,ZZJGDM,ZZJGMC,LOCATION,STATE
请求参数:
{
"sbtype": {
"properties": {
"SBID": {
"type": "string",
"index": "not_analyzed"
},
"SDMC": {
"type": "string"
},
"DZ": {
"type": "string"
},
"ZZJGDM": {
"type": "string",
"index": "not_analyzed"
},
"ZZJGMC": {
"type": "string"
},
"LOCATION": {
"type": "geo_point", (格式:y,x)
"lat_lon": true
},
"STATE": {
"type": "integer"
}
}
}
}
2、矩形空间查询(这个版本有个bug,需要改成多边形查询,输入矩形范围即可)
--查询地址:http://10.163.130.220:9200/sbindex/_search/
--请求类型:POST
--矩形
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"geo_polygon": {
"LOCATION": {
"points": [
{
"lat": 27.109278,
"lon": 104.701803
},
{
"lat": 27.109278,
"lon": 104.731691
},
{
"lat": 27.130276,
"lon": 104.731691
},
{
"lat": 27.130276,
"lon": 104.701803
}
]
}
}
}
]
}
}
}
},
"size": 200
}
3、圆形空间查询
{
"query":{
"filtered":{
"filter":{
"bool":{
"must":[
{
"geo_distance":{
"distance":"0.1km",
"LOCATION":{
"lat":27.109278,
"lon":104.701803
}
}
}
]
}
}
}
},
"size":200
}
4、多边形空间查询(点位闭合)
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"geo_polygon": {
"LOCATION": {
"points": [
{
"lat": 27.109278,
"lon": 104.701803
},
{
"lat": 27.109278,
"lon": 104.731691
},
{
"lat": 27.130276,
"lon": 104.731691
},
{
"lat": 27.130276,
"lon": 104.701803
},
{
"lat": 27.109278,
"lon": 104.701803
}
]
}
}
}
]
}
}
}
},
"size": 200
}