Skip to content

Commit 98572f6

Browse files
author
Christoph Büscher
authored
Fix rare failure condition in FieldSortBuilderTests (#74347) (#74356)
Under rare randomization conditions, the mininum values used in FieldSortBuilderTests#testIsBottomSortShardDisjoint can currently be missintepreted and parsed as years by the date parser that is called deeper down in DateFieldMapper#isFieldWithinQuery. In practice this cannot happen because `isBottomSortShardDisjoint` uses the formatted sort values for a date field, which are string values and don't cause this kind of error. This PR fixes that in the test setup. Closes #74142
1 parent 1d277b8 commit 98572f6

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

server/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
import org.elasticsearch.index.query.QueryBuilder;
4646
import org.elasticsearch.index.query.QueryBuilders;
4747
import org.elasticsearch.index.query.QueryRewriteContext;
48-
import org.elasticsearch.index.query.SearchExecutionContext;
4948
import org.elasticsearch.index.query.QueryShardException;
5049
import org.elasticsearch.index.query.RangeQueryBuilder;
50+
import org.elasticsearch.index.query.SearchExecutionContext;
5151
import org.elasticsearch.search.DocValueFormat;
5252
import org.elasticsearch.search.MultiValueMode;
5353
import org.elasticsearch.search.SearchSortValuesAndFormats;
@@ -636,8 +636,10 @@ public void testIsBottomSortShardDisjoint() throws Exception {
636636
FieldSortBuilder fieldSort = SortBuilders.fieldSort("custom-date");
637637
try (DirectoryReader reader = writer.getReader()) {
638638
SearchExecutionContext context = createMockSearchExecutionContext(new IndexSearcher(reader));
639+
DocValueFormat[] dateValueFormat = new DocValueFormat[] {
640+
context.getFieldType("custom-date").docValueFormat(null, null) };
639641
assertTrue(fieldSort.isBottomSortShardDisjoint(context,
640-
new SearchSortValuesAndFormats(new Object[] { 0L }, new DocValueFormat[] { DocValueFormat.RAW })));
642+
new SearchSortValuesAndFormats(new Object[] { 0L }, dateValueFormat)));
641643
}
642644
for (int i = 0; i < numDocs; i++) {
643645
Document doc = new Document();
@@ -650,27 +652,29 @@ public void testIsBottomSortShardDisjoint() throws Exception {
650652
}
651653
try (DirectoryReader reader = writer.getReader()) {
652654
SearchExecutionContext context = createMockSearchExecutionContext(new IndexSearcher(reader));
655+
DocValueFormat[] dateValueFormat = new DocValueFormat[] {
656+
context.getFieldType("custom-date").docValueFormat(null, null) };
653657
assertFalse(fieldSort.isBottomSortShardDisjoint(context, null));
654658
assertFalse(fieldSort.isBottomSortShardDisjoint(context,
655-
new SearchSortValuesAndFormats(new Object[] { minValue }, new DocValueFormat[] { DocValueFormat.RAW })));
659+
new SearchSortValuesAndFormats(new Object[] { minValue }, dateValueFormat)));
656660
assertTrue(fieldSort.isBottomSortShardDisjoint(context,
657-
new SearchSortValuesAndFormats(new Object[] { minValue-1 }, new DocValueFormat[] { DocValueFormat.RAW })));
661+
new SearchSortValuesAndFormats(new Object[] { minValue-1 }, dateValueFormat)));
658662
assertFalse(fieldSort.isBottomSortShardDisjoint(context,
659-
new SearchSortValuesAndFormats(new Object[] { minValue+1 }, new DocValueFormat[] { DocValueFormat.RAW })));
663+
new SearchSortValuesAndFormats(new Object[] { minValue+1 }, dateValueFormat)));
660664
fieldSort.order(SortOrder.DESC);
661665
assertTrue(fieldSort.isBottomSortShardDisjoint(context,
662-
new SearchSortValuesAndFormats(new Object[] { maxValue+1 }, new DocValueFormat[] { DocValueFormat.RAW })));
666+
new SearchSortValuesAndFormats(new Object[] { maxValue+1 }, dateValueFormat)));
663667
assertFalse(fieldSort.isBottomSortShardDisjoint(context,
664-
new SearchSortValuesAndFormats(new Object[] { maxValue }, new DocValueFormat[] { DocValueFormat.RAW })));
668+
new SearchSortValuesAndFormats(new Object[] { maxValue }, dateValueFormat)));
665669
assertFalse(fieldSort.isBottomSortShardDisjoint(context,
666-
new SearchSortValuesAndFormats(new Object[] { minValue }, new DocValueFormat[] { DocValueFormat.RAW })));
670+
new SearchSortValuesAndFormats(new Object[] { minValue }, dateValueFormat)));
667671
fieldSort.setNestedSort(new NestedSortBuilder("empty"));
668672
assertFalse(fieldSort.isBottomSortShardDisjoint(context,
669-
new SearchSortValuesAndFormats(new Object[] { minValue-1 }, new DocValueFormat[] { DocValueFormat.RAW })));
673+
new SearchSortValuesAndFormats(new Object[] { minValue-1 }, dateValueFormat)));
670674
fieldSort.setNestedSort(null);
671675
fieldSort.missing("100");
672676
assertFalse(fieldSort.isBottomSortShardDisjoint(context,
673-
new SearchSortValuesAndFormats(new Object[] { maxValue+1 }, new DocValueFormat[] { DocValueFormat.RAW })));
677+
new SearchSortValuesAndFormats(new Object[] { maxValue+1 }, dateValueFormat)));
674678
}
675679
}
676680
}

0 commit comments

Comments
 (0)