diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FieldQueryBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FieldQueryBuilder.java index eb5ebfed03c..c47a87c57b3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FieldQueryBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FieldQueryBuilder.java @@ -45,6 +45,8 @@ public class FieldQueryBuilder extends BaseQueryBuilder { private String analyzer; + private Boolean autoGeneratePhraseQueries; + private Boolean allowLeadingWildcard; private Boolean lowercaseExpandedTerms; @@ -184,6 +186,19 @@ public class FieldQueryBuilder extends BaseQueryBuilder { return this; } + /** + * Set to true if phrase queries will be automatically generated + * when the analyzer returns more than one term from whitespace + * delimited text. + * NOTE: this behavior may not be suitable for all languages. + *

+ * Set to false if phrase queries should only be generated when + * surrounded by double quotes. + */ + public void autoGeneratePhraseQueries(boolean autoGeneratePhraseQueries) { + this.autoGeneratePhraseQueries = autoGeneratePhraseQueries; + } + /** * Should leading wildcards be allowed or not. Defaults to true. */ @@ -266,6 +281,9 @@ public class FieldQueryBuilder extends BaseQueryBuilder { if (analyzer != null) { builder.field("analyzer", analyzer); } + if (autoGeneratePhraseQueries != null) { + builder.field("auto_generate_phrase_queries", autoGeneratePhraseQueries); + } if (allowLeadingWildcard != null) { builder.field("allow_leading_wildcard", allowLeadingWildcard); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryStringQueryBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryStringQueryBuilder.java index 10c6fb67d1c..00653c5407b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryStringQueryBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryStringQueryBuilder.java @@ -52,6 +52,8 @@ public class QueryStringQueryBuilder extends BaseQueryBuilder { private String analyzer; + private Boolean autoGeneratePhraseQueries; + private Boolean allowLeadingWildcard; private Boolean lowercaseExpandedTerms; @@ -157,6 +159,19 @@ public class QueryStringQueryBuilder extends BaseQueryBuilder { return this; } + /** + * Set to true if phrase queries will be automatically generated + * when the analyzer returns more than one term from whitespace + * delimited text. + * NOTE: this behavior may not be suitable for all languages. + *

+ * Set to false if phrase queries should only be generated when + * surrounded by double quotes. + */ + public void autoGeneratePhraseQueries(boolean autoGeneratePhraseQueries) { + this.autoGeneratePhraseQueries = autoGeneratePhraseQueries; + } + /** * Should leading wildcards be allowed or not. Defaults to true. */ @@ -260,6 +275,9 @@ public class QueryStringQueryBuilder extends BaseQueryBuilder { if (analyzer != null) { builder.field("analyzer", analyzer); } + if (autoGeneratePhraseQueries != null) { + builder.field("auto_generate_phrase_queries", autoGeneratePhraseQueries); + } if (allowLeadingWildcard != null) { builder.field("allow_leading_wildcard", allowLeadingWildcard); }