elasticsearch 在python代码中实现地理位置范围查询流程

1、建立索引结构,知名location 字段为geo_point

es = Elasticsearch()

data={"mappings":

{"re": {

"properties": {

"location": {

"type": "geo_point"}

}

}

}

}

es.indices.create(index='my_index', body=data, ignore=409)

2、添加数据必须有 location字段为{“lat”:22,"lon":102}形式

es.create(index='my_index', doc_type='re', id=i, ignore=409, body={"name":"xxx","location":{"lat":44.277,"lon":-73.989}})

3、查询;

body = {"query": {

"bool": {

"filter": {

"geo_bounding_box": {

"location": {

"top_left": {

"lat": 53.55,

"lon": 73.66

},

"bottom_right": {

"lat": 3.86,

"lon": 135.230

}

}

}

}

}

}

}

ress=es.search(index='my_index', scroll='1m', body=body,size=100)

 

完成

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值