Geo-distance sorting should use `POSITIVE_INFINITY` for missing geo points instead of `MAX_VALUE`.
This is consistent with the behaviour of geo sorting in Lucene and also numeric fields in Elasticsearch. Closes #20733
This commit is contained in:
parent
dc166c5dc6
commit
059052899f
|
@ -586,11 +586,11 @@ public class GeoDistanceSortBuilder extends SortBuilder<GeoDistanceSortBuilder>
|
||||||
final SortedNumericDoubleValues distanceValues = GeoDistance.distanceValues(geoPointValues, distances);
|
final SortedNumericDoubleValues distanceValues = GeoDistance.distanceValues(geoPointValues, distances);
|
||||||
final NumericDoubleValues selectedValues;
|
final NumericDoubleValues selectedValues;
|
||||||
if (nested == null) {
|
if (nested == null) {
|
||||||
selectedValues = finalSortMode.select(distanceValues, Double.MAX_VALUE);
|
selectedValues = finalSortMode.select(distanceValues, Double.POSITIVE_INFINITY);
|
||||||
} else {
|
} else {
|
||||||
final BitSet rootDocs = nested.rootDocs(context);
|
final BitSet rootDocs = nested.rootDocs(context);
|
||||||
final DocIdSetIterator innerDocs = nested.innerDocs(context);
|
final DocIdSetIterator innerDocs = nested.innerDocs(context);
|
||||||
selectedValues = finalSortMode.select(distanceValues, Double.MAX_VALUE, rootDocs, innerDocs,
|
selectedValues = finalSortMode.select(distanceValues, Double.POSITIVE_INFINITY, rootDocs, innerDocs,
|
||||||
context.reader().maxDoc());
|
context.reader().maxDoc());
|
||||||
}
|
}
|
||||||
return selectedValues.getRawDoubleValues();
|
return selectedValues.getRawDoubleValues();
|
||||||
|
|
|
@ -375,7 +375,7 @@ public class GeoDistanceIT extends ESIntegTestCase {
|
||||||
assertHitCount(searchResponse, 2);
|
assertHitCount(searchResponse, 2);
|
||||||
assertOrderedSearchHits(searchResponse, "1", "2");
|
assertOrderedSearchHits(searchResponse, "1", "2");
|
||||||
assertThat(((Number) searchResponse.getHits().getAt(0).sortValues()[0]).doubleValue(), closeTo(462.1d, 10d));
|
assertThat(((Number) searchResponse.getHits().getAt(0).sortValues()[0]).doubleValue(), closeTo(462.1d, 10d));
|
||||||
assertThat(((Number) searchResponse.getHits().getAt(1).sortValues()[0]).doubleValue(), equalTo(Double.MAX_VALUE));
|
assertThat(((Number) searchResponse.getHits().getAt(1).sortValues()[0]).doubleValue(), equalTo(Double.POSITIVE_INFINITY));
|
||||||
|
|
||||||
// Order: Desc
|
// Order: Desc
|
||||||
searchResponse = client().prepareSearch("test").setQuery(matchAllQuery())
|
searchResponse = client().prepareSearch("test").setQuery(matchAllQuery())
|
||||||
|
@ -385,7 +385,7 @@ public class GeoDistanceIT extends ESIntegTestCase {
|
||||||
// Doc with missing geo point is first, is consistent with 0.20.x
|
// Doc with missing geo point is first, is consistent with 0.20.x
|
||||||
assertHitCount(searchResponse, 2);
|
assertHitCount(searchResponse, 2);
|
||||||
assertOrderedSearchHits(searchResponse, "2", "1");
|
assertOrderedSearchHits(searchResponse, "2", "1");
|
||||||
assertThat(((Number) searchResponse.getHits().getAt(0).sortValues()[0]).doubleValue(), equalTo(Double.MAX_VALUE));
|
assertThat(((Number) searchResponse.getHits().getAt(0).sortValues()[0]).doubleValue(), equalTo(Double.POSITIVE_INFINITY));
|
||||||
assertThat(((Number) searchResponse.getHits().getAt(1).sortValues()[0]).doubleValue(), closeTo(5286d, 10d));
|
assertThat(((Number) searchResponse.getHits().getAt(1).sortValues()[0]).doubleValue(), closeTo(5286d, 10d));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,9 +523,9 @@ public class GeoDistanceIT extends ESIntegTestCase {
|
||||||
assertFirstHit(searchResponse, hasId("4"));
|
assertFirstHit(searchResponse, hasId("4"));
|
||||||
assertSearchHits(searchResponse, "1", "2", "3", "4");
|
assertSearchHits(searchResponse, "1", "2", "3", "4");
|
||||||
assertThat(((Number) searchResponse.getHits().getAt(0).sortValues()[0]).doubleValue(), closeTo(8572.0d, 10d));
|
assertThat(((Number) searchResponse.getHits().getAt(0).sortValues()[0]).doubleValue(), closeTo(8572.0d, 10d));
|
||||||
assertThat(((Number) searchResponse.getHits().getAt(1).sortValues()[0]).doubleValue(), equalTo(Double.MAX_VALUE));
|
assertThat(((Number) searchResponse.getHits().getAt(1).sortValues()[0]).doubleValue(), equalTo(Double.POSITIVE_INFINITY));
|
||||||
assertThat(((Number) searchResponse.getHits().getAt(2).sortValues()[0]).doubleValue(), equalTo(Double.MAX_VALUE));
|
assertThat(((Number) searchResponse.getHits().getAt(2).sortValues()[0]).doubleValue(), equalTo(Double.POSITIVE_INFINITY));
|
||||||
assertThat(((Number) searchResponse.getHits().getAt(3).sortValues()[0]).doubleValue(), equalTo(Double.MAX_VALUE));
|
assertThat(((Number) searchResponse.getHits().getAt(3).sortValues()[0]).doubleValue(), equalTo(Double.POSITIVE_INFINITY));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client().prepareSearch("companies").setQuery(matchAllQuery())
|
client().prepareSearch("companies").setQuery(matchAllQuery())
|
||||||
|
|
Loading…
Reference in New Issue