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)
完成