diff --git a/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java index 54f45c25f38..d79346cc7e5 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java @@ -85,6 +85,8 @@ public class QueryStringQueryBuilder extends BaseQueryBuilder { private String minimumShouldMatch; + private Boolean lenient; + public QueryStringQueryBuilder(String queryString) { this.queryString = queryString; } @@ -279,6 +281,15 @@ public class QueryStringQueryBuilder extends BaseQueryBuilder { return this; } + /** + * Sets the query string parser to be lenient when parsing field values, defaults to the index + * setting and if not set, defaults to false. + */ + public QueryStringQueryBuilder lenient(Boolean lenient) { + this.lenient = lenient; + return this; + } + @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(QueryStringQueryParser.NAME); @@ -351,6 +362,9 @@ public class QueryStringQueryBuilder extends BaseQueryBuilder { if (quoteFieldSuffix != null) { builder.field("quote_field_suffix", quoteFieldSuffix); } + if (lenient != null) { + builder.field("lenient", lenient); + } builder.endObject(); } } diff --git a/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 7173a9aa168..fe3e672b69a 100644 --- a/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -154,6 +154,7 @@ public class RestSearchAction extends BaseRestHandler { queryBuilder.analyzer(request.param("analyzer")); queryBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false)); queryBuilder.lowercaseExpandedTerms(request.paramAsBoolean("lowercase_expanded_terms", true)); + queryBuilder.lenient(request.paramAsBooleanOptional("lenient", null)); String defaultOperator = request.param("default_operator"); if (defaultOperator != null) { if ("OR".equals(defaultOperator)) {