diff --git a/core/src/main/java/org/elasticsearch/index/query/EmptyQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/EmptyQueryBuilder.java index 22493688254..3d09bb41b0a 100644 --- a/core/src/main/java/org/elasticsearch/index/query/EmptyQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/EmptyQueryBuilder.java @@ -34,7 +34,6 @@ import java.io.IOException; public final class EmptyQueryBuilder extends AbstractQueryBuilder { public static final String NAME = "empty_query"; - public static final EmptyQueryBuilder PROTOTYPE = new EmptyQueryBuilder(); /** * Construct an empty query. This query can *technically* be named and given a boost. diff --git a/core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java index fab49cb2ed9..e8533478198 100644 --- a/core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java @@ -102,7 +102,7 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder { private final int ordinal; - private static final GeoExecType PROTOTYPE = MEMORY; - GeoExecType(int ordinal) { this.ordinal = ordinal; } - @Override - public GeoExecType readFrom(StreamInput in) throws IOException { + public static GeoExecType readFromStream(StreamInput in) throws IOException { int ord = in.readVInt(); switch(ord) { case(0): return MEMORY; @@ -49,10 +46,6 @@ public enum GeoExecType implements Writeable { throw new ElasticsearchException("unknown serialized type [" + ord + "]"); } - public static GeoExecType readTypeFrom(StreamInput in) throws IOException { - return PROTOTYPE.readFrom(in); - } - @Override public void writeTo(StreamOutput out) throws IOException { out.writeVInt(this.ordinal); diff --git a/core/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java index 8205a80b4da..ac90148ef53 100644 --- a/core/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java @@ -40,7 +40,6 @@ public class SpanTermQueryBuilder extends BaseTermQueryBuilder { - static final FilterAggregatorBuilder PROTOTYPE = new FilterAggregatorBuilder("", EmptyQueryBuilder.PROTOTYPE); + static final FilterAggregatorBuilder PROTOTYPE = new FilterAggregatorBuilder("", new MatchAllQueryBuilder()); private final QueryBuilder filter; diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregator.java index 35cc6cd2b49..be31d9f6108 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregator.java @@ -59,7 +59,7 @@ public class FiltersAggregator extends BucketsAggregator { public static class KeyedFilter implements Writeable, ToXContent { - static final KeyedFilter PROTOTYPE = new KeyedFilter("", EmptyQueryBuilder.PROTOTYPE); + static final KeyedFilter PROTOTYPE = new KeyedFilter("", new MatchAllQueryBuilder()); private final String key; private final QueryBuilder filter; diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregatorBuilder.java index b35458aa67d..41e99db44be 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregatorBuilder.java @@ -22,7 +22,7 @@ package org.elasticsearch.search.aggregations.bucket.filters; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.query.EmptyQueryBuilder; +import org.elasticsearch.index.query.MatchAllQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.search.aggregations.AggregatorBuilder; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; @@ -39,7 +39,7 @@ import java.util.Objects; public class FiltersAggregatorBuilder extends AggregatorBuilder { - static final FiltersAggregatorBuilder PROTOTYPE = new FiltersAggregatorBuilder("", EmptyQueryBuilder.PROTOTYPE); + static final FiltersAggregatorBuilder PROTOTYPE = new FiltersAggregatorBuilder("", new MatchAllQueryBuilder()); private final List filters; private final boolean keyed; diff --git a/core/src/test/java/org/elasticsearch/index/query/HasParentQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/HasParentQueryBuilderTests.java index a7182cf25a5..911011e45f2 100644 --- a/core/src/test/java/org/elasticsearch/index/query/HasParentQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/HasParentQueryBuilderTests.java @@ -167,7 +167,7 @@ public class HasParentQueryBuilderTests extends AbstractQueryTestCase new IndicesQueryBuilder(new MatchAllQueryBuilder(), (String[]) null)); + expectThrows(IllegalArgumentException.class, () -> new IndicesQueryBuilder(new MatchAllQueryBuilder(), new String[0])); - try { - new IndicesQueryBuilder(EmptyQueryBuilder.PROTOTYPE, new String[0]); - fail("cannot be empty"); - } catch (IllegalArgumentException e) { - // expected - } - - IndicesQueryBuilder indicesQueryBuilder = new IndicesQueryBuilder(EmptyQueryBuilder.PROTOTYPE, "index"); - try { - indicesQueryBuilder.noMatchQuery((QueryBuilder) null); - fail("cannot be null"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - indicesQueryBuilder.noMatchQuery((String) null); - fail("cannot be null"); - } catch (IllegalArgumentException e) { - // expected - } + IndicesQueryBuilder indicesQueryBuilder = new IndicesQueryBuilder(new MatchAllQueryBuilder(), "index"); + expectThrows(IllegalArgumentException.class, () -> indicesQueryBuilder.noMatchQuery((QueryBuilder) null)); + expectThrows(IllegalArgumentException.class, () -> indicesQueryBuilder.noMatchQuery((String) null)); } public void testFromJson() throws IOException { diff --git a/core/src/test/java/org/elasticsearch/index/query/NestedQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/NestedQueryBuilderTests.java index 0195e20aba1..47f294dc433 100644 --- a/core/src/test/java/org/elasticsearch/index/query/NestedQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/NestedQueryBuilderTests.java @@ -118,7 +118,7 @@ public class NestedQueryBuilderTests extends AbstractQueryTestCase createQuery(Random r) { switch (RandomInts.randomIntBetween(r, 0, 4)) { case 0: return new MatchAllQueryBuilderTests().createTestQueryBuilder(); @@ -47,7 +47,7 @@ public class RandomQueryBuilder { case 3: return createMultiTermQuery(r); case 4: - return EmptyQueryBuilder.PROTOTYPE; + return new EmptyQueryBuilder(); default: throw new UnsupportedOperationException(); } diff --git a/core/src/test/java/org/elasticsearch/index/query/SpanContainingQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/SpanContainingQueryBuilderTests.java index f6d18447c94..999d85c6307 100644 --- a/core/src/test/java/org/elasticsearch/index/query/SpanContainingQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/SpanContainingQueryBuilderTests.java @@ -40,14 +40,14 @@ public class SpanContainingQueryBuilderTests extends AbstractQueryTestCase new SpanOrQueryBuilder((SpanQueryBuilder) null)); try { - SpanOrQueryBuilder spanOrBuilder = new SpanOrQueryBuilder(SpanTermQueryBuilder.PROTOTYPE); + SpanOrQueryBuilder spanOrBuilder = new SpanOrQueryBuilder(new SpanTermQueryBuilder("field", "value")); spanOrBuilder.clause(null); fail("cannot be null"); } catch (IllegalArgumentException e) { diff --git a/core/src/test/java/org/elasticsearch/index/query/SpanWithinQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/SpanWithinQueryBuilderTests.java index 217625516f7..3b7723be000 100644 --- a/core/src/test/java/org/elasticsearch/index/query/SpanWithinQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/SpanWithinQueryBuilderTests.java @@ -40,14 +40,14 @@ public class SpanWithinQueryBuilderTests extends AbstractQueryTestCase