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 08318874df2..f55a0c08149 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java @@ -964,8 +964,8 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder + client().prepareSearch("test").setQuery( + queryStringQuery("f_date:[now-2D TO now]").lenient(false)).get()); + assertThat(ExceptionsHelper.detailedMessage(e), + containsString("unit [D] not supported for date math [-2D]")); + } + private void assertHits(SearchHits hits, String... ids) { assertThat(hits.totalHits(), equalTo((long) ids.length)); Set hitIds = new HashSet<>(); @@ -263,5 +271,4 @@ public class QueryStringIT extends ESIntegTestCase { } assertThat(hitIds, containsInAnyOrder(ids)); } - } diff --git a/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java b/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java index 60f89ab326e..1af3bb99b28 100644 --- a/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java +++ b/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java @@ -564,6 +564,18 @@ public class SimpleQueryStringIT extends ESIntegTestCase { assertHitCount(resp, 1L); } + public void testAllFieldsWithSpecifiedLeniency() throws IOException { + String indexBody = copyToStringFromClasspath("/org/elasticsearch/search/query/all-query-index.json"); + prepareCreate("test").setSource(indexBody).get(); + ensureGreen("test"); + + Exception e = expectThrows(Exception.class, () -> + client().prepareSearch("test").setQuery( + simpleQueryStringQuery("foo123").lenient(false)).get()); + assertThat(ExceptionsHelper.detailedMessage(e), + containsString("NumberFormatException[For input string: \"foo123\"]")); + } + private void assertHits(SearchHits hits, String... ids) { assertThat(hits.totalHits(), equalTo((long) ids.length)); Set hitIds = new HashSet<>(); diff --git a/docs/reference/search/validate.asciidoc b/docs/reference/search/validate.asciidoc index 5b015f4e578..8b7b897934d 100644 --- a/docs/reference/search/validate.asciidoc +++ b/docs/reference/search/validate.asciidoc @@ -87,7 +87,7 @@ due to dynamic mapping, and 'foo' does not correctly parse into a date: [source,js] -------------------------------------------------- -GET twitter/tweet/_validate/query?q=post_date:foo +GET twitter/tweet/_validate/query?q=post_date:foo%5d -------------------------------------------------- // CONSOLE @@ -102,7 +102,7 @@ about why a query failed: [source,js] -------------------------------------------------- -GET twitter/tweet/_validate/query?q=post_date:foo&explain=true +GET twitter/tweet/_validate/query?q=post_date:foo%5d&explain=true -------------------------------------------------- // CONSOLE