Remove remaining PROTOTYPEs from org.elasticsearch.index.query
Relates to #17085
This commit is contained in:
parent
11648cbff6
commit
3d5def0789
|
@ -34,7 +34,6 @@ import java.io.IOException;
|
|||
public final class EmptyQueryBuilder extends AbstractQueryBuilder<EmptyQueryBuilder> {
|
||||
|
||||
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.
|
||||
|
|
|
@ -102,7 +102,7 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
|
|||
fieldName = in.readString();
|
||||
topLeft = in.readGeoPoint();
|
||||
bottomRight = in.readGeoPoint();
|
||||
type = GeoExecType.readTypeFrom(in);
|
||||
type = GeoExecType.readFromStream(in);
|
||||
validationMethod = GeoValidationMethod.readFromStream(in);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,14 +33,11 @@ public enum GeoExecType implements Writeable<GeoExecType> {
|
|||
|
||||
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<GeoExecType> {
|
|||
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);
|
||||
|
|
|
@ -40,7 +40,6 @@ public class SpanTermQueryBuilder extends BaseTermQueryBuilder<SpanTermQueryBuil
|
|||
|
||||
public static final String NAME = "span_term";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final SpanTermQueryBuilder PROTOTYPE = new SpanTermQueryBuilder("name", "value");
|
||||
|
||||
private static final ParseField TERM_FIELD = new ParseField("term");
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ import java.util.Objects;
|
|||
|
||||
public class FilterAggregatorBuilder extends AggregatorBuilder<FilterAggregatorBuilder> {
|
||||
|
||||
static final FilterAggregatorBuilder PROTOTYPE = new FilterAggregatorBuilder("", EmptyQueryBuilder.PROTOTYPE);
|
||||
static final FilterAggregatorBuilder PROTOTYPE = new FilterAggregatorBuilder("", new MatchAllQueryBuilder());
|
||||
|
||||
private final QueryBuilder<?> filter;
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public class FiltersAggregator extends BucketsAggregator {
|
|||
|
||||
public static class KeyedFilter implements Writeable<KeyedFilter>, 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;
|
||||
|
||||
|
|
|
@ -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<FiltersAggregatorBuilder> {
|
||||
|
||||
static final FiltersAggregatorBuilder PROTOTYPE = new FiltersAggregatorBuilder("", EmptyQueryBuilder.PROTOTYPE);
|
||||
static final FiltersAggregatorBuilder PROTOTYPE = new FiltersAggregatorBuilder("", new MatchAllQueryBuilder());
|
||||
|
||||
private final List<KeyedFilter> filters;
|
||||
private final boolean keyed;
|
||||
|
|
|
@ -167,7 +167,7 @@ public class HasParentQueryBuilderTests extends AbstractQueryTestCase<HasParentQ
|
|||
builder.startObject();
|
||||
builder.startObject("has_parent");
|
||||
builder.field("query");
|
||||
EmptyQueryBuilder.PROTOTYPE.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
new TermQueryBuilder("a", "a").toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.field("type", "foo"); // deprecated
|
||||
builder.endObject();
|
||||
builder.endObject();
|
||||
|
@ -187,7 +187,7 @@ public class HasParentQueryBuilderTests extends AbstractQueryTestCase<HasParentQ
|
|||
builder.startObject();
|
||||
builder.startObject("has_parent");
|
||||
builder.field("query");
|
||||
EmptyQueryBuilder.PROTOTYPE.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
new TermQueryBuilder("a", "a").toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.field(key, score ? "score": "none");
|
||||
builder.field("parent_type", "foo");
|
||||
builder.endObject();
|
||||
|
|
|
@ -67,34 +67,12 @@ public class IndicesQueryBuilderTests extends AbstractQueryTestCase<IndicesQuery
|
|||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
new IndicesQueryBuilder(EmptyQueryBuilder.PROTOTYPE, (String[]) null);
|
||||
fail("cannot be null");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
expectThrows(IllegalArgumentException.class, () -> 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 {
|
||||
|
|
|
@ -118,7 +118,7 @@ public class NestedQueryBuilderTests extends AbstractQueryTestCase<NestedQueryBu
|
|||
|
||||
public void testValidate() {
|
||||
try {
|
||||
new NestedQueryBuilder(null, EmptyQueryBuilder.PROTOTYPE);
|
||||
new NestedQueryBuilder(null, new MatchAllQueryBuilder());
|
||||
fail("cannot be null");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
|
@ -131,7 +131,7 @@ public class NestedQueryBuilderTests extends AbstractQueryTestCase<NestedQueryBu
|
|||
// expected
|
||||
}
|
||||
|
||||
NestedQueryBuilder nestedQueryBuilder = new NestedQueryBuilder("path", EmptyQueryBuilder.PROTOTYPE);
|
||||
NestedQueryBuilder nestedQueryBuilder = new NestedQueryBuilder("path", new MatchAllQueryBuilder());
|
||||
try {
|
||||
nestedQueryBuilder.scoreMode(null);
|
||||
fail("cannot be null");
|
||||
|
|
|
@ -36,7 +36,7 @@ public class RandomQueryBuilder {
|
|||
* @param r random seed
|
||||
* @return a random {@link QueryBuilder}
|
||||
*/
|
||||
public static QueryBuilder createQuery(Random r) {
|
||||
public static QueryBuilder<?> 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();
|
||||
}
|
||||
|
|
|
@ -40,14 +40,14 @@ public class SpanContainingQueryBuilderTests extends AbstractQueryTestCase<SpanC
|
|||
|
||||
public void testIllegalArguments() {
|
||||
try {
|
||||
new SpanContainingQueryBuilder(null, SpanTermQueryBuilder.PROTOTYPE);
|
||||
new SpanContainingQueryBuilder(null, new SpanTermQueryBuilder("field", "value"));
|
||||
fail("cannot be null");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
new SpanContainingQueryBuilder(SpanTermQueryBuilder.PROTOTYPE, null);
|
||||
new SpanContainingQueryBuilder(new SpanTermQueryBuilder("field", "value"), null);
|
||||
fail("cannot be null");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
|
|
|
@ -65,7 +65,7 @@ public class SpanNearQueryBuilderTests extends AbstractQueryTestCase<SpanNearQue
|
|||
}
|
||||
|
||||
try {
|
||||
SpanNearQueryBuilder spanNearQueryBuilder = new SpanNearQueryBuilder(SpanTermQueryBuilder.PROTOTYPE, 1);
|
||||
SpanNearQueryBuilder spanNearQueryBuilder = new SpanNearQueryBuilder(new SpanTermQueryBuilder("field", "value"), 1);
|
||||
spanNearQueryBuilder.clause(null);
|
||||
fail("cannot be null");
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
|
|
@ -62,13 +62,13 @@ public class SpanNotQueryBuilderTests extends AbstractQueryTestCase<SpanNotQuery
|
|||
|
||||
public void testIllegalArgument() {
|
||||
try {
|
||||
new SpanNotQueryBuilder(null, SpanTermQueryBuilder.PROTOTYPE);
|
||||
new SpanNotQueryBuilder(null, new SpanTermQueryBuilder("field", "value"));
|
||||
fail("cannot be null");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
new SpanNotQueryBuilder(SpanTermQueryBuilder.PROTOTYPE, null);
|
||||
new SpanNotQueryBuilder(new SpanTermQueryBuilder("field", "value"), null);
|
||||
fail("cannot be null");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
|
|
|
@ -55,7 +55,7 @@ public class SpanOrQueryBuilderTests extends AbstractQueryTestCase<SpanOrQueryBu
|
|||
expectThrows(IllegalArgumentException.class, () -> 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) {
|
||||
|
|
|
@ -40,14 +40,14 @@ public class SpanWithinQueryBuilderTests extends AbstractQueryTestCase<SpanWithi
|
|||
|
||||
public void testIllegalArguments() {
|
||||
try {
|
||||
new SpanWithinQueryBuilder(null, SpanTermQueryBuilder.PROTOTYPE);
|
||||
new SpanWithinQueryBuilder(null, new SpanTermQueryBuilder("field", "value"));
|
||||
fail("cannot be null");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
new SpanWithinQueryBuilder(SpanTermQueryBuilder.PROTOTYPE, null);
|
||||
new SpanWithinQueryBuilder(new SpanTermQueryBuilder("field", "value"), null);
|
||||
fail("cannot be null");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
|
|
|
@ -573,7 +573,7 @@ public class SearchSourceBuilderTests extends ESTestCase {
|
|||
|
||||
public void testEmptyPostFilter() throws IOException {
|
||||
SearchSourceBuilder builder = new SearchSourceBuilder();
|
||||
builder.postFilter(EmptyQueryBuilder.PROTOTYPE);
|
||||
builder.postFilter(new EmptyQueryBuilder());
|
||||
String query = "{ \"post_filter\": {} }";
|
||||
assertParseSearchSource(builder, new BytesArray(query));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue