Skip to content

Commit

Permalink
Use epoch_millis in can_match date range tests (elastic#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 elastic#63692
Closes elastic#77122
  • Loading branch information
dnhatn committed Sep 13, 2021
1 parent 27bf7c7 commit cb123bb
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 cb123bb

Please sign in to comment.