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)
完成
最后
以上就是饱满学姐最近收集整理的关于elasticsearch 在python代码中实现地理位置范围查询流程的全部内容,更多相关elasticsearch内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复