diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/AndFilterBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/AndFilterBuilder.java index f8a4fc90d47..7a24ced0dd6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/AndFilterBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/AndFilterBuilder.java @@ -53,7 +53,7 @@ public class AndFilterBuilder extends BaseFilterBuilder { } /** - * Should the inner filters be cached or not. Defaults to true. + * Should the filter be cached or not. Defaults to false. */ public AndFilterBuilder cache(boolean cache) { this.cache = cache; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/BoolFilterBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/BoolFilterBuilder.java index 3e05d5f5e53..9e7f69e8e17 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/BoolFilterBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/BoolFilterBuilder.java @@ -34,6 +34,8 @@ public class BoolFilterBuilder extends BaseFilterBuilder { private ArrayList clauses = new ArrayList(); + private Boolean cache; + private String filterName; /** @@ -70,6 +72,14 @@ public class BoolFilterBuilder extends BaseFilterBuilder { return this; } + /** + * Should the filter be cached or not. Defaults to false. + */ + public BoolFilterBuilder cache(boolean cache) { + this.cache = cache; + return this; + } + @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject("bool"); for (Clause clause : clauses) { @@ -87,6 +97,9 @@ public class BoolFilterBuilder extends BaseFilterBuilder { if (filterName != null) { builder.field("_name", filterName); } + if (cache != null) { + builder.field("_cache", cache); + } builder.endObject(); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoBoundingBoxFilterBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoBoundingBoxFilterBuilder.java index 0ce9f1828db..8c32779c4da 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoBoundingBoxFilterBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoBoundingBoxFilterBuilder.java @@ -40,6 +40,8 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder { private String bottomRightGeohash; + private Boolean cache; + private String filterName; public GeoBoundingBoxFilterBuilder(String name) { @@ -78,6 +80,14 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder { return this; } + /** + * Should the filter be cached or not. Defaults to false. + */ + public GeoBoundingBoxFilterBuilder cache(boolean cache) { + this.cache = cache; + return this; + } + @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(GeoBoundingBoxFilterParser.NAME); @@ -102,6 +112,9 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder { if (filterName != null) { builder.field("_name", filterName); } + if (cache != null) { + builder.field("_cache", cache); + } builder.endObject(); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoDistanceFilterBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoDistanceFilterBuilder.java index 1e75500a6aa..8ff37a36eca 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoDistanceFilterBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoDistanceFilterBuilder.java @@ -42,6 +42,8 @@ public class GeoDistanceFilterBuilder extends BaseFilterBuilder { private GeoDistance geoDistance; + private Boolean cache; + private String filterName; public GeoDistanceFilterBuilder(String name) { @@ -84,11 +86,22 @@ public class GeoDistanceFilterBuilder extends BaseFilterBuilder { return this; } + /** + * Sets the filter name for the filter that can be used when searching for matched_filters per hit. + */ public GeoDistanceFilterBuilder filterName(String filterName) { this.filterName = filterName; return this; } + /** + * Should the filter be cached or not. Defaults to false. + */ + public GeoDistanceFilterBuilder cache(boolean cache) { + this.cache = cache; + return this; + } + @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(GeoDistanceFilterParser.NAME); if (geohash != null) { @@ -103,6 +116,9 @@ public class GeoDistanceFilterBuilder extends BaseFilterBuilder { if (filterName != null) { builder.field("_name", filterName); } + if (cache != null) { + builder.field("_cache", cache); + } builder.endObject(); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoPolygonFilterBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoPolygonFilterBuilder.java index 8ef30d82db0..0c7e560ffd6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoPolygonFilterBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoPolygonFilterBuilder.java @@ -36,6 +36,8 @@ public class GeoPolygonFilterBuilder extends BaseFilterBuilder { private final List points = Lists.newArrayList(); + private Boolean cache; + private String filterName; public GeoPolygonFilterBuilder(String name) { @@ -52,11 +54,22 @@ public class GeoPolygonFilterBuilder extends BaseFilterBuilder { return addPoint(values[0], values[1]); } + /** + * Sets the filter name for the filter that can be used when searching for matched_filters per hit. + */ public GeoPolygonFilterBuilder filterName(String filterName) { this.filterName = filterName; return this; } + /** + * Should the filter be cached or not. Defaults to false. + */ + public GeoPolygonFilterBuilder cache(boolean cache) { + this.cache = cache; + return this; + } + @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(GeoPolygonFilterParser.NAME); @@ -71,6 +84,9 @@ public class GeoPolygonFilterBuilder extends BaseFilterBuilder { if (filterName != null) { builder.field("_name", filterName); } + if (cache != null) { + builder.field("_cache", cache); + } builder.endObject(); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/NotFilterBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/NotFilterBuilder.java index 71bd39f266d..c222d87d2d7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/NotFilterBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/NotFilterBuilder.java @@ -41,7 +41,7 @@ public class NotFilterBuilder extends BaseFilterBuilder { } /** - * Should the inner filter be cached or not. Defaults to true. + * Should the filter be cached or not. Defaults to false. */ public NotFilterBuilder cache(boolean cache) { this.cache = cache; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/NumericRangeFilterBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/NumericRangeFilterBuilder.java index ffc02f9a072..8d7856fabf4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/NumericRangeFilterBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/NumericRangeFilterBuilder.java @@ -42,6 +42,8 @@ public class NumericRangeFilterBuilder extends BaseFilterBuilder { private boolean includeUpper = true; + private Boolean cache; + private String filterName; /** @@ -329,11 +331,22 @@ public class NumericRangeFilterBuilder extends BaseFilterBuilder { return this; } + /** + * Sets the filter name for the filter that can be used when searching for matched_filters per hit. + */ public NumericRangeFilterBuilder filterName(String filterName) { this.filterName = filterName; return this; } + /** + * Should the filter be cached or not. Defaults to false. + */ + public NumericRangeFilterBuilder cache(boolean cache) { + this.cache = cache; + return this; + } + @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(NumericRangeFilterParser.NAME); @@ -347,6 +360,9 @@ public class NumericRangeFilterBuilder extends BaseFilterBuilder { if (filterName != null) { builder.field("_name", filterName); } + if (cache != null) { + builder.field("_cache", cache); + } builder.endObject(); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/OrFilterBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/OrFilterBuilder.java index d2b5a9c0e62..36af45750e7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/OrFilterBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/OrFilterBuilder.java @@ -53,7 +53,7 @@ public class OrFilterBuilder extends BaseFilterBuilder { } /** - * Should the inner filters be cached or not. Defaults to true. + * Should the filter be cached or not. Defaults to false. */ public OrFilterBuilder cache(boolean cache) { this.cache = cache; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/PrefixFilterBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/PrefixFilterBuilder.java index 33746cacf40..f79a02b9f0d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/PrefixFilterBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/PrefixFilterBuilder.java @@ -35,6 +35,8 @@ public class PrefixFilterBuilder extends BaseFilterBuilder { private final String prefix; + private Boolean cache; + private String filterName; /** @@ -49,17 +51,31 @@ public class PrefixFilterBuilder extends BaseFilterBuilder { this.prefix = prefix; } + /** + * Sets the filter name for the filter that can be used when searching for matched_filters per hit. + */ public PrefixFilterBuilder filterName(String filterName) { this.filterName = filterName; return this; } + /** + * Should the filter be cached or not. Defaults to false. + */ + public PrefixFilterBuilder cache(boolean cache) { + this.cache = cache; + return this; + } + @Override public void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(PrefixFilterParser.NAME); builder.field(name, prefix); if (filterName != null) { builder.field("_name", filterName); } + if (cache != null) { + builder.field("_cache", cache); + } builder.endObject(); } } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryFilterBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryFilterBuilder.java index bfb0d2bba09..3df5994636f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryFilterBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryFilterBuilder.java @@ -32,6 +32,8 @@ public class QueryFilterBuilder extends BaseFilterBuilder { private final XContentQueryBuilder queryBuilder; + private Boolean cache; + private String filterName; /** @@ -43,20 +45,36 @@ public class QueryFilterBuilder extends BaseFilterBuilder { this.queryBuilder = queryBuilder; } + /** + * Sets the filter name for the filter that can be used when searching for matched_filters per hit. + */ public QueryFilterBuilder filterName(String filterName) { this.filterName = filterName; return this; } + /** + * Should the filter be cached or not. Defaults to false. + */ + public QueryFilterBuilder cache(boolean cache) { + this.cache = cache; + return this; + } + @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { - if (filterName != null) { + if (filterName == null && cache == null) { builder.field(QueryFilterParser.NAME); queryBuilder.toXContent(builder, params); } else { builder.startObject(FQueryFilterParser.NAME); builder.field("query"); queryBuilder.toXContent(builder, params); - builder.field("_name", filterName); + if (filterName != null) { + builder.field("_name", filterName); + } + if (cache != null) { + builder.field("_cache", cache); + } builder.endObject(); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/RangeFilterBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/RangeFilterBuilder.java index c1c63951de5..6dae3f50bd6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/RangeFilterBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/RangeFilterBuilder.java @@ -40,6 +40,8 @@ public class RangeFilterBuilder extends BaseFilterBuilder { private boolean includeUpper = true; + private Boolean cache; + private String filterName; /** @@ -327,11 +329,22 @@ public class RangeFilterBuilder extends BaseFilterBuilder { return this; } + /** + * Sets the filter name for the filter that can be used when searching for matched_filters per hit. + */ public RangeFilterBuilder filterName(String filterName) { this.filterName = filterName; return this; } + /** + * Should the filter be cached or not. Defaults to true. + */ + public RangeFilterBuilder cache(boolean cache) { + this.cache = cache; + return this; + } + @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(RangeFilterParser.NAME); @@ -345,6 +358,9 @@ public class RangeFilterBuilder extends BaseFilterBuilder { if (filterName != null) { builder.field("_name", filterName); } + if (cache != null) { + builder.field("_cache", cache); + } builder.endObject(); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/ScriptFilterBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/ScriptFilterBuilder.java index 06b27d91184..7ee5c3e1409 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/ScriptFilterBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/ScriptFilterBuilder.java @@ -37,6 +37,8 @@ public class ScriptFilterBuilder extends BaseFilterBuilder { private String lang; + private Boolean cache; + private String filterName; public ScriptFilterBuilder(String script) { @@ -60,16 +62,27 @@ public class ScriptFilterBuilder extends BaseFilterBuilder { return this; } + /** + * Sets the script language. + */ + public ScriptFilterBuilder lang(String lang) { + this.lang = lang; + return this; + } + + /** + * Sets the filter name for the filter that can be used when searching for matched_filters per hit. + */ public ScriptFilterBuilder filterName(String filterName) { this.filterName = filterName; return this; } /** - * Sets the script language. + * Should the filter be cached or not. Defaults to false. */ - public ScriptFilterBuilder lang(String lang) { - this.lang = lang; + public ScriptFilterBuilder cache(boolean cache) { + this.cache = cache; return this; } @@ -85,6 +98,9 @@ public class ScriptFilterBuilder extends BaseFilterBuilder { if (filterName != null) { builder.field("_name", filterName); } + if (cache != null) { + builder.field("_cache", cache); + } builder.endObject(); } } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/TermFilterBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/TermFilterBuilder.java index 9443b56ab50..bc3596f3176 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/TermFilterBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/TermFilterBuilder.java @@ -34,6 +34,8 @@ public class TermFilterBuilder extends BaseFilterBuilder { private final Object value; + private Boolean cache; + private String filterName; /** @@ -97,17 +99,31 @@ public class TermFilterBuilder extends BaseFilterBuilder { this.value = value; } + /** + * Sets the filter name for the filter that can be used when searching for matched_filters per hit. + */ public TermFilterBuilder filterName(String filterName) { this.filterName = filterName; return this; } + /** + * Should the filter be cached or not. Defaults to true. + */ + public TermFilterBuilder cache(boolean cache) { + this.cache = cache; + return this; + } + @Override public void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(TermFilterParser.NAME); builder.field(name, value); if (filterName != null) { builder.field("_name", filterName); } + if (cache != null) { + builder.field("_cache", cache); + } builder.endObject(); } } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/TermsFilterBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/TermsFilterBuilder.java index 300566d5698..5375b0cbaa2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/TermsFilterBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/TermsFilterBuilder.java @@ -34,6 +34,8 @@ public class TermsFilterBuilder extends BaseFilterBuilder { private final Object[] values; + private Boolean cache; + private String filterName; /** @@ -113,11 +115,22 @@ public class TermsFilterBuilder extends BaseFilterBuilder { this.values = values; } + /** + * Sets the filter name for the filter that can be used when searching for matched_filters per hit. + */ public TermsFilterBuilder filterName(String filterName) { this.filterName = filterName; return this; } + /** + * Should the filter be cached or not. Defaults to false. + */ + public TermsFilterBuilder cache(boolean cache) { + this.cache = cache; + return this; + } + @Override public void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(TermsFilterParser.NAME); builder.startArray(name); @@ -129,6 +142,9 @@ public class TermsFilterBuilder extends BaseFilterBuilder { if (filterName != null) { builder.field("_name", filterName); } + if (cache != null) { + builder.field("_cache", cache); + } builder.endObject(); }