Skip to content

Commit 6e9e283

Browse files
authored
Use epoch_millis in can_match date range tests (#77464) (#77631)
There is a known issue in 7.x where a date parameter of a range query can be interpreted as the number of years if no format is provided. This commit always uses epoch_millis format to avoid this issue in CanMatchPreFilterSearchPhaseTests. Relates #63692 Closes #77122
1 parent 7f9a0a4 commit 6e9e283

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

server/src/test/java/org/elasticsearch/action/search/CanMatchPreFilterSearchPhaseTests.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public void testCanMatchFilteringOnCoordinatorThatCanBeSkipped() throws Exceptio
451451
List<Index> regularIndices =
452452
randomList(0, 2, () -> new Index(randomAlphaOfLength(10), UUIDs.base64UUID()));
453453

454-
long indexMinTimestamp = randomLongBetween(0, 5000);
454+
long indexMinTimestamp = randomLongBetween(1000, 5000);
455455
long indexMaxTimestamp = randomLongBetween(indexMinTimestamp, 5000 * 2);
456456
StaticCoordinatorRewriteContextProviderBuilder contextProviderBuilder = new StaticCoordinatorRewriteContextProviderBuilder();
457457
String timestampFieldName = dataStream.getTimeStampField().getName();
@@ -463,7 +463,8 @@ public void testCanMatchFilteringOnCoordinatorThatCanBeSkipped() throws Exceptio
463463
// We query a range outside of the timestamp range covered by both datastream indices
464464
rangeQueryBuilder
465465
.from(indexMaxTimestamp + 1)
466-
.to(indexMaxTimestamp + 2);
466+
.to(indexMaxTimestamp + 2)
467+
.format("epoch_millis");
467468

468469
BoolQueryBuilder queryBuilder = new BoolQueryBuilder()
469470
.filter(rangeQueryBuilder);
@@ -519,7 +520,7 @@ public void testCanMatchFilteringOnCoordinatorParsingFails() throws Exception {
519520
List<Index> regularIndices =
520521
randomList(0, 2, () -> new Index(randomAlphaOfLength(10), UUIDs.base64UUID()));
521522

522-
long indexMinTimestamp = randomLongBetween(0, 5000);
523+
long indexMinTimestamp = randomLongBetween(1000, 5000);
523524
long indexMaxTimestamp = randomLongBetween(indexMinTimestamp, 5000 * 2);
524525
StaticCoordinatorRewriteContextProviderBuilder contextProviderBuilder = new StaticCoordinatorRewriteContextProviderBuilder();
525526
String timestampFieldName = dataStream.getTimeStampField().getName();
@@ -577,7 +578,8 @@ public void testCanMatchFilteringOnCoordinatorThatCanNotBeSkipped() throws Excep
577578
// We query a range within the timestamp range covered by both datastream indices
578579
rangeQueryBuilder
579580
.from(indexMinTimestamp)
580-
.to(indexMaxTimestamp);
581+
.to(indexMaxTimestamp)
582+
.format("epoch_millis");
581583

582584
queryBuilder.filter(rangeQueryBuilder);
583585

@@ -590,7 +592,8 @@ public void testCanMatchFilteringOnCoordinatorThatCanNotBeSkipped() throws Excep
590592
// We query a range outside of the timestamp range covered by both datastream indices
591593
RangeQueryBuilder rangeQueryBuilder = new RangeQueryBuilder(timestampFieldName)
592594
.from(indexMaxTimestamp + 1)
593-
.to(indexMaxTimestamp + 2);
595+
.to(indexMaxTimestamp + 2)
596+
.format("epoch_millis");
594597

595598
TermQueryBuilder termQueryBuilder = new TermQueryBuilder("fake", "value");
596599

0 commit comments

Comments
 (0)