Elasticsearch2.3.2空间查询

写在前面: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
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值