Skip to content

Commit e5e00ce

Browse files
author
Christoph Büscher
committed
Fix rare failure condition in FieldSortBuilderTests (elastic#74347)
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 elastic#74142
1 parent 90e8716 commit e5e00ce

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;
@@ -599,8 +599,10 @@ public void testIsBottomSortShardDisjoint() throws Exception {
599599
FieldSortBuilder fieldSort = SortBuilders.fieldSort("custom-date");
600600
try (DirectoryReader reader = writer.getReader()) {
601601
SearchExecutionContext context = createMockSearchExecutionContext(new IndexSearcher(reader));
602+
DocValueFormat[] dateValueFormat = new DocValueFormat[] {
603+
context.getFieldType("custom-date").docValueFormat(null, null) };
602604
assertTrue(fieldSort.isBottomSortShardDisjoint(context,
603-
new SearchSortValuesAndFormats(new Object[] { 0L }, new DocValueFormat[] { DocValueFormat.RAW })));
605+
new SearchSortValuesAndFormats(new Object[] { 0L }, dateValueFormat)));
604606
}
605607
for (int i = 0; i < numDocs; i++) {
606608
Document doc = new Document();
@@ -613,27 +615,29 @@ public void testIsBottomSortShardDisjoint() throws Exception {
613615
}
614616
try (DirectoryReader reader = writer.getReader()) {
615617
SearchExecutionContext context = createMockSearchExecutionContext(new IndexSearcher(reader));
618+
DocValueFormat[] dateValueFormat = new DocValueFormat[] {
619+
context.getFieldType("custom-date").docValueFormat(null, null) };
616620
assertFalse(fieldSort.isBottomSortShardDisjoint(context, null));
617621
assertFalse(fieldSort.isBottomSortShardDisjoint(context,
618-
new SearchSortValuesAndFormats(new Object[] { minValue }, new DocValueFormat[] { DocValueFormat.RAW })));
622+
new SearchSortValuesAndFormats(new Object[] { minValue }, dateValueFormat)));
619623
assertTrue(fieldSort.isBottomSortShardDisjoint(context,
620-
new SearchSortValuesAndFormats(new Object[] { minValue-1 }, new DocValueFormat[] { DocValueFormat.RAW })));
624+
new SearchSortValuesAndFormats(new Object[] { minValue-1 }, dateValueFormat)));
621625
assertFalse(fieldSort.isBottomSortShardDisjoint(context,
622-
new SearchSortValuesAndFormats(new Object[] { minValue+1 }, new DocValueFormat[] { DocValueFormat.RAW })));
626+
new SearchSortValuesAndFormats(new Object[] { minValue+1 }, dateValueFormat)));
623627
fieldSort.order(SortOrder.DESC);
624628
assertTrue(fieldSort.isBottomSortShardDisjoint(context,
625-
new SearchSortValuesAndFormats(new Object[] { maxValue+1 }, new DocValueFormat[] { DocValueFormat.RAW })));
629+
new SearchSortValuesAndFormats(new Object[] { maxValue+1 }, dateValueFormat)));
626630
assertFalse(fieldSort.isBottomSortShardDisjoint(context,
627-
new SearchSortValuesAndFormats(new Object[] { maxValue }, new DocValueFormat[] { DocValueFormat.RAW })));
631+
new SearchSortValuesAndFormats(new Object[] { maxValue }, dateValueFormat)));
628632
assertFalse(fieldSort.isBottomSortShardDisjoint(context,
629-
new SearchSortValuesAndFormats(new Object[] { minValue }, new DocValueFormat[] { DocValueFormat.RAW })));
633+
new SearchSortValuesAndFormats(new Object[] { minValue }, dateValueFormat)));
630634
fieldSort.setNestedSort(new NestedSortBuilder("empty"));
631635
assertFalse(fieldSort.isBottomSortShardDisjoint(context,
632-
new SearchSortValuesAndFormats(new Object[] { minValue-1 }, new DocValueFormat[] { DocValueFormat.RAW })));
636+
new SearchSortValuesAndFormats(new Object[] { minValue-1 }, dateValueFormat)));
633637
fieldSort.setNestedSort(null);
634638
fieldSort.missing("100");
635639
assertFalse(fieldSort.isBottomSortShardDisjoint(context,
636-
new SearchSortValuesAndFormats(new Object[] { maxValue+1 }, new DocValueFormat[] { DocValueFormat.RAW })));
640+
new SearchSortValuesAndFormats(new Object[] { maxValue+1 }, dateValueFormat)));
637641
}
638642
}
639643
}

0 commit comments

Comments
 (0)