ES7.16.2高级搜索之geo_point地理位置(四)

##geo_point地理位置搜索

##索引
PUT my_location
{
  "mappings": {
    "properties": {
      "location":{
        "type": "geo_point"
      }
    }
  }
}

##插入数据
POST my_location/_bulk
{"index":{"_id":2}}
{"text":"上海站","location":{"lat":31.256224,"lon":121.462311}}
{"index":{"_id":3}}
{"text":"五一广场","location":"POINT (121.460186 31.251281)"}
{"index":{"_id":4}}
{"text":"交通公园","location":"31.253531,121.473939"}
{"index":{"_id":5}}
{"text":"万业远景大厦","location":[121.448215,31.26229]}

##根据地理位置查询
GET /my_location/_search
{
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": {
        "geo_bounding_box": {
          "location": {
            "top_left": {
              "lat": 31.265395,
              "lon": 121.444075
            },
            "bottom_right": {
              "lat": 31.253845,
              "lon": 121.468417
            }
          }
        }
      }
    }
  }
}

##根据距离distance搜索
GET my_location/_search
{
  "query": {
    "bool": {
      "must": [
        {"match_all": {}}
      ],
      "filter": [
        {
          "geo_distance": {
            "distance": "2000km",
            "location": {
              "lat": 40.73,
              "lon": -74.1
            }
          }
        }
      ]
    }
  }
}

##基础地理位置进行聚合分析
##如0~100m有几个酒店
##100~300m有几个酒店
GET my_location/_search
{
  "size": 0,
  "aggs": {
    "aggs_by_distance": {
      "geo_distance": {
        "field": "location",
        "origin": {
          "lat": 31.3,
          "lon": 121.4
        },
        "unit": "km",
        "distance_type": "plane", 
        "ranges": [
          {
            "from": 0,
            "to": 5
          },
          {
            "from": 5,
            "to": 10
          },
          {
            "from": 10,
            "to": 100
          }
        ]
      }
    }
  }
}

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值