Skip to content

Commit

Permalink
Use epoch_millis in can_match date range tests (#77464)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dnhatn authored Sep 10, 2021
1 parent bbd8d46 commit c6700d7
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public void testCanMatchFilteringOnCoordinatorThatCanBeSkipped() throws Exceptio
List<Index> regularIndices =
randomList(0, 2, () -> new Index(randomAlphaOfLength(10), UUIDs.base64UUID()));

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

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

long indexMinTimestamp = randomLongBetween(0, 5000);
long indexMinTimestamp = randomLongBetween(1000, 5000);
long indexMaxTimestamp = randomLongBetween(indexMinTimestamp, 5000 * 2);
StaticCoordinatorRewriteContextProviderBuilder contextProviderBuilder = new StaticCoordinatorRewriteContextProviderBuilder();
String timestampFieldName = dataStream.getTimeStampField().getName();
Expand Down Expand Up @@ -577,7 +578,8 @@ public void testCanMatchFilteringOnCoordinatorThatCanNotBeSkipped() throws Excep
// We query a range within the timestamp range covered by both datastream indices
rangeQueryBuilder
.from(indexMinTimestamp)
.to(indexMaxTimestamp);
.to(indexMaxTimestamp)
.format("epoch_millis");

queryBuilder.filter(rangeQueryBuilder);

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

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

Expand Down

0 comments on commit c6700d7

Please sign in to comment.