一:准备
1测试数据
2创建es索引,创建lat lon的复合mapping,下面给出案例
3具有空间坐标的数据导入es
4通过es客户端进行查询;下载elasticSearch.js进行请求。
git clone http://www.github.com/lukas-vlcek/elasticsearch-js
二:查询
1按空间不规则面相交查询方式(通过三个或三个以上的空间坐标点形成的面进行查询)【查询该三点形成的面里的所有数据】
{
"query": {
"bool": {
"must": [{"match_all": {}}],
"filter": {
"geo_polygon": {
"location": {
"points": [
{
"lat": 34.0,
"lon": 111.30285940371897
},{
"lat": 28.73792370444459,
"lon": 111.30285940371897
},{
"lat": 34.0,
"lon": 115.30285940371897
},
{
"lat": 28.73792370444459,
"lon": 115.30285940371897
}
]}}}}}}
2有条件的空间相交查询 (查询该三点形成的面里CSRQ字段内容为721670400000的详情)
{
"query": {
"bool": {
"must": [{
"match":{
"CSRQ":"721670400000"
}}],
"filter": {
"geo_polygon": {
"location": {
"points": [
{
"lat": 34.0,
"lon": 111.30285940371897
},
{
"lat": 28.73792370444459,
"lon": 111.30285940371897
},{
"lat": 34.0,
"lon": 115.30285940371897
},
{
"lat": 28.73792370444459,
"lon": 115.30285940371897
}
]
}
}
}
}
}
}
3查询一个区间(查询由三个点组成的该地理空间面20<=HYZK<=21的内容)
{
"query": {
"bool": {
"must": [{ "range":{
"HYZK":{
"gte":"20",
"lte":"21"
}
}
}],
"filter": {
"geo_polygon": {
"location": {
"points": [
{
"lat": 34.0,
"lon": 111.30285940371897
},
{
"lat": 28.73792370444459,
"lon": 111.30285940371897
},{
"lat": 34.0,
"lon": 115.30285940371897
},
{
"lat": 28.73792370444459,
"lon": 115.30285940371897
}
]
}
}
}
}
}
}