There are some similar topic, but I have decided to open new one, as I have found the exact reason of this bug.
While use org.elasticsearch.index.query.FilterBuilders#geoDistanceFilter
FilterBuilders.geoDistanceFilter("locations").distance("100mi")
.lat(-70).lon(40);
It builds incorrect filter (query) according to the documentation, should be [lon, lat], however builder builds [lat,lon]:
...
"geo_distance" : {
"points" : [ -70, 40 ],
"distance" : "100mi"
}
...
Reason:
org.elasticsearch.index.query.GeoDistanceFilterBuilder (lines: 124-126)
} else {
builder.startArray(name).value(lon).value(lat).endArray();
}
Thus it builds array with "name" and values FIRST - lon, SECOND - lat.
org.elasticsearch.common.geo.GeoPoint#resetFromString (lines: 65-74)
public GeoPoint resetFromString(String value) {
int comma = value.indexOf(',');
if (comma != -1) {
lat = Double.parseDouble(value.substring(0, comma).trim());
lon = Double.parseDouble(value.substring(comma + 1).trim());
} else {
resetFromGeoHash(value);
}
return this;
}
It parse string(array) and take values FIRST - lat, SECOND - lon.
Therefore it use incorrect order, as it writes there lon, lat, but reads lat,lon