File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed
main/java/org/elasticsearch/search/sort
test/java/org/elasticsearch/search/sort Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 1+ pr : 130924
2+ summary : Check field data type before casting when applying geo distance sort
3+ area : Search
4+ type : bug
5+ issues :
6+ - 129500
Original file line number Diff line number Diff line change @@ -599,7 +599,13 @@ private IndexGeoPointFieldData fieldData(SearchExecutionContext context) {
599599 throw new IllegalArgumentException ("failed to find mapper for [" + fieldName + "] for geo distance based sort" );
600600 }
601601 }
602- return context .getForField (fieldType , MappedFieldType .FielddataOperation .SEARCH );
602+ IndexFieldData <?> indexFieldData = context .getForField (fieldType , MappedFieldType .FielddataOperation .SEARCH );
603+ if (indexFieldData instanceof IndexGeoPointFieldData ) {
604+ return (IndexGeoPointFieldData ) indexFieldData ;
605+ }
606+ throw new IllegalArgumentException (
607+ "unable to apply geo distance sort to field [" + fieldName + "] of type [" + fieldType .typeName () + "]"
608+ );
603609 }
604610
605611 private Nested nested (SearchExecutionContext context ) throws IOException {
Original file line number Diff line number Diff line change 2323import org .elasticsearch .index .mapper .GeoPointFieldMapper ;
2424import org .elasticsearch .index .mapper .MappedFieldType ;
2525import org .elasticsearch .index .mapper .NestedPathFieldMapper ;
26+ import org .elasticsearch .index .mapper .NumberFieldMapper ;
2627import org .elasticsearch .index .query .GeoValidationMethod ;
2728import org .elasticsearch .index .query .MatchAllQueryBuilder ;
2829import org .elasticsearch .index .query .MatchNoneQueryBuilder ;
@@ -99,6 +100,9 @@ public static GeoDistanceSortBuilder randomGeoDistanceSortBuilder() {
99100
100101 @ Override
101102 protected MappedFieldType provideMappedFieldType (String name ) {
103+ if (name .equals ("double" )) {
104+ return new NumberFieldMapper .NumberFieldType (name , NumberFieldMapper .NumberType .DOUBLE );
105+ }
102106 return new GeoPointFieldMapper .GeoPointFieldType (name );
103107 }
104108
@@ -531,6 +535,12 @@ public void testBuildInvalidPoints() throws IOException {
531535 );
532536 assertEquals ("illegal longitude value [-360.0] for [GeoDistanceSort] for field [fieldName]." , ex .getMessage ());
533537 }
538+ {
539+ GeoDistanceSortBuilder sortBuilder = new GeoDistanceSortBuilder ("double" , 0.0 , 180.0 );
540+ sortBuilder .validation (GeoValidationMethod .STRICT );
541+ IllegalArgumentException ex = expectThrows (IllegalArgumentException .class , () -> sortBuilder .build (searchExecutionContext ));
542+ assertEquals ("unable to apply geo distance sort to field [double] of type [double]" , ex .getMessage ());
543+ }
534544 }
535545
536546 /**
You can’t perform that action at this time.
0 commit comments