Skip to content

Commit 02043a2

Browse files
author
Christoph Büscher
authored
[Tests] Fix rare edge case in SimpleQueryStringBuilderTests (#35201)
If the random query string is "now" by accident _and_ we are also not setting some field names to use explicitely, then we can hit the "mapped_date" field from default test setup. This correctly leads to the query being was marked as not cacheable, but we assume and check so later. This change fixes this rare edge case by making sure we don't hit the "date" field in this rare cases. Closes #35183
1 parent 409050e commit 02043a2

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ protected SimpleQueryStringBuilder doCreateTestQueryBuilder() {
104104
fields.put(STRING_FIELD_NAME_2, 2.0f / randomIntBetween(1, 20));
105105
}
106106
}
107+
// special handling if query is "now" and no field specified. This hits the "mapped_date" field which leads to the query not being
108+
// cacheable and trigger later test failures (see https://github.com/elastic/elasticsearch/issues/35183)
109+
if (fieldCount == 0 && result.value().equalsIgnoreCase("now")) {
110+
fields.put(STRING_FIELD_NAME_2, 2.0f / randomIntBetween(1, 20));
111+
}
112+
107113
result.fields(fields);
108114
if (randomBoolean()) {
109115
result.autoGenerateSynonymsPhraseQuery(randomBoolean());

0 commit comments

Comments
 (0)