diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java index d293199aa5a..75465e2db1a 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java @@ -21,7 +21,6 @@ package org.elasticsearch.index.query; import org.apache.lucene.queryparser.classic.MapperQueryParser; import org.apache.lucene.queryparser.classic.QueryParserSettings; -import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BoostQuery; import org.apache.lucene.search.FuzzyQuery; import org.apache.lucene.search.Query; @@ -92,7 +91,7 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder { @Override @@ -511,6 +512,29 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase 0); + XContentBuilder builder = JsonXContent.contentBuilder(); + builder.startObject(); { + builder.startObject("query_string"); { + builder.field("query", "/[ac]*a[ac]{1,10}/"); + builder.field("default_field", STRING_FIELD_NAME); + builder.field("max_determinized_states", 10); + } + builder.endObject(); + } + builder.endObject(); + + QueryBuilder queryBuilder = new QueryParseContext(createParser(builder)).parseInnerQueryBuilder(); + TooComplexToDeterminizeException e = expectThrows(TooComplexToDeterminizeException.class, + () -> queryBuilder.toQuery(createShardContext())); + assertThat(e.getMessage(), containsString("Determinizing [ac]*")); + assertThat(e.getMessage(), containsString("would result in more than 10 states")); + } + public void testToQueryFuzzyQueryAutoFuzziness() throws Exception { assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0); @@ -784,7 +808,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase