diff --git a/docs/reference/query-dsl/prefix-query.asciidoc b/docs/reference/query-dsl/prefix-query.asciidoc index e168bb4de0d..9d28dfb6b42 100644 --- a/docs/reference/query-dsl/prefix-query.asciidoc +++ b/docs/reference/query-dsl/prefix-query.asciidoc @@ -43,7 +43,8 @@ information, see the <>. `case_insensitive`:: (Optional, boolean) allows ASCII case insensitive matching of the -value with the indexed field values when set to true. Setting to false is disallowed. +value with the indexed field values when set to true. Default is false which means +the case sensitivity of matching depends on the underlying field's mapping. [[prefix-query-notes]] ==== Notes diff --git a/docs/reference/query-dsl/regexp-query.asciidoc b/docs/reference/query-dsl/regexp-query.asciidoc index a0ead3ea9df..c50207299f2 100644 --- a/docs/reference/query-dsl/regexp-query.asciidoc +++ b/docs/reference/query-dsl/regexp-query.asciidoc @@ -70,7 +70,8 @@ expression syntax>>. `case_insensitive`:: (Optional, boolean) allows case insensitive matching of the regular expression -value with the indexed field values when set to true. Setting to false is disallowed. +value with the indexed field values when set to true. Default is false which means +the case sensitivity of matching depends on the underlying field's mapping. `max_determinized_states`:: + diff --git a/docs/reference/query-dsl/term-query.asciidoc b/docs/reference/query-dsl/term-query.asciidoc index dc2de433258..1a2626f937b 100644 --- a/docs/reference/query-dsl/term-query.asciidoc +++ b/docs/reference/query-dsl/term-query.asciidoc @@ -64,7 +64,8 @@ increases the relevance score. `case_insensitive`:: (Optional, boolean) allows ASCII case insensitive matching of the -value with the indexed field values when set to true. Setting to false is disallowed. +value with the indexed field values when set to true. Default is false which means +the case sensitivity of matching depends on the underlying field's mapping [[term-query-notes]] ==== Notes diff --git a/docs/reference/query-dsl/wildcard-query.asciidoc b/docs/reference/query-dsl/wildcard-query.asciidoc index 8d3c0f2630a..56daf53e120 100644 --- a/docs/reference/query-dsl/wildcard-query.asciidoc +++ b/docs/reference/query-dsl/wildcard-query.asciidoc @@ -71,7 +71,8 @@ increases the relevance score. `case_insensitive`:: (Optional, boolean) allows case insensitive matching of the -pattern with the indexed field values when set to true. Setting to false is disallowed. +pattern with the indexed field values when set to true. Default is false which means +the case sensitivity of matching depends on the underlying field's mapping. [[wildcard-query-notes]] ==== Notes diff --git a/server/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java index cd45c0dc10a..317f60c3361 100644 --- a/server/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java @@ -107,18 +107,15 @@ public class PrefixQueryBuilder extends AbstractQueryBuilder public String value() { return this.value; } - + public PrefixQueryBuilder caseInsensitive(boolean caseInsensitive) { - if (caseInsensitive == false) { - throw new IllegalArgumentException("The case insensitive setting cannot be set to false."); - } this.caseInsensitive = caseInsensitive; return this; - } + } public boolean caseInsensitive() { return this.caseInsensitive; - } + } public PrefixQueryBuilder rewrite(String rewrite) { this.rewrite = rewrite; @@ -175,10 +172,6 @@ public class PrefixQueryBuilder extends AbstractQueryBuilder rewrite = parser.textOrNull(); } else if (CASE_INSENSITIVE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { caseInsensitive = parser.booleanValue(); - if (caseInsensitive == false) { - throw new ParsingException(parser.getTokenLocation(), - "[prefix] query does not support [" + currentFieldName + "] = false"); - } } else { throw new ParsingException(parser.getTokenLocation(), "[prefix] query does not support [" + currentFieldName + "]"); @@ -192,21 +185,18 @@ public class PrefixQueryBuilder extends AbstractQueryBuilder } } - PrefixQueryBuilder result = new PrefixQueryBuilder(fieldName, value) + return new PrefixQueryBuilder(fieldName, value) .rewrite(rewrite) .boost(boost) - .queryName(queryName); - if (caseInsensitive) { - result.caseInsensitive(caseInsensitive); - } - return result; + .queryName(queryName) + .caseInsensitive(caseInsensitive); } @Override public String getWriteableName() { return NAME; } - + @Override protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws IOException { QueryShardContext context = queryRewriteContext.convertToShardContext(); diff --git a/server/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java index 3cf1935801e..565997246ae 100644 --- a/server/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java @@ -154,9 +154,6 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder } public RegexpQueryBuilder caseInsensitive(boolean caseInsensitive) { - if (caseInsensitive == false) { - throw new IllegalArgumentException("The case insensitive setting cannot be set to false."); - } this.caseInsensitive = caseInsensitive; return this; } @@ -240,10 +237,6 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder flagsValue = parser.intValue(); } else if (CASE_INSENSITIVE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { caseInsensitive = parser.booleanValue(); - if (caseInsensitive == false) { - throw new ParsingException(parser.getTokenLocation(), - "[regexp] query does not support [" + currentFieldName + "] = false"); - } } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { queryName = parser.text(); } else { @@ -265,9 +258,7 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder .rewrite(rewrite) .boost(boost) .queryName(queryName); - if (caseInsensitive) { - result.caseInsensitive(caseInsensitive); - } + result.caseInsensitive(caseInsensitive); return result; } diff --git a/server/src/main/java/org/elasticsearch/index/query/TermQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/TermQueryBuilder.java index e1ff338f401..c632494e805 100644 --- a/server/src/main/java/org/elasticsearch/index/query/TermQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/TermQueryBuilder.java @@ -87,9 +87,6 @@ public class TermQueryBuilder extends BaseTermQueryBuilder { } public TermQueryBuilder caseInsensitive(boolean caseInsensitive) { - if (caseInsensitive == false) { - throw new IllegalArgumentException("The case insensitive setting cannot be set to false."); - } this.caseInsensitive = caseInsensitive; return this; } @@ -144,10 +141,6 @@ public class TermQueryBuilder extends BaseTermQueryBuilder { boost = parser.floatValue(); } else if (CASE_INSENSITIVE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { caseInsensitive = parser.booleanValue(); - if (caseInsensitive == false) { - throw new ParsingException(parser.getTokenLocation(), - "[term] query does not support [" + currentFieldName + "] = false"); - } } else { throw new ParsingException(parser.getTokenLocation(), "[term] query does not support [" + currentFieldName + "]"); @@ -168,9 +161,7 @@ public class TermQueryBuilder extends BaseTermQueryBuilder { if (queryName != null) { termQuery.queryName(queryName); } - if (caseInsensitive) { - termQuery.caseInsensitive(caseInsensitive); - } + termQuery.caseInsensitive(caseInsensitive); return termQuery; } diff --git a/server/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java index 4b309bd880a..c3fff751f81 100644 --- a/server/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java @@ -126,18 +126,15 @@ public class WildcardQueryBuilder extends AbstractQueryBuilder parseQuery(shortJson)); assertEquals("[regexp] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage()); } - - public void testParseFailsWithCaseSensitive() throws IOException { - String json = - "{\n" + - " \"regexp\": {\n" + - " \"user1\": {\n" + - " \"value\": \"k.*y\",\n" + - " \"case_insensitive\": false\n" + - " },\n" + - " }\n" + - "}"; - ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json)); - assertEquals("[regexp] query does not support [case_insensitive] = false", e.getMessage()); - } }