ES GEO地理空间查询java版
一、半径范围查询
1、设置mapping,类型为geo_point
PUT /my_locations
{
"mappings": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
2、中心点查询半径内匹配点
GET /my_locations/_search
{
"query": {
"bool": {
"must": {
"match_all": {
}
},
"filter": {
"geo_distance": {
"distance": "12km",
"location": {
"lat": 40,
"lon": -70
}
}
}
}
}
}
3、java 代码
......
MultiCondition.GeoDistance geo = multiCondition.getGeoDistance();
GeoDistanceQueryBuilder geoDistanceQueryBuilder = QueryBuilders.geoDistanceQuery(geo.getFieldName())
.point(geo.geoPoint.lat(),geo.geoPoint.getLon())
.distance(geo.getDistance(), DistanceUnit.KILOMETERS)
.geoDistance(GeoDistance.PLANE);
boolQueryBuilder.filter(geoDistanceQueryBuilder);
......
GeoDistanceSortBuilder geoSortBuilder = SortBuilders.geoDistanceSort(geoDistance.getFieldName(), geoDistance.geoPoint.getLat(), geoDistance.geoPoint.ge