Skip to content

Commit 573b632

Browse files
author
Christoph Büscher
authored
[Tests] Fix edge case in SimpleQueryStringBuilderTests (#36611)
A previous fix of a similar problem in #35201 wasn't general enough, we also need to catch cases where the randomly generated query string starts with some version of "now" and hits a date field. Closes #36595
1 parent 5fe4c90 commit 573b632

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

server/src/test/java/org/elasticsearch/index/query/SimpleQueryStringBuilderTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
6868

6969
@Override
7070
protected SimpleQueryStringBuilder doCreateTestQueryBuilder() {
71-
SimpleQueryStringBuilder result = new SimpleQueryStringBuilder(randomAlphaOfLengthBetween(1, 10));
71+
String queryText = randomAlphaOfLengthBetween(1, 10);
72+
SimpleQueryStringBuilder result = new SimpleQueryStringBuilder(queryText);
7273
if (randomBoolean()) {
7374
result.analyzeWildcard(randomBoolean());
7475
}
@@ -105,9 +106,9 @@ protected SimpleQueryStringBuilder doCreateTestQueryBuilder() {
105106
fields.put(STRING_FIELD_NAME_2, 2.0f / randomIntBetween(1, 20));
106107
}
107108
}
108-
// special handling if query is "now" and no field specified. This hits the "mapped_date" field which leads to the query not being
109-
// cacheable and trigger later test failures (see https://github.com/elastic/elasticsearch/issues/35183)
110-
if (fieldCount == 0 && result.value().equalsIgnoreCase("now")) {
109+
// special handling if query start with "now" and no field specified. This hits the "mapped_date" field which leads to the query not
110+
// being cacheable and trigger later test failures (see https://github.com/elastic/elasticsearch/issues/35183)
111+
if (fieldCount == 0 && queryText.length() >= 3 && queryText.substring(0,3).equalsIgnoreCase("now")) {
111112
fields.put(STRING_FIELD_NAME_2, 2.0f / randomIntBetween(1, 20));
112113
}
113114

0 commit comments

Comments
 (0)