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 @@ -624,7 +624,13 @@ private IndexGeoPointFieldData fieldData(SearchExecutionContext context) {
624
624
throw new IllegalArgumentException ("failed to find mapper for [" + fieldName + "] for geo distance based sort" );
625
625
}
626
626
}
627
- return context .getForField (fieldType , MappedFieldType .FielddataOperation .SEARCH );
627
+ IndexFieldData <?> indexFieldData = context .getForField (fieldType , MappedFieldType .FielddataOperation .SEARCH );
628
+ if (indexFieldData instanceof IndexGeoPointFieldData ) {
629
+ return (IndexGeoPointFieldData ) indexFieldData ;
630
+ }
631
+ throw new IllegalArgumentException (
632
+ "unable to apply geo distance sort to field [" + fieldName + "] of type [" + fieldType .typeName () + "]"
633
+ );
628
634
}
629
635
630
636
private Nested nested (SearchExecutionContext context ) throws IOException {
Original file line number Diff line number Diff line change 23
23
import org .elasticsearch .index .mapper .GeoPointFieldMapper ;
24
24
import org .elasticsearch .index .mapper .MappedFieldType ;
25
25
import org .elasticsearch .index .mapper .NestedPathFieldMapper ;
26
+ import org .elasticsearch .index .mapper .NumberFieldMapper ;
26
27
import org .elasticsearch .index .query .GeoValidationMethod ;
27
28
import org .elasticsearch .index .query .MatchAllQueryBuilder ;
28
29
import org .elasticsearch .index .query .MatchNoneQueryBuilder ;
@@ -99,6 +100,9 @@ public static GeoDistanceSortBuilder randomGeoDistanceSortBuilder() {
99
100
100
101
@ Override
101
102
protected MappedFieldType provideMappedFieldType (String name ) {
103
+ if (name .equals ("double" )) {
104
+ return new NumberFieldMapper .NumberFieldType (name , NumberFieldMapper .NumberType .DOUBLE );
105
+ }
102
106
return new GeoPointFieldMapper .GeoPointFieldType (name );
103
107
}
104
108
@@ -531,6 +535,12 @@ public void testBuildInvalidPoints() throws IOException {
531
535
);
532
536
assertEquals ("illegal longitude value [-360.0] for [GeoDistanceSort] for field [fieldName]." , ex .getMessage ());
533
537
}
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
+ }
534
544
}
535
545
536
546
/**
You can’t perform that action at this time.
0 commit comments