parent
6776586725
commit
eb338f46f7
|
@ -167,11 +167,8 @@ public class ExplainRequest extends SingleShardRequest<ExplainRequest> {
|
|||
preference = in.readOptionalString();
|
||||
query = in.readQuery();
|
||||
filteringAlias = in.readStringArray();
|
||||
if (in.readBoolean()) {
|
||||
fields = in.readStringArray();
|
||||
}
|
||||
|
||||
fetchSourceContext = FetchSourceContext.optionalReadFromStream(in);
|
||||
fields = in.readOptionalStringArray();
|
||||
fetchSourceContext = in.readOptionalStreamable(FetchSourceContext::new);
|
||||
nowInMillis = in.readVLong();
|
||||
}
|
||||
|
||||
|
@ -184,14 +181,8 @@ public class ExplainRequest extends SingleShardRequest<ExplainRequest> {
|
|||
out.writeOptionalString(preference);
|
||||
out.writeQuery(query);
|
||||
out.writeStringArray(filteringAlias);
|
||||
if (fields != null) {
|
||||
out.writeBoolean(true);
|
||||
out.writeStringArray(fields);
|
||||
} else {
|
||||
out.writeBoolean(false);
|
||||
}
|
||||
|
||||
FetchSourceContext.optionalWriteToStream(fetchSourceContext, out);
|
||||
out.writeOptionalStringArray(fields);
|
||||
out.writeOptionalStreamable(fetchSourceContext);
|
||||
out.writeVLong(nowInMillis);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -287,8 +287,7 @@ public class GetRequest extends SingleShardRequest<GetRequest> implements Realti
|
|||
|
||||
this.versionType = VersionType.fromValue(in.readByte());
|
||||
this.version = in.readLong();
|
||||
|
||||
fetchSourceContext = FetchSourceContext.optionalReadFromStream(in);
|
||||
fetchSourceContext = in.readOptionalStreamable(FetchSourceContext::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -319,8 +318,7 @@ public class GetRequest extends SingleShardRequest<GetRequest> implements Realti
|
|||
out.writeBoolean(ignoreErrorsOnGeneratedFields);
|
||||
out.writeByte(versionType.getValue());
|
||||
out.writeLong(version);
|
||||
|
||||
FetchSourceContext.optionalWriteToStream(fetchSourceContext, out);
|
||||
out.writeOptionalStreamable(fetchSourceContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -198,7 +198,7 @@ public class MultiGetRequest extends ActionRequest<MultiGetRequest> implements I
|
|||
version = in.readLong();
|
||||
versionType = VersionType.fromValue(in.readByte());
|
||||
|
||||
fetchSourceContext = FetchSourceContext.optionalReadFromStream(in);
|
||||
fetchSourceContext = in.readOptionalStreamable(FetchSourceContext::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -220,7 +220,7 @@ public class MultiGetRequest extends ActionRequest<MultiGetRequest> implements I
|
|||
out.writeLong(version);
|
||||
out.writeByte(versionType.getValue());
|
||||
|
||||
FetchSourceContext.optionalWriteToStream(fetchSourceContext, out);
|
||||
out.writeOptionalStreamable(fetchSourceContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -75,6 +75,7 @@ public abstract class ToXContentToBytes implements ToXContent {
|
|||
toXContent(builder, EMPTY_PARAMS);
|
||||
return builder.string();
|
||||
} catch (Exception e) {
|
||||
// So we have a stack trace logged somewhere
|
||||
return "{ \"error\" : \"" + ExceptionsHelper.detailedMessage(e) + "\"}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ public enum GeoDistance implements Writeable<GeoDistance> {
|
|||
return GeoDistance.values()[ord];
|
||||
}
|
||||
|
||||
public static GeoDistance readGeoDistanceFrom(StreamInput in) throws IOException {
|
||||
public static GeoDistance readFromStream(StreamInput in) throws IOException {
|
||||
return DEFAULT.readFrom(in);
|
||||
}
|
||||
|
||||
|
|
|
@ -511,6 +511,23 @@ public abstract class StreamInput extends InputStream {
|
|||
return new GeoPoint(readDouble(), readDouble());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a {@linkplain DateTimeZone}.
|
||||
*/
|
||||
public DateTimeZone readTimeZone() throws IOException {
|
||||
return DateTimeZone.forID(readString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an optional {@linkplain DateTimeZone}.
|
||||
*/
|
||||
public DateTimeZone readOptionalTimeZone() throws IOException {
|
||||
if (readBoolean()) {
|
||||
return DateTimeZone.forID(readString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int[] readIntArray() throws IOException {
|
||||
int length = readVInt();
|
||||
int[] values = new int[length];
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.elasticsearch.search.sort.SortBuilder;
|
|||
import org.elasticsearch.search.suggest.SuggestionBuilder;
|
||||
import org.elasticsearch.search.suggest.phrase.SmoothingModel;
|
||||
import org.elasticsearch.tasks.Task;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.ReadableInstant;
|
||||
|
||||
import java.io.EOFException;
|
||||
|
@ -759,6 +760,25 @@ public abstract class StreamOutput extends OutputStream {
|
|||
writeDouble(geoPoint.lon());
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a {@linkplain DateTimeZone} to the stream.
|
||||
*/
|
||||
public void writeTimeZone(DateTimeZone timeZone) throws IOException {
|
||||
writeString(timeZone.getID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an optional {@linkplain DateTimeZone} to the stream.
|
||||
*/
|
||||
public void writeOptionalTimeZone(DateTimeZone timeZone) throws IOException {
|
||||
if (timeZone == null) {
|
||||
writeBoolean(false);
|
||||
} else {
|
||||
writeBoolean(true);
|
||||
writeTimeZone(timeZone);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a list of {@link Writeable} objects
|
||||
*/
|
||||
|
|
|
@ -146,8 +146,7 @@ public enum CombineFunction implements Writeable<CombineFunction> {
|
|||
out.writeVInt(this.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CombineFunction readFrom(StreamInput in) throws IOException {
|
||||
public static CombineFunction readFromStream(StreamInput in) throws IOException {
|
||||
int ordinal = in.readVInt();
|
||||
if (ordinal < 0 || ordinal >= values().length) {
|
||||
throw new IOException("Unknown CombineFunction ordinal [" + ordinal + "]");
|
||||
|
@ -155,10 +154,6 @@ public enum CombineFunction implements Writeable<CombineFunction> {
|
|||
return values()[ordinal];
|
||||
}
|
||||
|
||||
public static CombineFunction readCombineFunctionFrom(StreamInput in) throws IOException {
|
||||
return CombineFunction.MULTIPLY.readFrom(in);
|
||||
}
|
||||
|
||||
public static CombineFunction fromString(String combineFunction) {
|
||||
return valueOf(combineFunction.toUpperCase(Locale.ROOT));
|
||||
}
|
||||
|
|
|
@ -83,8 +83,7 @@ public class FiltersFunctionScoreQuery extends Query {
|
|||
out.writeVInt(this.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScoreMode readFrom(StreamInput in) throws IOException {
|
||||
public static ScoreMode readFromStream(StreamInput in) throws IOException {
|
||||
int ordinal = in.readVInt();
|
||||
if (ordinal < 0 || ordinal >= values().length) {
|
||||
throw new IOException("Unknown ScoreMode ordinal [" + ordinal + "]");
|
||||
|
@ -92,10 +91,6 @@ public class FiltersFunctionScoreQuery extends Query {
|
|||
return values()[ordinal];
|
||||
}
|
||||
|
||||
public static ScoreMode readScoreModeFrom(StreamInput in) throws IOException {
|
||||
return ScoreMode.MULTIPLY.readFrom(in);
|
||||
}
|
||||
|
||||
public static ScoreMode fromString(String scoreMode) {
|
||||
return valueOf(scoreMode.toUpperCase(Locale.ROOT));
|
||||
}
|
||||
|
|
|
@ -47,10 +47,6 @@ public final class Fuzziness implements ToXContent, Writeable<Fuzziness> {
|
|||
|
||||
private final String fuzziness;
|
||||
|
||||
/** the prototype constant is intended for deserialization when used with
|
||||
* {@link org.elasticsearch.common.io.stream.StreamableReader#readFrom(StreamInput)} */
|
||||
static final Fuzziness PROTOTYPE = AUTO;
|
||||
|
||||
private Fuzziness(int fuzziness) {
|
||||
if (fuzziness != 0 && fuzziness != 1 && fuzziness != 2) {
|
||||
throw new IllegalArgumentException("Valid edit distances are [0, 1, 2] but was [" + fuzziness + "]");
|
||||
|
@ -65,6 +61,18 @@ public final class Fuzziness implements ToXContent, Writeable<Fuzziness> {
|
|||
this.fuzziness = fuzziness.toUpperCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public Fuzziness(StreamInput in) throws IOException {
|
||||
fuzziness = in.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fuzziness);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Fuzziness} instance from an edit distance. The value must be one of <tt>[0, 1, 2]</tt>
|
||||
*
|
||||
|
@ -237,18 +245,4 @@ public final class Fuzziness implements ToXContent, Writeable<Fuzziness> {
|
|||
public int hashCode() {
|
||||
return fuzziness.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fuzziness);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fuzziness readFrom(StreamInput in) throws IOException {
|
||||
return new Fuzziness(in.readString());
|
||||
}
|
||||
|
||||
public static Fuzziness readFuzzinessFrom(StreamInput in) throws IOException {
|
||||
return PROTOTYPE.readFrom(in);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -381,7 +381,7 @@ public enum VersionType implements Writeable<VersionType> {
|
|||
throw new IllegalArgumentException("No version type match [" + value + "]");
|
||||
}
|
||||
|
||||
public static VersionType readVersionTypeFrom(StreamInput in) throws IOException {
|
||||
public static VersionType readFromStream(StreamInput in) throws IOException {
|
||||
int ordinal = in.readVInt();
|
||||
assert (ordinal == 0 || ordinal == 1 || ordinal == 2 || ordinal == 3);
|
||||
return VersionType.values()[ordinal];
|
||||
|
|
|
@ -56,6 +56,20 @@ public abstract class AbstractQueryBuilder<QB extends AbstractQueryBuilder<QB>>
|
|||
super(XContentType.JSON);
|
||||
}
|
||||
|
||||
protected AbstractQueryBuilder(StreamInput in) throws IOException {
|
||||
boost = in.readFloat();
|
||||
queryName = in.readOptionalString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeFloat(boost);
|
||||
out.writeOptionalString(queryName);
|
||||
doWriteTo(out);
|
||||
}
|
||||
|
||||
protected abstract void doWriteTo(StreamOutput out) throws IOException;
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
|
@ -143,25 +157,6 @@ public abstract class AbstractQueryBuilder<QB extends AbstractQueryBuilder<QB>>
|
|||
return (QB) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final QB readFrom(StreamInput in) throws IOException {
|
||||
QB queryBuilder = doReadFrom(in);
|
||||
queryBuilder.boost = in.readFloat();
|
||||
queryBuilder.queryName = in.readOptionalString();
|
||||
return queryBuilder;
|
||||
}
|
||||
|
||||
protected abstract QB doReadFrom(StreamInput in) throws IOException;
|
||||
|
||||
@Override
|
||||
public final void writeTo(StreamOutput out) throws IOException {
|
||||
doWriteTo(out);
|
||||
out.writeFloat(boost);
|
||||
out.writeOptionalString(queryName);
|
||||
}
|
||||
|
||||
protected abstract void doWriteTo(StreamOutput out) throws IOException;
|
||||
|
||||
protected final QueryValidationException addValidationError(String validationError, QueryValidationException validationException) {
|
||||
return QueryValidationException.addValidationError(getName(), validationError, validationException);
|
||||
}
|
||||
|
@ -261,7 +256,7 @@ public abstract class AbstractQueryBuilder<QB extends AbstractQueryBuilder<QB>>
|
|||
|
||||
@Override
|
||||
public final QueryBuilder<?> rewrite(QueryRewriteContext queryShardContext) throws IOException {
|
||||
QueryBuilder rewritten = doRewrite(queryShardContext);
|
||||
QueryBuilder<?> rewritten = doRewrite(queryShardContext);
|
||||
if (rewritten == this) {
|
||||
return rewritten;
|
||||
}
|
||||
|
|
|
@ -119,6 +119,21 @@ public abstract class BaseTermQueryBuilder<QB extends BaseTermQueryBuilder<QB>>
|
|||
this.value = convertToBytesRefIfString(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
protected BaseTermQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
value = in.readGenericValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeGenericValue(value);
|
||||
}
|
||||
|
||||
/** Returns the field name used in this query. */
|
||||
public String fieldName() {
|
||||
return this.fieldName;
|
||||
|
@ -152,17 +167,4 @@ public abstract class BaseTermQueryBuilder<QB extends BaseTermQueryBuilder<QB>>
|
|||
return Objects.equals(fieldName, other.fieldName) &&
|
||||
Objects.equals(value, other.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final QB doReadFrom(StreamInput in) throws IOException {
|
||||
return createBuilder(in.readString(), in.readGenericValue());
|
||||
}
|
||||
|
||||
protected abstract QB createBuilder(String fieldName, Object value);
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeGenericValue(value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> {
|
|||
|
||||
public static final String NAME = "bool";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(BoolQueryBuilder.NAME);
|
||||
public static final BoolQueryBuilder PROTOTYPE = new BoolQueryBuilder();
|
||||
|
||||
public static final boolean ADJUST_PURE_NEGATIVE_DEFAULT = true;
|
||||
public static final boolean DISABLE_COORD_DEFAULT = false;
|
||||
|
@ -76,6 +75,37 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> {
|
|||
|
||||
private String minimumShouldMatch;
|
||||
|
||||
/**
|
||||
* Build an empty bool query.
|
||||
*/
|
||||
public BoolQueryBuilder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public BoolQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
mustClauses.addAll(readQueries(in));
|
||||
mustNotClauses.addAll(readQueries(in));
|
||||
shouldClauses.addAll(readQueries(in));
|
||||
filterClauses.addAll(readQueries(in));
|
||||
adjustPureNegative = in.readBoolean();
|
||||
disableCoord = in.readBoolean();
|
||||
minimumShouldMatch = in.readOptionalString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
writeQueries(out, mustClauses);
|
||||
writeQueries(out, mustNotClauses);
|
||||
writeQueries(out, shouldClauses);
|
||||
writeQueries(out, filterClauses);
|
||||
out.writeBoolean(adjustPureNegative);
|
||||
out.writeBoolean(disableCoord);
|
||||
out.writeOptionalString(minimumShouldMatch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a query that <b>must</b> appear in the matching documents and will
|
||||
* contribute to scoring. No <tt>null</tt> value allowed.
|
||||
|
@ -441,35 +471,6 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> {
|
|||
Objects.equals(filterClauses, other.filterClauses);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BoolQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
|
||||
List<QueryBuilder<?>> queryBuilders = readQueries(in);
|
||||
boolQueryBuilder.mustClauses.addAll(queryBuilders);
|
||||
queryBuilders = readQueries(in);
|
||||
boolQueryBuilder.mustNotClauses.addAll(queryBuilders);
|
||||
queryBuilders = readQueries(in);
|
||||
boolQueryBuilder.shouldClauses.addAll(queryBuilders);
|
||||
queryBuilders = readQueries(in);
|
||||
boolQueryBuilder.filterClauses.addAll(queryBuilders);
|
||||
boolQueryBuilder.adjustPureNegative = in.readBoolean();
|
||||
boolQueryBuilder.disableCoord = in.readBoolean();
|
||||
boolQueryBuilder.minimumShouldMatch = in.readOptionalString();
|
||||
return boolQueryBuilder;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
writeQueries(out, mustClauses);
|
||||
writeQueries(out, mustNotClauses);
|
||||
writeQueries(out, shouldClauses);
|
||||
writeQueries(out, filterClauses);
|
||||
out.writeBoolean(adjustPureNegative);
|
||||
out.writeBoolean(disableCoord);
|
||||
out.writeOptionalString(minimumShouldMatch);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected QueryBuilder<?> doRewrite(QueryRewriteContext queryRewriteContext) throws IOException {
|
||||
BoolQueryBuilder newBuilder = new BoolQueryBuilder();
|
||||
|
|
|
@ -47,15 +47,14 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder<BoostingQueryBuil
|
|||
|
||||
public static final String NAME = "boosting";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final BoostingQueryBuilder PROTOTYPE = new BoostingQueryBuilder(EmptyQueryBuilder.PROTOTYPE, EmptyQueryBuilder.PROTOTYPE);
|
||||
|
||||
private static final ParseField POSITIVE_FIELD = new ParseField("positive");
|
||||
private static final ParseField NEGATIVE_FIELD = new ParseField("negative");
|
||||
private static final ParseField NEGATIVE_BOOST_FIELD = new ParseField("negative_boost");
|
||||
|
||||
private final QueryBuilder positiveQuery;
|
||||
private final QueryBuilder<?> positiveQuery;
|
||||
|
||||
private final QueryBuilder negativeQuery;
|
||||
private final QueryBuilder<?> negativeQuery;
|
||||
|
||||
private float negativeBoost = -1;
|
||||
|
||||
|
@ -66,7 +65,7 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder<BoostingQueryBuil
|
|||
* @param positiveQuery the positive query for this boosting query.
|
||||
* @param negativeQuery the negative query for this boosting query.
|
||||
*/
|
||||
public BoostingQueryBuilder(QueryBuilder positiveQuery, QueryBuilder negativeQuery) {
|
||||
public BoostingQueryBuilder(QueryBuilder<?> positiveQuery, QueryBuilder<?> negativeQuery) {
|
||||
if (positiveQuery == null) {
|
||||
throw new IllegalArgumentException("inner clause [positive] cannot be null.");
|
||||
}
|
||||
|
@ -77,6 +76,23 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder<BoostingQueryBuil
|
|||
this.negativeQuery = negativeQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public BoostingQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
positiveQuery = in.readQuery();
|
||||
negativeQuery = in.readQuery();
|
||||
negativeBoost = in.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(positiveQuery);
|
||||
out.writeQuery(negativeQuery);
|
||||
out.writeFloat(negativeBoost);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the positive query for this boosting query.
|
||||
*/
|
||||
|
@ -208,22 +224,6 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder<BoostingQueryBuil
|
|||
Objects.equals(negativeQuery, other.negativeQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BoostingQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
QueryBuilder positiveQuery = in.readQuery();
|
||||
QueryBuilder negativeQuery = in.readQuery();
|
||||
BoostingQueryBuilder boostingQuery = new BoostingQueryBuilder(positiveQuery, negativeQuery);
|
||||
boostingQuery.negativeBoost = in.readFloat();
|
||||
return boostingQuery;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(positiveQuery);
|
||||
out.writeQuery(negativeQuery);
|
||||
out.writeFloat(negativeBoost);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected QueryBuilder<?> doRewrite(QueryRewriteContext queryRewriteContext) throws IOException {
|
||||
QueryBuilder positiveQuery = this.positiveQuery.rewrite(queryRewriteContext);
|
||||
|
|
|
@ -60,7 +60,6 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue
|
|||
|
||||
public static final String NAME = "common";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final CommonTermsQueryBuilder PROTOTYPE = new CommonTermsQueryBuilder("field", "text");
|
||||
|
||||
public static final float DEFAULT_CUTOFF_FREQ = 0.01f;
|
||||
public static final Operator DEFAULT_HIGH_FREQ_OCCUR = Operator.OR;
|
||||
|
@ -109,6 +108,35 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue
|
|||
this.text = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public CommonTermsQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
text = in.readGenericValue();
|
||||
highFreqOperator = Operator.readFromStream(in);
|
||||
lowFreqOperator = Operator.readFromStream(in);
|
||||
analyzer = in.readOptionalString();
|
||||
lowFreqMinimumShouldMatch = in.readOptionalString();
|
||||
highFreqMinimumShouldMatch = in.readOptionalString();
|
||||
disableCoord = in.readBoolean();
|
||||
cutoffFrequency = in.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(this.fieldName);
|
||||
out.writeGenericValue(this.text);
|
||||
highFreqOperator.writeTo(out);
|
||||
lowFreqOperator.writeTo(out);
|
||||
out.writeOptionalString(analyzer);
|
||||
out.writeOptionalString(lowFreqMinimumShouldMatch);
|
||||
out.writeOptionalString(highFreqMinimumShouldMatch);
|
||||
out.writeBoolean(disableCoord);
|
||||
out.writeFloat(cutoffFrequency);
|
||||
}
|
||||
|
||||
public String fieldName() {
|
||||
return this.fieldName;
|
||||
}
|
||||
|
@ -239,7 +267,7 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue
|
|||
XContentParser parser = parseContext.parser();
|
||||
XContentParser.Token token = parser.nextToken();
|
||||
if (token != XContentParser.Token.FIELD_NAME) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + CommonTermsQueryBuilder.NAME + "] query malformed, no field");
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + NAME + "] query malformed, no field");
|
||||
}
|
||||
String fieldName = parser.currentName();
|
||||
Object text = null;
|
||||
|
@ -397,32 +425,6 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue
|
|||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommonTermsQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
CommonTermsQueryBuilder commonTermsQueryBuilder = new CommonTermsQueryBuilder(in.readString(), in.readGenericValue());
|
||||
commonTermsQueryBuilder.highFreqOperator = Operator.readOperatorFrom(in);
|
||||
commonTermsQueryBuilder.lowFreqOperator = Operator.readOperatorFrom(in);
|
||||
commonTermsQueryBuilder.analyzer = in.readOptionalString();
|
||||
commonTermsQueryBuilder.lowFreqMinimumShouldMatch = in.readOptionalString();
|
||||
commonTermsQueryBuilder.highFreqMinimumShouldMatch = in.readOptionalString();
|
||||
commonTermsQueryBuilder.disableCoord = in.readBoolean();
|
||||
commonTermsQueryBuilder.cutoffFrequency = in.readFloat();
|
||||
return commonTermsQueryBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(this.fieldName);
|
||||
out.writeGenericValue(this.text);
|
||||
highFreqOperator.writeTo(out);
|
||||
lowFreqOperator.writeTo(out);
|
||||
out.writeOptionalString(analyzer);
|
||||
out.writeOptionalString(lowFreqMinimumShouldMatch);
|
||||
out.writeOptionalString(highFreqMinimumShouldMatch);
|
||||
out.writeBoolean(disableCoord);
|
||||
out.writeFloat(cutoffFrequency);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(fieldName, text, highFreqOperator, lowFreqOperator, analyzer,
|
||||
|
|
|
@ -39,11 +39,10 @@ public class ConstantScoreQueryBuilder extends AbstractQueryBuilder<ConstantScor
|
|||
|
||||
public static final String NAME = "constant_score";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final ConstantScoreQueryBuilder PROTOTYPE = new ConstantScoreQueryBuilder(EmptyQueryBuilder.PROTOTYPE);
|
||||
|
||||
private static final ParseField INNER_QUERY_FIELD = new ParseField("filter", "query");
|
||||
|
||||
private final QueryBuilder filterBuilder;
|
||||
private final QueryBuilder<?> filterBuilder;
|
||||
|
||||
/**
|
||||
* A query that wraps another query and simply returns a constant score equal to the
|
||||
|
@ -51,17 +50,30 @@ public class ConstantScoreQueryBuilder extends AbstractQueryBuilder<ConstantScor
|
|||
*
|
||||
* @param filterBuilder The query to wrap in a constant score query
|
||||
*/
|
||||
public ConstantScoreQueryBuilder(QueryBuilder filterBuilder) {
|
||||
public ConstantScoreQueryBuilder(QueryBuilder<?> filterBuilder) {
|
||||
if (filterBuilder == null) {
|
||||
throw new IllegalArgumentException("inner clause [filter] cannot be null.");
|
||||
}
|
||||
this.filterBuilder = filterBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public ConstantScoreQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
filterBuilder = in.readQuery();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(filterBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the query that was wrapped in this constant score query
|
||||
*/
|
||||
public QueryBuilder innerQuery() {
|
||||
public QueryBuilder<?> innerQuery() {
|
||||
return this.filterBuilder;
|
||||
}
|
||||
|
||||
|
@ -149,20 +161,9 @@ public class ConstantScoreQueryBuilder extends AbstractQueryBuilder<ConstantScor
|
|||
return Objects.equals(filterBuilder, other.filterBuilder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConstantScoreQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
QueryBuilder innerFilterBuilder = in.readQuery();
|
||||
return new ConstantScoreQueryBuilder(innerFilterBuilder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(filterBuilder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected QueryBuilder<?> doRewrite(QueryRewriteContext queryRewriteContext) throws IOException {
|
||||
QueryBuilder rewrite = filterBuilder.rewrite(queryRewriteContext);
|
||||
QueryBuilder<?> rewrite = filterBuilder.rewrite(queryRewriteContext);
|
||||
if (rewrite != filterBuilder) {
|
||||
return new ConstantScoreQueryBuilder(rewrite);
|
||||
}
|
||||
|
|
|
@ -43,17 +43,35 @@ public class DisMaxQueryBuilder extends AbstractQueryBuilder<DisMaxQueryBuilder>
|
|||
|
||||
public static final String NAME = "dis_max";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final DisMaxQueryBuilder PROTOTYPE = new DisMaxQueryBuilder();
|
||||
|
||||
/** Default multiplication factor for breaking ties in document scores.*/
|
||||
public static final float DEFAULT_TIE_BREAKER = 0.0f;
|
||||
|
||||
private static final ParseField TIE_BREAKER_FIELD = new ParseField("tie_breaker");
|
||||
private static final ParseField QUERIES_FIELD = new ParseField("queries");
|
||||
|
||||
private final List<QueryBuilder<?>> queries = new ArrayList<>();
|
||||
|
||||
/** Default multiplication factor for breaking ties in document scores.*/
|
||||
public static float DEFAULT_TIE_BREAKER = 0.0f;
|
||||
private float tieBreaker = DEFAULT_TIE_BREAKER;
|
||||
|
||||
public DisMaxQueryBuilder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public DisMaxQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
queries.addAll(readQueries(in));
|
||||
tieBreaker = in.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
writeQueries(out, queries);
|
||||
out.writeFloat(tieBreaker);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a sub-query to this disjunction.
|
||||
*/
|
||||
|
@ -176,21 +194,6 @@ public class DisMaxQueryBuilder extends AbstractQueryBuilder<DisMaxQueryBuilder>
|
|||
return new DisjunctionMaxQuery(luceneQueries, tieBreaker);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisMaxQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
DisMaxQueryBuilder disMax = new DisMaxQueryBuilder();
|
||||
List<QueryBuilder<?>> queryBuilders = readQueries(in);
|
||||
disMax.queries.addAll(queryBuilders);
|
||||
disMax.tieBreaker = in.readFloat();
|
||||
return disMax;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
writeQueries(out, queries);
|
||||
out.writeFloat(tieBreaker);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(queries, tieBreaker);
|
||||
|
|
|
@ -34,10 +34,25 @@ import java.io.IOException;
|
|||
public final class EmptyQueryBuilder extends AbstractQueryBuilder<EmptyQueryBuilder> {
|
||||
|
||||
public static final String NAME = "empty_query";
|
||||
|
||||
/** the one and only empty query builder */
|
||||
public static final EmptyQueryBuilder PROTOTYPE = new EmptyQueryBuilder();
|
||||
|
||||
/**
|
||||
* Construct an empty query. This query can *technically* be named and given a boost.
|
||||
*/
|
||||
public EmptyQueryBuilder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public EmptyQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWriteableName() {
|
||||
return NAME;
|
||||
|
@ -57,16 +72,6 @@ public final class EmptyQueryBuilder extends AbstractQueryBuilder<EmptyQueryBuil
|
|||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected EmptyQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
return new EmptyQueryBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return 31;
|
||||
|
|
|
@ -45,7 +45,6 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder<ExistsQueryBuilder>
|
|||
|
||||
public static final String NAME = "exists";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final ExistsQueryBuilder PROTOTYPE = new ExistsQueryBuilder("field");
|
||||
|
||||
public static final ParseField FIELD_FIELD = new ParseField("field");
|
||||
|
||||
|
@ -58,6 +57,19 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder<ExistsQueryBuilder>
|
|||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public ExistsQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the field name that has to exist for this query to match
|
||||
*/
|
||||
|
@ -152,16 +164,6 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder<ExistsQueryBuilder>
|
|||
return Objects.equals(fieldName, other.fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExistsQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
return new ExistsQueryBuilder(in.readString());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWriteableName() {
|
||||
return NAME;
|
||||
|
|
|
@ -39,13 +39,11 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
|||
|
||||
public static final String NAME = "field_masking_span";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final FieldMaskingSpanQueryBuilder PROTOTYPE =
|
||||
new FieldMaskingSpanQueryBuilder(new SpanTermQueryBuilder("field", "text"), "field");
|
||||
|
||||
private static final ParseField FIELD_FIELD = new ParseField("field");
|
||||
private static final ParseField QUERY_FIELD = new ParseField("query");
|
||||
|
||||
private final SpanQueryBuilder queryBuilder;
|
||||
private final SpanQueryBuilder<?> queryBuilder;
|
||||
|
||||
private final String fieldName;
|
||||
|
||||
|
@ -55,7 +53,7 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
|||
* @param queryBuilder inner {@link SpanQueryBuilder}
|
||||
* @param fieldName the field name
|
||||
*/
|
||||
public FieldMaskingSpanQueryBuilder(SpanQueryBuilder queryBuilder, String fieldName) {
|
||||
public FieldMaskingSpanQueryBuilder(SpanQueryBuilder<?> queryBuilder, String fieldName) {
|
||||
if (Strings.isEmpty(fieldName)) {
|
||||
throw new IllegalArgumentException("field name is null or empty");
|
||||
}
|
||||
|
@ -66,6 +64,21 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
|||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public FieldMaskingSpanQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
queryBuilder = (SpanQueryBuilder<?>) in.readQuery();
|
||||
fieldName = in.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(queryBuilder);
|
||||
out.writeString(fieldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the field name for this query
|
||||
*/
|
||||
|
@ -153,18 +166,6 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
|||
return new FieldMaskingSpanQuery((SpanQuery)innerQuery, fieldInQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FieldMaskingSpanQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
QueryBuilder innerQueryBuilder = in.readQuery();
|
||||
return new FieldMaskingSpanQueryBuilder((SpanQueryBuilder) innerQueryBuilder, in.readString());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(queryBuilder);
|
||||
out.writeString(fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(queryBuilder, fieldName);
|
||||
|
|
|
@ -49,7 +49,6 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i
|
|||
|
||||
public static final String NAME = "fuzzy";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final FuzzyQueryBuilder PROTOTYPE = new FuzzyQueryBuilder();
|
||||
|
||||
/** Default maximum edit distance. Defaults to AUTO. */
|
||||
public static final Fuzziness DEFAULT_FUZZINESS = Fuzziness.AUTO;
|
||||
|
@ -163,10 +162,29 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i
|
|||
this.value = convertToBytesRefIfString(value);
|
||||
}
|
||||
|
||||
private FuzzyQueryBuilder() {
|
||||
// for prototype
|
||||
this.fieldName = null;
|
||||
this.value = null;
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public FuzzyQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
value = in.readGenericValue();
|
||||
fuzziness = new Fuzziness(in);
|
||||
prefixLength = in.readVInt();
|
||||
maxExpansions = in.readVInt();
|
||||
transpositions = in.readBoolean();
|
||||
rewrite = in.readOptionalString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(this.fieldName);
|
||||
out.writeGenericValue(this.value);
|
||||
this.fuzziness.writeTo(out);
|
||||
out.writeVInt(this.prefixLength);
|
||||
out.writeVInt(this.maxExpansions);
|
||||
out.writeBoolean(this.transpositions);
|
||||
out.writeOptionalString(this.rewrite);
|
||||
}
|
||||
|
||||
public String fieldName() {
|
||||
|
@ -336,28 +354,6 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i
|
|||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FuzzyQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
FuzzyQueryBuilder fuzzyQueryBuilder = new FuzzyQueryBuilder(in.readString(), in.readGenericValue());
|
||||
fuzzyQueryBuilder.fuzziness = Fuzziness.readFuzzinessFrom(in);
|
||||
fuzzyQueryBuilder.prefixLength = in.readVInt();
|
||||
fuzzyQueryBuilder.maxExpansions = in.readVInt();
|
||||
fuzzyQueryBuilder.transpositions = in.readBoolean();
|
||||
fuzzyQueryBuilder.rewrite = in.readOptionalString();
|
||||
return fuzzyQueryBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(this.fieldName);
|
||||
out.writeGenericValue(this.value);
|
||||
this.fuzziness.writeTo(out);
|
||||
out.writeVInt(this.prefixLength);
|
||||
out.writeVInt(this.maxExpansions);
|
||||
out.writeBoolean(this.transpositions);
|
||||
out.writeOptionalString(this.rewrite);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(fieldName, value, fuzziness, prefixLength, maxExpansions, transpositions, rewrite);
|
||||
|
|
|
@ -57,8 +57,6 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
|
|||
|
||||
/** Default type for executing this query (memory as of this writing). */
|
||||
public static final GeoExecType DEFAULT_TYPE = GeoExecType.MEMORY;
|
||||
/** Needed for serialization. */
|
||||
public static final GeoBoundingBoxQueryBuilder PROTOTYPE = new GeoBoundingBoxQueryBuilder("");
|
||||
|
||||
private static final ParseField IGNORE_MALFORMED_FIELD = new ParseField("ignore_malformed");
|
||||
private static final ParseField TYPE_FIELD = new ParseField("type");
|
||||
|
@ -96,6 +94,27 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
|
|||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public GeoBoundingBoxQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
topLeft = in.readGeoPoint();
|
||||
bottomRight = in.readGeoPoint();
|
||||
type = GeoExecType.readTypeFrom(in);
|
||||
validationMethod = GeoValidationMethod.readFromStream(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeGeoPoint(topLeft);
|
||||
out.writeGeoPoint(bottomRight);
|
||||
type.writeTo(out);
|
||||
validationMethod.writeTo(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds top left point.
|
||||
* @param top The top latitude
|
||||
|
@ -453,26 +472,6 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
|
|||
return Objects.hash(topLeft, bottomRight, type, validationMethod, fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GeoBoundingBoxQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
String fieldName = in.readString();
|
||||
GeoBoundingBoxQueryBuilder geo = new GeoBoundingBoxQueryBuilder(fieldName);
|
||||
geo.topLeft = in.readGeoPoint();
|
||||
geo.bottomRight = in.readGeoPoint();
|
||||
geo.type = GeoExecType.readTypeFrom(in);
|
||||
geo.validationMethod = GeoValidationMethod.readGeoValidationMethodFrom(in);
|
||||
return geo;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeGeoPoint(topLeft);
|
||||
out.writeGeoPoint(bottomRight);
|
||||
type.writeTo(out);
|
||||
validationMethod.writeTo(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWriteableName() {
|
||||
return NAME;
|
||||
|
|
|
@ -66,8 +66,6 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
|
|||
/** Default for optimising query through pre computed bounding box query. */
|
||||
public static final String DEFAULT_OPTIMIZE_BBOX = "memory";
|
||||
|
||||
public static final GeoDistanceQueryBuilder PROTOTYPE = new GeoDistanceQueryBuilder("_na_");
|
||||
|
||||
private static final ParseField VALIDATION_METHOD_FIELD = new ParseField("validation_method");
|
||||
private static final ParseField IGNORE_MALFORMED_FIELD = new ParseField("ignore_malformed");
|
||||
private static final ParseField COERCE_FIELD = new ParseField("coerce", "normalize");
|
||||
|
@ -99,6 +97,29 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
|
|||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public GeoDistanceQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
distance = in.readDouble();
|
||||
validationMethod = GeoValidationMethod.readFromStream(in);
|
||||
center = in.readGeoPoint();
|
||||
optimizeBbox = in.readString();
|
||||
geoDistance = GeoDistance.readFromStream(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeDouble(distance);
|
||||
validationMethod.writeTo(out);
|
||||
out.writeGeoPoint(center);
|
||||
out.writeString(optimizeBbox);
|
||||
geoDistance.writeTo(out);
|
||||
}
|
||||
|
||||
/** Name of the field this query is operating on. */
|
||||
public String fieldName() {
|
||||
return this.fieldName;
|
||||
|
@ -401,28 +422,6 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
|
|||
Objects.equals(geoDistance, other.geoDistance);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GeoDistanceQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
String fieldName = in.readString();
|
||||
GeoDistanceQueryBuilder result = new GeoDistanceQueryBuilder(fieldName);
|
||||
result.distance = in.readDouble();
|
||||
result.validationMethod = GeoValidationMethod.readGeoValidationMethodFrom(in);
|
||||
result.center = in.readGeoPoint();
|
||||
result.optimizeBbox = in.readString();
|
||||
result.geoDistance = GeoDistance.readGeoDistanceFrom(in);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeDouble(distance);
|
||||
validationMethod.writeTo(out);
|
||||
out.writeGeoPoint(center);
|
||||
out.writeString(optimizeBbox);
|
||||
geoDistance.writeTo(out);
|
||||
}
|
||||
|
||||
private QueryValidationException checkLatLon(boolean indexCreatedBeforeV2_0) {
|
||||
// validation was not available prior to 2.x, so to support bwc percolation queries we only ignore_malformed on 2.x created indexes
|
||||
if (GeoValidationMethod.isIgnoreMalformed(validationMethod) || indexCreatedBeforeV2_0) {
|
||||
|
|
|
@ -59,8 +59,6 @@ public class GeoDistanceRangeQueryBuilder extends AbstractQueryBuilder<GeoDistan
|
|||
public static final DistanceUnit DEFAULT_UNIT = DistanceUnit.DEFAULT;
|
||||
public static final String DEFAULT_OPTIMIZE_BBOX = "memory";
|
||||
|
||||
public static final GeoDistanceRangeQueryBuilder PROTOTYPE = new GeoDistanceRangeQueryBuilder("_na_", new GeoPoint());
|
||||
|
||||
private static final ParseField FROM_FIELD = new ParseField("from");
|
||||
private static final ParseField TO_FIELD = new ParseField("to");
|
||||
private static final ParseField INCLUDE_LOWER_FIELD = new ParseField("include_lower");
|
||||
|
@ -114,6 +112,37 @@ public class GeoDistanceRangeQueryBuilder extends AbstractQueryBuilder<GeoDistan
|
|||
this(fieldName, geohash == null ? null : new GeoPoint().resetFromGeoHash(geohash));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public GeoDistanceRangeQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
point = in.readGeoPoint();
|
||||
from = in.readGenericValue();
|
||||
to = in.readGenericValue();
|
||||
includeLower = in.readBoolean();
|
||||
includeUpper = in.readBoolean();
|
||||
unit = DistanceUnit.valueOf(in.readString());
|
||||
geoDistance = GeoDistance.readFromStream(in);
|
||||
optimizeBbox = in.readString();
|
||||
validationMethod = GeoValidationMethod.readFromStream(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeGeoPoint(point);
|
||||
out.writeGenericValue(from);
|
||||
out.writeGenericValue(to);
|
||||
out.writeBoolean(includeLower);
|
||||
out.writeBoolean(includeUpper);
|
||||
out.writeString(unit.name());
|
||||
geoDistance.writeTo(out);;
|
||||
out.writeString(optimizeBbox);
|
||||
validationMethod.writeTo(out);
|
||||
}
|
||||
|
||||
public String fieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
@ -536,34 +565,6 @@ public class GeoDistanceRangeQueryBuilder extends AbstractQueryBuilder<GeoDistan
|
|||
return queryBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GeoDistanceRangeQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
GeoDistanceRangeQueryBuilder queryBuilder = new GeoDistanceRangeQueryBuilder(in.readString(), in.readGeoPoint());
|
||||
queryBuilder.from = in.readGenericValue();
|
||||
queryBuilder.to = in.readGenericValue();
|
||||
queryBuilder.includeLower = in.readBoolean();
|
||||
queryBuilder.includeUpper = in.readBoolean();
|
||||
queryBuilder.unit = DistanceUnit.valueOf(in.readString());
|
||||
queryBuilder.geoDistance = GeoDistance.readGeoDistanceFrom(in);
|
||||
queryBuilder.optimizeBbox = in.readString();
|
||||
queryBuilder.validationMethod = GeoValidationMethod.readGeoValidationMethodFrom(in);
|
||||
return queryBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeGeoPoint(point);
|
||||
out.writeGenericValue(from);
|
||||
out.writeGenericValue(to);
|
||||
out.writeBoolean(includeLower);
|
||||
out.writeBoolean(includeUpper);
|
||||
out.writeString(unit.name());
|
||||
geoDistance.writeTo(out);;
|
||||
out.writeString(optimizeBbox);
|
||||
validationMethod.writeTo(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doEquals(GeoDistanceRangeQueryBuilder other) {
|
||||
return ((Objects.equals(fieldName, other.fieldName)) &&
|
||||
|
|
|
@ -40,7 +40,6 @@ import org.elasticsearch.index.search.geo.GeoPolygonQuery;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
@ -49,11 +48,6 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQuery
|
|||
public static final String NAME = "geo_polygon";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
|
||||
private static final List<GeoPoint> PROTO_SHAPE = Arrays.asList(new GeoPoint(1.0, 1.0), new GeoPoint(1.0, 2.0),
|
||||
new GeoPoint(2.0, 1.0));
|
||||
|
||||
public static final GeoPolygonQueryBuilder PROTOTYPE = new GeoPolygonQueryBuilder("field", PROTO_SHAPE);
|
||||
|
||||
private static final ParseField COERCE_FIELD = new ParseField("coerce", "normalize");
|
||||
private static final ParseField IGNORE_MALFORMED_FIELD = new ParseField("ignore_malformed");
|
||||
private static final ParseField VALIDATION_METHOD = new ParseField("validation_method");
|
||||
|
@ -90,6 +84,30 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQuery
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public GeoPolygonQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
int size = in.readVInt();
|
||||
shell = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
shell.add(in.readGeoPoint());
|
||||
}
|
||||
validationMethod = GeoValidationMethod.readFromStream(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeVInt(shell.size());
|
||||
for (GeoPoint point : shell) {
|
||||
out.writeGeoPoint(point);
|
||||
}
|
||||
validationMethod.writeTo(out);
|
||||
}
|
||||
|
||||
public String fieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
@ -268,29 +286,6 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQuery
|
|||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GeoPolygonQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
String fieldName = in.readString();
|
||||
List<GeoPoint> shell = new ArrayList<>();
|
||||
int size = in.readVInt();
|
||||
for (int i = 0; i < size; i++) {
|
||||
shell.add(in.readGeoPoint());
|
||||
}
|
||||
GeoPolygonQueryBuilder builder = new GeoPolygonQueryBuilder(fieldName, shell);
|
||||
builder.validationMethod = GeoValidationMethod.readGeoValidationMethodFrom(in);
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeVInt(shell.size());
|
||||
for (GeoPoint point : shell) {
|
||||
out.writeGeoPoint(point);
|
||||
}
|
||||
validationMethod.writeTo(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doEquals(GeoPolygonQueryBuilder other) {
|
||||
return Objects.equals(validationMethod, other.validationMethod)
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.elasticsearch.common.Strings;
|
|||
import org.elasticsearch.common.geo.ShapeRelation;
|
||||
import org.elasticsearch.common.geo.ShapesAvailability;
|
||||
import org.elasticsearch.common.geo.SpatialStrategy;
|
||||
import org.elasticsearch.common.geo.builders.PointBuilder;
|
||||
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
|
@ -61,8 +60,6 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
|
|||
public static final String DEFAULT_SHAPE_FIELD_NAME = "shape";
|
||||
public static final ShapeRelation DEFAULT_SHAPE_RELATION = ShapeRelation.INTERSECTS;
|
||||
|
||||
public static final GeoShapeQueryBuilder PROTOTYPE = new GeoShapeQueryBuilder("field", new PointBuilder());
|
||||
|
||||
private static final ParseField SHAPE_FIELD = new ParseField("shape");
|
||||
private static final ParseField STRATEGY_FIELD = new ParseField("strategy");
|
||||
private static final ParseField RELATION_FIELD = new ParseField("relation");
|
||||
|
@ -131,6 +128,44 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
|
|||
this.indexedShapeType = indexedShapeType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public GeoShapeQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
if (in.readBoolean()) {
|
||||
shape = in.readShape();
|
||||
indexedShapeId = null;
|
||||
indexedShapeType = null;
|
||||
} else {
|
||||
shape = null;
|
||||
indexedShapeId = in.readOptionalString();
|
||||
indexedShapeType = in.readOptionalString();
|
||||
indexedShapeIndex = in.readOptionalString();
|
||||
indexedShapePath = in.readOptionalString();
|
||||
}
|
||||
relation = ShapeRelation.DISJOINT.readFrom(in);
|
||||
strategy = in.readOptionalWriteable(SpatialStrategy.RECURSIVE::readFrom);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
boolean hasShape = shape != null;
|
||||
out.writeBoolean(hasShape);
|
||||
if (hasShape) {
|
||||
out.writeShape(shape);
|
||||
} else {
|
||||
out.writeOptionalString(indexedShapeId);
|
||||
out.writeOptionalString(indexedShapeType);
|
||||
out.writeOptionalString(indexedShapeIndex);
|
||||
out.writeOptionalString(indexedShapePath);
|
||||
}
|
||||
relation.writeTo(out);
|
||||
out.writeOptionalWriteable(strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the field that will be queried
|
||||
*/
|
||||
|
@ -495,54 +530,6 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
|
|||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GeoShapeQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
String fieldName = in.readString();
|
||||
GeoShapeQueryBuilder builder;
|
||||
if (in.readBoolean()) {
|
||||
builder = new GeoShapeQueryBuilder(fieldName, in.readShape());
|
||||
} else {
|
||||
String indexedShapeId = in.readOptionalString();
|
||||
String indexedShapeType = in.readOptionalString();
|
||||
String indexedShapeIndex = in.readOptionalString();
|
||||
String indexedShapePath = in.readOptionalString();
|
||||
builder = new GeoShapeQueryBuilder(fieldName, indexedShapeId, indexedShapeType);
|
||||
if (indexedShapeIndex != null) {
|
||||
builder.indexedShapeIndex = indexedShapeIndex;
|
||||
}
|
||||
if (indexedShapePath != null) {
|
||||
builder.indexedShapePath = indexedShapePath;
|
||||
}
|
||||
}
|
||||
builder.relation = ShapeRelation.DISJOINT.readFrom(in);
|
||||
if (in.readBoolean()) {
|
||||
builder.strategy = SpatialStrategy.RECURSIVE.readFrom(in);
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
boolean hasShape = shape != null;
|
||||
out.writeBoolean(hasShape);
|
||||
if (hasShape) {
|
||||
out.writeShape(shape);
|
||||
} else {
|
||||
out.writeOptionalString(indexedShapeId);
|
||||
out.writeOptionalString(indexedShapeType);
|
||||
out.writeOptionalString(indexedShapeIndex);
|
||||
out.writeOptionalString(indexedShapePath);
|
||||
}
|
||||
relation.writeTo(out);
|
||||
if (strategy == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
strategy.writeTo(out);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doEquals(GeoShapeQueryBuilder other) {
|
||||
return Objects.equals(fieldName, other.fieldName)
|
||||
|
|
|
@ -40,7 +40,7 @@ public enum GeoValidationMethod implements Writeable<GeoValidationMethod>{
|
|||
public static final GeoValidationMethod DEFAULT = STRICT;
|
||||
public static final boolean DEFAULT_LENIENT_PARSING = (DEFAULT != STRICT);
|
||||
|
||||
public static GeoValidationMethod readGeoValidationMethodFrom(StreamInput in) throws IOException {
|
||||
public static GeoValidationMethod readFromStream(StreamInput in) throws IOException {
|
||||
return GeoValidationMethod.values()[in.readVInt()];
|
||||
}
|
||||
|
||||
|
|
|
@ -98,7 +98,6 @@ public class GeohashCellQuery {
|
|||
* <code>false</code>.
|
||||
*/
|
||||
public static class Builder extends AbstractQueryBuilder<Builder> {
|
||||
public static final Builder PROTOTYPE = new Builder("field", new GeoPoint());
|
||||
// we need to store the geohash rather than the corresponding point,
|
||||
// because a transformation from a geohash to a point an back to the
|
||||
// geohash will extend the accuracy of the hash to max precision
|
||||
|
@ -128,6 +127,25 @@ public class GeohashCellQuery {
|
|||
this.neighbors = neighbors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public Builder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
geohash = in.readString();
|
||||
levels = in.readOptionalVInt();
|
||||
neighbors = in.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeString(geohash);
|
||||
out.writeOptionalVInt(levels);
|
||||
out.writeBoolean(neighbors);
|
||||
}
|
||||
|
||||
public Builder point(GeoPoint point) {
|
||||
this.geohash = point.getGeohash();
|
||||
return this;
|
||||
|
@ -307,30 +325,6 @@ public class GeohashCellQuery {
|
|||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Builder doReadFrom(StreamInput in) throws IOException {
|
||||
String field = in.readString();
|
||||
String geohash = in.readString();
|
||||
Builder builder = new Builder(field, geohash);
|
||||
if (in.readBoolean()) {
|
||||
builder.precision(in.readVInt());
|
||||
}
|
||||
builder.neighbors(in.readBoolean());
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeString(geohash);
|
||||
boolean hasLevels = levels != null;
|
||||
out.writeBoolean(hasLevels);
|
||||
if (hasLevels) {
|
||||
out.writeVInt(levels);
|
||||
}
|
||||
out.writeBoolean(neighbors);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doEquals(Builder other) {
|
||||
return Objects.equals(fieldName, other.fieldName)
|
||||
|
|
|
@ -68,8 +68,6 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
*/
|
||||
public static final ScoreMode DEFAULT_SCORE_MODE = ScoreMode.None;
|
||||
|
||||
public static final HasChildQueryBuilder PROTOTYPE = new HasChildQueryBuilder("", EmptyQueryBuilder.PROTOTYPE);
|
||||
|
||||
private static final ParseField QUERY_FIELD = new ParseField("query", "filter");
|
||||
private static final ParseField TYPE_FIELD = new ParseField("type", "child_type");
|
||||
private static final ParseField MAX_CHILDREN_FIELD = new ParseField("max_children");
|
||||
|
@ -114,6 +112,29 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
this.query = query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public HasChildQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
type = in.readString();
|
||||
minChildren = in.readInt();
|
||||
maxChildren = in.readInt();
|
||||
scoreMode = ScoreMode.values()[in.readVInt()];
|
||||
query = in.readQuery();
|
||||
innerHitBuilder = in.readOptionalWriteable(InnerHitBuilder::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(type);
|
||||
out.writeInt(minChildren());
|
||||
out.writeInt(maxChildren());
|
||||
out.writeVInt(scoreMode.ordinal());
|
||||
out.writeQuery(query);
|
||||
out.writeOptionalWriteable(innerHitBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines how the scores from the matching child documents are mapped into the parent document.
|
||||
*/
|
||||
|
@ -451,36 +472,6 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
return Objects.hash(query, type, scoreMode, minChildren, maxChildren, innerHitBuilder);
|
||||
}
|
||||
|
||||
protected HasChildQueryBuilder(StreamInput in) throws IOException {
|
||||
type = in.readString();
|
||||
minChildren = in.readInt();
|
||||
maxChildren = in.readInt();
|
||||
final int ordinal = in.readVInt();
|
||||
scoreMode = ScoreMode.values()[ordinal];
|
||||
query = in.readQuery();
|
||||
innerHitBuilder = InnerHitBuilder.optionalReadFromStream(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HasChildQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
return new HasChildQueryBuilder(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(type);
|
||||
out.writeInt(minChildren());
|
||||
out.writeInt(maxChildren());
|
||||
out.writeVInt(scoreMode.ordinal());
|
||||
out.writeQuery(query);
|
||||
if (innerHitBuilder != null) {
|
||||
out.writeBoolean(true);
|
||||
innerHitBuilder.writeTo(out);
|
||||
} else {
|
||||
out.writeBoolean(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected QueryBuilder<?> doRewrite(QueryRewriteContext queryRewriteContext) throws IOException {
|
||||
QueryBuilder<?> rewrite = query.rewrite(queryRewriteContext);
|
||||
|
|
|
@ -46,7 +46,6 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
|
|||
|
||||
public static final String NAME = "has_parent";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final HasParentQueryBuilder PROTOTYPE = new HasParentQueryBuilder("", EmptyQueryBuilder.PROTOTYPE);
|
||||
|
||||
public static final boolean DEFAULT_SCORE = false;
|
||||
|
||||
|
@ -86,6 +85,25 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public HasParentQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
type = in.readString();
|
||||
score = in.readBoolean();
|
||||
query = in.readQuery();
|
||||
innerHit = in.readOptionalWriteable(InnerHitBuilder::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(type);
|
||||
out.writeBoolean(score);
|
||||
out.writeQuery(query);
|
||||
out.writeOptionalWriteable(innerHit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines if the parent score is mapped into the child documents.
|
||||
*/
|
||||
|
@ -263,31 +281,6 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
|
|||
return NAME;
|
||||
}
|
||||
|
||||
protected HasParentQueryBuilder(StreamInput in) throws IOException {
|
||||
type = in.readString();
|
||||
score = in.readBoolean();
|
||||
query = in.readQuery();
|
||||
innerHit = InnerHitBuilder.optionalReadFromStream(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HasParentQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
return new HasParentQueryBuilder(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(type);
|
||||
out.writeBoolean(score);
|
||||
out.writeQuery(query);
|
||||
if (innerHit != null) {
|
||||
out.writeBoolean(true);
|
||||
innerHit.writeTo(out);
|
||||
} else {
|
||||
out.writeBoolean(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doEquals(HasParentQueryBuilder that) {
|
||||
return Objects.equals(query, that.query)
|
||||
|
|
|
@ -49,7 +49,6 @@ public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> {
|
|||
|
||||
public static final String NAME = "ids";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final IdsQueryBuilder PROTOTYPE = new IdsQueryBuilder();
|
||||
|
||||
private static final ParseField TYPE_FIELD = new ParseField("type", "types", "_type");
|
||||
private static final ParseField VALUES_FIELD = new ParseField("values");
|
||||
|
@ -58,7 +57,6 @@ public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> {
|
|||
|
||||
private final String[] types;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new IdsQueryBuilder without providing the types of the documents to look for
|
||||
*/
|
||||
|
@ -76,6 +74,21 @@ public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> {
|
|||
this.types = types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public IdsQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
types = in.readStringArray();
|
||||
Collections.addAll(ids, in.readStringArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeStringArray(types);
|
||||
out.writeStringArray(ids.toArray(new String[ids.size()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the types used in this query
|
||||
*/
|
||||
|
@ -208,19 +221,6 @@ public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> {
|
|||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IdsQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
IdsQueryBuilder idsQueryBuilder = new IdsQueryBuilder(in.readStringArray());
|
||||
idsQueryBuilder.addIds(in.readStringArray());
|
||||
return idsQueryBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeStringArray(types);
|
||||
out.writeStringArray(ids.toArray(new String[ids.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(ids, Arrays.hashCode(types));
|
||||
|
|
|
@ -41,7 +41,6 @@ public class IndicesQueryBuilder extends AbstractQueryBuilder<IndicesQueryBuilde
|
|||
|
||||
public static final String NAME = "indices";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final IndicesQueryBuilder PROTOTYPE = new IndicesQueryBuilder(EmptyQueryBuilder.PROTOTYPE, "index");
|
||||
|
||||
private static final ParseField QUERY_FIELD = new ParseField("query");
|
||||
private static final ParseField NO_MATCH_QUERY = new ParseField("no_match_query");
|
||||
|
@ -65,6 +64,23 @@ public class IndicesQueryBuilder extends AbstractQueryBuilder<IndicesQueryBuilde
|
|||
this.indices = indices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public IndicesQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
innerQuery = in.readQuery();
|
||||
indices = in.readStringArray();
|
||||
noMatchQuery = in.readQuery();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(innerQuery);
|
||||
out.writeStringArray(indices);
|
||||
out.writeQuery(noMatchQuery);
|
||||
}
|
||||
|
||||
public QueryBuilder<?> innerQuery() {
|
||||
return this.innerQuery;
|
||||
}
|
||||
|
@ -202,20 +218,6 @@ public class IndicesQueryBuilder extends AbstractQueryBuilder<IndicesQueryBuilde
|
|||
return noMatchQuery.toQuery(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IndicesQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
IndicesQueryBuilder indicesQueryBuilder = new IndicesQueryBuilder(in.readQuery(), in.readStringArray());
|
||||
indicesQueryBuilder.noMatchQuery = in.readQuery();
|
||||
return indicesQueryBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(innerQuery);
|
||||
out.writeStringArray(indices);
|
||||
out.writeQuery(noMatchQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int doHashCode() {
|
||||
return Objects.hash(innerQuery, noMatchQuery, Arrays.hashCode(indices));
|
||||
|
|
|
@ -37,7 +37,21 @@ public class MatchAllQueryBuilder extends AbstractQueryBuilder<MatchAllQueryBuil
|
|||
|
||||
public static final String NAME = "match_all";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final MatchAllQueryBuilder PROTOTYPE = new MatchAllQueryBuilder();
|
||||
|
||||
public MatchAllQueryBuilder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public MatchAllQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
// only superclass has state
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
|
@ -91,16 +105,6 @@ public class MatchAllQueryBuilder extends AbstractQueryBuilder<MatchAllQueryBuil
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MatchAllQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
return new MatchAllQueryBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
//nothing to write really
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWriteableName() {
|
||||
return NAME;
|
||||
|
|
|
@ -38,7 +38,20 @@ public class MatchNoneQueryBuilder extends AbstractQueryBuilder<MatchNoneQueryBu
|
|||
public static final String NAME = "match_none";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
|
||||
public static final MatchNoneQueryBuilder PROTOTYPE = new MatchNoneQueryBuilder();
|
||||
public MatchNoneQueryBuilder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public MatchNoneQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
// all state is in the superclass
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
|
@ -93,16 +106,6 @@ public class MatchNoneQueryBuilder extends AbstractQueryBuilder<MatchNoneQueryBu
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MatchNoneQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
return new MatchNoneQueryBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
//nothing to write really
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWriteableName() {
|
||||
return NAME;
|
||||
|
|
|
@ -42,8 +42,6 @@ public class MatchPhrasePrefixQueryBuilder extends AbstractQueryBuilder<MatchPhr
|
|||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final ParseField MAX_EXPANSIONS_FIELD = new ParseField("max_expansions");
|
||||
|
||||
public static final MatchPhrasePrefixQueryBuilder PROTOTYPE = new MatchPhrasePrefixQueryBuilder("", "");
|
||||
|
||||
private final String fieldName;
|
||||
|
||||
private final Object value;
|
||||
|
@ -65,6 +63,27 @@ public class MatchPhrasePrefixQueryBuilder extends AbstractQueryBuilder<MatchPhr
|
|||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public MatchPhrasePrefixQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
value = in.readGenericValue();
|
||||
slop = in.readVInt();
|
||||
maxExpansions = in.readVInt();
|
||||
analyzer = in.readOptionalString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeGenericValue(value);
|
||||
out.writeVInt(slop);
|
||||
out.writeVInt(maxExpansions);
|
||||
out.writeOptionalString(analyzer);
|
||||
}
|
||||
|
||||
/** Returns the field name used in this query. */
|
||||
public String fieldName() {
|
||||
return this.fieldName;
|
||||
|
@ -158,24 +177,6 @@ public class MatchPhrasePrefixQueryBuilder extends AbstractQueryBuilder<MatchPhr
|
|||
return matchQuery.parse(MatchQuery.Type.PHRASE_PREFIX, fieldName, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MatchPhrasePrefixQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
MatchPhrasePrefixQueryBuilder matchQuery = new MatchPhrasePrefixQueryBuilder(in.readString(), in.readGenericValue());
|
||||
matchQuery.slop = in.readVInt();
|
||||
matchQuery.maxExpansions = in.readVInt();
|
||||
matchQuery.analyzer = in.readOptionalString();
|
||||
return matchQuery;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeGenericValue(value);
|
||||
out.writeVInt(slop);
|
||||
out.writeVInt(maxExpansions);
|
||||
out.writeOptionalString(analyzer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doEquals(MatchPhrasePrefixQueryBuilder other) {
|
||||
return Objects.equals(fieldName, other.fieldName) &&
|
||||
|
|
|
@ -40,8 +40,6 @@ public class MatchPhraseQueryBuilder extends AbstractQueryBuilder<MatchPhraseQue
|
|||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final ParseField SLOP_FIELD = new ParseField("slop", "phrase_slop");
|
||||
|
||||
public static final MatchPhraseQueryBuilder PROTOTYPE = new MatchPhraseQueryBuilder("", "");
|
||||
|
||||
private final String fieldName;
|
||||
|
||||
private final Object value;
|
||||
|
@ -61,6 +59,25 @@ public class MatchPhraseQueryBuilder extends AbstractQueryBuilder<MatchPhraseQue
|
|||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public MatchPhraseQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
value = in.readGenericValue();
|
||||
slop = in.readVInt();
|
||||
analyzer = in.readOptionalString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeGenericValue(value);
|
||||
out.writeVInt(slop);
|
||||
out.writeOptionalString(analyzer);
|
||||
}
|
||||
|
||||
/** Returns the field name used in this query. */
|
||||
public String fieldName() {
|
||||
return this.fieldName;
|
||||
|
@ -133,22 +150,6 @@ public class MatchPhraseQueryBuilder extends AbstractQueryBuilder<MatchPhraseQue
|
|||
return matchQuery.parse(MatchQuery.Type.PHRASE, fieldName, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MatchPhraseQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
MatchPhraseQueryBuilder matchQuery = new MatchPhraseQueryBuilder(in.readString(), in.readGenericValue());
|
||||
matchQuery.slop = in.readVInt();
|
||||
matchQuery.analyzer = in.readOptionalString();
|
||||
return matchQuery;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeGenericValue(value);
|
||||
out.writeVInt(slop);
|
||||
out.writeOptionalString(analyzer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doEquals(MatchPhraseQueryBuilder other) {
|
||||
return Objects.equals(fieldName, other.fieldName) && Objects.equals(value, other.value) && Objects.equals(analyzer, other.analyzer)
|
||||
|
|
|
@ -102,8 +102,6 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
|
||||
private Float cutoffFrequency = null;
|
||||
|
||||
public static final MatchQueryBuilder PROTOTYPE = new MatchQueryBuilder("","");
|
||||
|
||||
/**
|
||||
* Constructs a new match query.
|
||||
*/
|
||||
|
@ -118,6 +116,49 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public MatchQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
value = in.readGenericValue();
|
||||
type = MatchQuery.Type.readFromStream(in);
|
||||
operator = Operator.readFromStream(in);
|
||||
slop = in.readVInt();
|
||||
prefixLength = in.readVInt();
|
||||
maxExpansions = in.readVInt();
|
||||
fuzzyTranspositions = in.readBoolean();
|
||||
lenient = in.readBoolean();
|
||||
zeroTermsQuery = MatchQuery.ZeroTermsQuery.readFromStream(in);
|
||||
// optional fields
|
||||
analyzer = in.readOptionalString();
|
||||
minimumShouldMatch = in.readOptionalString();
|
||||
fuzzyRewrite = in.readOptionalString();
|
||||
fuzziness = in.readOptionalWriteable(Fuzziness::new);
|
||||
cutoffFrequency = in.readOptionalFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeGenericValue(value);
|
||||
type.writeTo(out);
|
||||
operator.writeTo(out);
|
||||
out.writeVInt(slop);
|
||||
out.writeVInt(prefixLength);
|
||||
out.writeVInt(maxExpansions);
|
||||
out.writeBoolean(fuzzyTranspositions);
|
||||
out.writeBoolean(lenient);
|
||||
zeroTermsQuery.writeTo(out);
|
||||
// optional fields
|
||||
out.writeOptionalString(analyzer);
|
||||
out.writeOptionalString(minimumShouldMatch);
|
||||
out.writeOptionalString(fuzzyRewrite);
|
||||
out.writeOptionalWriteable(fuzziness);
|
||||
out.writeOptionalFloat(cutoffFrequency);
|
||||
}
|
||||
|
||||
/** Returns the field name used in this query. */
|
||||
public String fieldName() {
|
||||
return this.fieldName;
|
||||
|
@ -461,60 +502,6 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
fuzzyRewrite, lenient, fuzzyTranspositions, zeroTermsQuery, cutoffFrequency);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MatchQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
MatchQueryBuilder matchQuery = new MatchQueryBuilder(in.readString(), in.readGenericValue());
|
||||
matchQuery.type = MatchQuery.Type.readTypeFrom(in);
|
||||
matchQuery.operator = Operator.readOperatorFrom(in);
|
||||
matchQuery.slop = in.readVInt();
|
||||
matchQuery.prefixLength = in.readVInt();
|
||||
matchQuery.maxExpansions = in.readVInt();
|
||||
matchQuery.fuzzyTranspositions = in.readBoolean();
|
||||
matchQuery.lenient = in.readBoolean();
|
||||
matchQuery.zeroTermsQuery = MatchQuery.ZeroTermsQuery.readZeroTermsQueryFrom(in);
|
||||
// optional fields
|
||||
matchQuery.analyzer = in.readOptionalString();
|
||||
matchQuery.minimumShouldMatch = in.readOptionalString();
|
||||
matchQuery.fuzzyRewrite = in.readOptionalString();
|
||||
if (in.readBoolean()) {
|
||||
matchQuery.fuzziness = Fuzziness.readFuzzinessFrom(in);
|
||||
}
|
||||
if (in.readBoolean()) {
|
||||
matchQuery.cutoffFrequency = in.readFloat();
|
||||
}
|
||||
return matchQuery;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeGenericValue(value);
|
||||
type.writeTo(out);
|
||||
operator.writeTo(out);
|
||||
out.writeVInt(slop);
|
||||
out.writeVInt(prefixLength);
|
||||
out.writeVInt(maxExpansions);
|
||||
out.writeBoolean(fuzzyTranspositions);
|
||||
out.writeBoolean(lenient);
|
||||
zeroTermsQuery.writeTo(out);
|
||||
// optional fields
|
||||
out.writeOptionalString(analyzer);
|
||||
out.writeOptionalString(minimumShouldMatch);
|
||||
out.writeOptionalString(fuzzyRewrite);
|
||||
if (fuzziness == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
fuzziness.writeTo(out);
|
||||
}
|
||||
if (cutoffFrequency == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
out.writeFloat(cutoffFrequency);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWriteableName() {
|
||||
return NAME;
|
||||
|
|
|
@ -82,7 +82,6 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
|
|||
|
||||
public static final String NAME = "more_like_this";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME, "mlt");
|
||||
public static final MoreLikeThisQueryBuilder PROTOTYPE = new MoreLikeThisQueryBuilder(new String[]{"_na_"}, null);
|
||||
|
||||
public static final int DEFAULT_MAX_QUERY_TERMS = XMoreLikeThis.DEFAULT_MAX_QUERY_TERMS;
|
||||
public static final int DEFAULT_MIN_TERM_FREQ = XMoreLikeThis.DEFAULT_MIN_TERM_FREQ;
|
||||
|
@ -233,7 +232,7 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
|
|||
perFieldAnalyzer = (Map<String, String>) in.readGenericValue();
|
||||
routing = in.readOptionalString();
|
||||
version = in.readLong();
|
||||
versionType = VersionType.readVersionTypeFrom(in);
|
||||
versionType = VersionType.readFromStream(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -510,6 +509,51 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
|
|||
this.likeItems = Optional.ofNullable(likeItems).orElse(new Item[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public MoreLikeThisQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fields = in.readOptionalStringArray();
|
||||
likeTexts = in.readStringArray();
|
||||
likeItems = in.readList(Item::new).toArray(new Item[0]);
|
||||
unlikeTexts = in.readStringArray();
|
||||
unlikeItems = in.readList(Item::new).toArray(new Item[0]);
|
||||
maxQueryTerms = in.readVInt();
|
||||
minTermFreq = in.readVInt();
|
||||
minDocFreq = in.readVInt();
|
||||
maxDocFreq = in.readVInt();
|
||||
minWordLength = in.readVInt();
|
||||
maxWordLength = in.readVInt();
|
||||
stopWords = in.readOptionalStringArray();
|
||||
analyzer = in.readOptionalString();
|
||||
minimumShouldMatch = in.readString();
|
||||
boostTerms = (Float) in.readGenericValue();
|
||||
include = in.readBoolean();
|
||||
failOnUnsupportedField = in.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeOptionalStringArray(fields);
|
||||
out.writeStringArray(likeTexts);
|
||||
out.writeList(Arrays.asList(likeItems));
|
||||
out.writeStringArray(unlikeTexts);
|
||||
out.writeList(Arrays.asList(unlikeItems));
|
||||
out.writeVInt(maxQueryTerms);
|
||||
out.writeVInt(minTermFreq);
|
||||
out.writeVInt(minDocFreq);
|
||||
out.writeVInt(maxDocFreq);
|
||||
out.writeVInt(minWordLength);
|
||||
out.writeVInt(maxWordLength);
|
||||
out.writeOptionalStringArray(stopWords);
|
||||
out.writeOptionalString(analyzer);
|
||||
out.writeString(minimumShouldMatch);
|
||||
out.writeGenericValue(boostTerms);
|
||||
out.writeBoolean(include);
|
||||
out.writeBoolean(failOnUnsupportedField);
|
||||
}
|
||||
|
||||
public String[] fields() {
|
||||
return this.fields;
|
||||
}
|
||||
|
@ -1141,66 +1185,6 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MoreLikeThisQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
String[] fields = in.readOptionalStringArray();
|
||||
String[] likeTexts = in.readStringArray();
|
||||
Item[] likeItems = readItems(in);
|
||||
MoreLikeThisQueryBuilder moreLikeThisQueryBuilder = new MoreLikeThisQueryBuilder(fields, likeTexts, likeItems);
|
||||
moreLikeThisQueryBuilder.unlikeTexts = in.readStringArray();
|
||||
moreLikeThisQueryBuilder.unlikeItems = readItems(in);
|
||||
moreLikeThisQueryBuilder.maxQueryTerms = in.readVInt();
|
||||
moreLikeThisQueryBuilder.minTermFreq = in.readVInt();
|
||||
moreLikeThisQueryBuilder.minDocFreq = in.readVInt();
|
||||
moreLikeThisQueryBuilder.maxDocFreq = in.readVInt();
|
||||
moreLikeThisQueryBuilder.minWordLength = in.readVInt();
|
||||
moreLikeThisQueryBuilder.maxWordLength = in.readVInt();
|
||||
moreLikeThisQueryBuilder.stopWords = in.readOptionalStringArray();
|
||||
moreLikeThisQueryBuilder.analyzer = in.readOptionalString();
|
||||
moreLikeThisQueryBuilder.minimumShouldMatch = in.readString();
|
||||
moreLikeThisQueryBuilder.boostTerms = (Float) in.readGenericValue();
|
||||
moreLikeThisQueryBuilder.include = in.readBoolean();
|
||||
moreLikeThisQueryBuilder.failOnUnsupportedField = in.readBoolean();
|
||||
return moreLikeThisQueryBuilder;
|
||||
}
|
||||
|
||||
private static Item[] readItems(StreamInput in) throws IOException {
|
||||
int size = in.readVInt();
|
||||
Item[] items = new Item[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
items[i] = new Item(in);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeOptionalStringArray(fields);
|
||||
out.writeStringArray(likeTexts);
|
||||
writeItems(likeItems, out);
|
||||
out.writeStringArray(unlikeTexts);
|
||||
writeItems(unlikeItems, out);
|
||||
out.writeVInt(maxQueryTerms);
|
||||
out.writeVInt(minTermFreq);
|
||||
out.writeVInt(minDocFreq);
|
||||
out.writeVInt(maxDocFreq);
|
||||
out.writeVInt(minWordLength);
|
||||
out.writeVInt(maxWordLength);
|
||||
out.writeOptionalStringArray(stopWords);
|
||||
out.writeOptionalString(analyzer);
|
||||
out.writeString(minimumShouldMatch);
|
||||
out.writeGenericValue(boostTerms);
|
||||
out.writeBoolean(include);
|
||||
out.writeBoolean(failOnUnsupportedField);
|
||||
}
|
||||
|
||||
private static void writeItems(Item[] items, StreamOutput out) throws IOException {
|
||||
out.writeVInt(items.length);
|
||||
for (Item item : items) {
|
||||
item.writeTo(out);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(Arrays.hashCode(fields), Arrays.hashCode(likeTexts),
|
||||
|
|
|
@ -78,7 +78,7 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
|
|||
|
||||
private final Object value;
|
||||
private final Map<String, Float> fieldsBoosts;
|
||||
private MultiMatchQueryBuilder.Type type = DEFAULT_TYPE;
|
||||
private Type type = DEFAULT_TYPE;
|
||||
private Operator operator = DEFAULT_OPERATOR;
|
||||
private String analyzer;
|
||||
private int slop = DEFAULT_PHRASE_SLOP;
|
||||
|
@ -93,8 +93,6 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
|
|||
private Float cutoffFrequency = null;
|
||||
private MatchQuery.ZeroTermsQuery zeroTermsQuery = DEFAULT_ZERO_TERMS_QUERY;
|
||||
|
||||
public static final MultiMatchQueryBuilder PROTOTYPE = new MultiMatchQueryBuilder("");
|
||||
|
||||
public enum Type implements Writeable<Type> {
|
||||
|
||||
/**
|
||||
|
@ -128,8 +126,6 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
|
|||
*/
|
||||
PHRASE_PREFIX(MatchQuery.Type.PHRASE_PREFIX, 0.0f, new ParseField("phrase_prefix"));
|
||||
|
||||
private static final Type PROTOTYPE = BEST_FIELDS;
|
||||
|
||||
private MatchQuery.Type matchQueryType;
|
||||
private final float tieBreaker;
|
||||
private final ParseField parseField;
|
||||
|
@ -167,15 +163,10 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
|
|||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type readFrom(StreamInput in) throws IOException {
|
||||
public static Type readFromStream(StreamInput in) throws IOException {
|
||||
return Type.values()[in.readVInt()];
|
||||
}
|
||||
|
||||
public static Type readTypeFrom(StreamInput in) throws IOException {
|
||||
return PROTOTYPE.readFrom(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(this.ordinal());
|
||||
|
@ -206,6 +197,57 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public MultiMatchQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
value = in.readGenericValue();
|
||||
int size = in.readVInt();
|
||||
fieldsBoosts = new TreeMap<>();
|
||||
for (int i = 0; i < size; i++) {
|
||||
fieldsBoosts.put(in.readString(), in.readFloat());
|
||||
}
|
||||
type = Type.readFromStream(in);
|
||||
operator = Operator.readFromStream(in);
|
||||
analyzer = in.readOptionalString();
|
||||
slop = in.readVInt();
|
||||
fuzziness = in.readOptionalWriteable(Fuzziness::new);
|
||||
prefixLength = in.readVInt();
|
||||
maxExpansions = in.readVInt();
|
||||
minimumShouldMatch = in.readOptionalString();
|
||||
fuzzyRewrite = in.readOptionalString();
|
||||
useDisMax = in.readOptionalBoolean();
|
||||
tieBreaker = in.readOptionalFloat();
|
||||
lenient = in.readBoolean();
|
||||
cutoffFrequency = in.readOptionalFloat();
|
||||
zeroTermsQuery = MatchQuery.ZeroTermsQuery.readFromStream(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeGenericValue(value);
|
||||
out.writeVInt(fieldsBoosts.size());
|
||||
for (Map.Entry<String, Float> fieldsEntry : fieldsBoosts.entrySet()) {
|
||||
out.writeString(fieldsEntry.getKey());
|
||||
out.writeFloat(fieldsEntry.getValue());
|
||||
}
|
||||
type.writeTo(out);
|
||||
operator.writeTo(out);
|
||||
out.writeOptionalString(analyzer);
|
||||
out.writeVInt(slop);
|
||||
out.writeOptionalWriteable(fuzziness);
|
||||
out.writeVInt(prefixLength);
|
||||
out.writeVInt(maxExpansions);
|
||||
out.writeOptionalString(minimumShouldMatch);
|
||||
out.writeOptionalString(fuzzyRewrite);
|
||||
out.writeOptionalBoolean(useDisMax);
|
||||
out.writeOptionalFloat(tieBreaker);
|
||||
out.writeBoolean(lenient);
|
||||
out.writeOptionalFloat(cutoffFrequency);
|
||||
zeroTermsQuery.writeTo(out);
|
||||
}
|
||||
|
||||
public Object value() {
|
||||
return value;
|
||||
}
|
||||
|
@ -721,61 +763,6 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
|
|||
return newFieldsBoosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MultiMatchQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
MultiMatchQueryBuilder multiMatchQuery = new MultiMatchQueryBuilder(in.readGenericValue());
|
||||
int size = in.readVInt();
|
||||
for (int i = 0; i < size; i++) {
|
||||
multiMatchQuery.fieldsBoosts.put(in.readString(), in.readFloat());
|
||||
}
|
||||
multiMatchQuery.type = MultiMatchQueryBuilder.Type.readTypeFrom(in);
|
||||
multiMatchQuery.operator = Operator.readOperatorFrom(in);
|
||||
multiMatchQuery.analyzer = in.readOptionalString();
|
||||
multiMatchQuery.slop = in.readVInt();
|
||||
if (in.readBoolean()) {
|
||||
multiMatchQuery.fuzziness = Fuzziness.readFuzzinessFrom(in);
|
||||
}
|
||||
multiMatchQuery.prefixLength = in.readVInt();
|
||||
multiMatchQuery.maxExpansions = in.readVInt();
|
||||
multiMatchQuery.minimumShouldMatch = in.readOptionalString();
|
||||
multiMatchQuery.fuzzyRewrite = in.readOptionalString();
|
||||
multiMatchQuery.useDisMax = in.readOptionalBoolean();
|
||||
multiMatchQuery.tieBreaker = (Float) in.readGenericValue();
|
||||
multiMatchQuery.lenient = in.readBoolean();
|
||||
multiMatchQuery.cutoffFrequency = (Float) in.readGenericValue();
|
||||
multiMatchQuery.zeroTermsQuery = MatchQuery.ZeroTermsQuery.readZeroTermsQueryFrom(in);
|
||||
return multiMatchQuery;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeGenericValue(value);
|
||||
out.writeVInt(fieldsBoosts.size());
|
||||
for (Map.Entry<String, Float> fieldsEntry : fieldsBoosts.entrySet()) {
|
||||
out.writeString(fieldsEntry.getKey());
|
||||
out.writeFloat(fieldsEntry.getValue());
|
||||
}
|
||||
type.writeTo(out);
|
||||
operator.writeTo(out);
|
||||
out.writeOptionalString(analyzer);
|
||||
out.writeVInt(slop);
|
||||
if (fuzziness != null) {
|
||||
out.writeBoolean(true);
|
||||
fuzziness.writeTo(out);
|
||||
} else {
|
||||
out.writeBoolean(false);
|
||||
}
|
||||
out.writeVInt(prefixLength);
|
||||
out.writeVInt(maxExpansions);
|
||||
out.writeOptionalString(minimumShouldMatch);
|
||||
out.writeOptionalString(fuzzyRewrite);
|
||||
out.writeOptionalBoolean(useDisMax);
|
||||
out.writeGenericValue(tieBreaker);
|
||||
out.writeBoolean(lenient);
|
||||
out.writeGenericValue(cutoffFrequency);
|
||||
zeroTermsQuery.writeTo(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(value, fieldsBoosts, type, operator, analyzer, slop, fuzziness,
|
||||
|
|
|
@ -43,7 +43,6 @@ public class NestedQueryBuilder extends AbstractQueryBuilder<NestedQueryBuilder>
|
|||
*/
|
||||
public static final String NAME = "nested";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final NestedQueryBuilder PROTOTYPE = new NestedQueryBuilder("", EmptyQueryBuilder.PROTOTYPE);
|
||||
|
||||
/**
|
||||
* The default score move for nested queries.
|
||||
|
@ -84,6 +83,25 @@ public class NestedQueryBuilder extends AbstractQueryBuilder<NestedQueryBuilder>
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public NestedQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
path = in.readString();
|
||||
scoreMode = ScoreMode.values()[in.readVInt()];
|
||||
query = in.readQuery();
|
||||
innerHitBuilder = in.readOptionalWriteable(InnerHitBuilder::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(path);
|
||||
out.writeVInt(scoreMode.ordinal());
|
||||
out.writeQuery(query);
|
||||
out.writeOptionalWriteable(innerHitBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* The score mode how the scores from the matching child documents are mapped into the nested parent document.
|
||||
*/
|
||||
|
@ -198,32 +216,6 @@ public class NestedQueryBuilder extends AbstractQueryBuilder<NestedQueryBuilder>
|
|||
return Objects.hash(query, path, scoreMode, innerHitBuilder);
|
||||
}
|
||||
|
||||
private NestedQueryBuilder(StreamInput in) throws IOException {
|
||||
path = in.readString();
|
||||
final int ordinal = in.readVInt();
|
||||
scoreMode = ScoreMode.values()[ordinal];
|
||||
query = in.readQuery();
|
||||
innerHitBuilder = InnerHitBuilder.optionalReadFromStream(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(path);
|
||||
out.writeVInt(scoreMode.ordinal());
|
||||
out.writeQuery(query);
|
||||
if (innerHitBuilder != null) {
|
||||
out.writeBoolean(true);
|
||||
innerHitBuilder.writeTo(out);
|
||||
} else {
|
||||
out.writeBoolean(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NestedQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
return new NestedQueryBuilder(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query doToQuery(QueryShardContext context) throws IOException {
|
||||
ObjectMapper nestedObjectMapper = context.getObjectMapper(path);
|
||||
|
|
|
@ -53,7 +53,7 @@ public enum Operator implements Writeable<Operator> {
|
|||
}
|
||||
}
|
||||
|
||||
public static Operator readOperatorFrom(StreamInput in) throws IOException {
|
||||
public static Operator readFromStream(StreamInput in) throws IOException {
|
||||
int ordinal = in.readVInt();
|
||||
if (ordinal < 0 || ordinal >= values().length) {
|
||||
throw new IOException("Unknown Operator ordinal [" + ordinal + "]");
|
||||
|
|
|
@ -43,8 +43,6 @@ public final class ParentIdQueryBuilder extends AbstractQueryBuilder<ParentIdQue
|
|||
public static final String NAME = "parent_id";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
|
||||
public static final ParentIdQueryBuilder PROTO = new ParentIdQueryBuilder(null, null);
|
||||
|
||||
private static final ParseField ID_FIELD = new ParseField("id");
|
||||
private static final ParseField TYPE_FIELD = new ParseField("type", "child_type");
|
||||
|
||||
|
@ -56,6 +54,21 @@ public final class ParentIdQueryBuilder extends AbstractQueryBuilder<ParentIdQue
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public ParentIdQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
type = in.readString();
|
||||
id = in.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(type);
|
||||
out.writeString(id);
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
@ -126,19 +139,6 @@ public final class ParentIdQueryBuilder extends AbstractQueryBuilder<ParentIdQue
|
|||
return query.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ParentIdQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
String type = in.readString();
|
||||
String id = in.readString();
|
||||
return new ParentIdQueryBuilder(type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(type);
|
||||
out.writeString(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doEquals(ParentIdQueryBuilder that) {
|
||||
return Objects.equals(type, that.type) && Objects.equals(id, that.id);
|
||||
|
|
|
@ -71,8 +71,6 @@ public class PercolatorQueryBuilder extends AbstractQueryBuilder<PercolatorQuery
|
|||
public static final String NAME = "percolator";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
|
||||
public static final PercolatorQueryBuilder PROTO = new PercolatorQueryBuilder(null, null, null, null, null, null, null, null);
|
||||
|
||||
static final ParseField DOCUMENT_FIELD = new ParseField("document");
|
||||
private static final ParseField DOCUMENT_TYPE_FIELD = new ParseField("document_type");
|
||||
private static final ParseField INDEXED_DOCUMENT_FIELD_INDEX = new ParseField("index");
|
||||
|
@ -134,17 +132,40 @@ public class PercolatorQueryBuilder extends AbstractQueryBuilder<PercolatorQuery
|
|||
this.document = null;
|
||||
}
|
||||
|
||||
private PercolatorQueryBuilder(String documentType, BytesReference document, String indexedDocumentIndex, String indexedDocumentType,
|
||||
String indexedDocumentId, String indexedDocumentRouting, String indexedDocumentPreference,
|
||||
Long indexedDocumentVersion) {
|
||||
this.documentType = documentType;
|
||||
this.document = document;
|
||||
this.indexedDocumentIndex = indexedDocumentIndex;
|
||||
this.indexedDocumentType = indexedDocumentType;
|
||||
this.indexedDocumentId = indexedDocumentId;
|
||||
this.indexedDocumentRouting = indexedDocumentRouting;
|
||||
this.indexedDocumentPreference = indexedDocumentPreference;
|
||||
this.indexedDocumentVersion = indexedDocumentVersion;
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public PercolatorQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
documentType = in.readString();
|
||||
indexedDocumentIndex = in.readOptionalString();
|
||||
indexedDocumentType = in.readOptionalString();
|
||||
indexedDocumentId = in.readOptionalString();
|
||||
indexedDocumentRouting = in.readOptionalString();
|
||||
indexedDocumentPreference = in.readOptionalString();
|
||||
if (in.readBoolean()) {
|
||||
indexedDocumentVersion = in.readVLong();
|
||||
} else {
|
||||
indexedDocumentVersion = null;
|
||||
}
|
||||
document = in.readOptionalBytesReference();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(documentType);
|
||||
out.writeOptionalString(indexedDocumentIndex);
|
||||
out.writeOptionalString(indexedDocumentType);
|
||||
out.writeOptionalString(indexedDocumentId);
|
||||
out.writeOptionalString(indexedDocumentRouting);
|
||||
out.writeOptionalString(indexedDocumentPreference);
|
||||
if (indexedDocumentVersion != null) {
|
||||
out.writeBoolean(true);
|
||||
out.writeVLong(indexedDocumentVersion);
|
||||
} else {
|
||||
out.writeBoolean(false);
|
||||
}
|
||||
out.writeOptionalBytesReference(document);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -267,48 +288,6 @@ public class PercolatorQueryBuilder extends AbstractQueryBuilder<PercolatorQuery
|
|||
return queryBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PercolatorQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
String docType = in.readString();
|
||||
String documentIndex = in.readOptionalString();
|
||||
String documentType = in.readOptionalString();
|
||||
String documentId = in.readOptionalString();
|
||||
String documentRouting = in.readOptionalString();
|
||||
String documentPreference = in.readOptionalString();
|
||||
Long documentVersion = null;
|
||||
if (in.readBoolean()) {
|
||||
documentVersion = in.readVLong();
|
||||
}
|
||||
BytesReference documentSource = null;
|
||||
if (in.readBoolean()) {
|
||||
documentSource = in.readBytesReference();
|
||||
}
|
||||
return new PercolatorQueryBuilder(docType, documentSource, documentIndex, documentType, documentId,
|
||||
documentRouting, documentPreference, documentVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(documentType);
|
||||
out.writeOptionalString(indexedDocumentIndex);
|
||||
out.writeOptionalString(indexedDocumentType);
|
||||
out.writeOptionalString(indexedDocumentId);
|
||||
out.writeOptionalString(indexedDocumentRouting);
|
||||
out.writeOptionalString(indexedDocumentPreference);
|
||||
if (indexedDocumentVersion != null) {
|
||||
out.writeBoolean(true);
|
||||
out.writeVLong(indexedDocumentVersion);
|
||||
} else {
|
||||
out.writeBoolean(false);
|
||||
}
|
||||
if (document != null) {
|
||||
out.writeBoolean(true);
|
||||
out.writeBytesReference(document);
|
||||
} else {
|
||||
out.writeBoolean(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doEquals(PercolatorQueryBuilder other) {
|
||||
return Objects.equals(documentType, other.documentType)
|
||||
|
|
|
@ -44,7 +44,6 @@ public class PrefixQueryBuilder extends AbstractQueryBuilder<PrefixQueryBuilder>
|
|||
|
||||
public static final String NAME = "prefix";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final PrefixQueryBuilder PROTOTYPE = new PrefixQueryBuilder("field", "value");
|
||||
|
||||
private static final ParseField PREFIX_FIELD = new ParseField("value", "prefix");
|
||||
private static final ParseField REWRITE_FIELD = new ParseField("rewrite");
|
||||
|
@ -72,6 +71,23 @@ public class PrefixQueryBuilder extends AbstractQueryBuilder<PrefixQueryBuilder>
|
|||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public PrefixQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
value = in.readString();
|
||||
rewrite = in.readOptionalString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeString(value);
|
||||
out.writeOptionalString(rewrite);
|
||||
}
|
||||
|
||||
public String fieldName() {
|
||||
return this.fieldName;
|
||||
}
|
||||
|
@ -178,20 +194,6 @@ public class PrefixQueryBuilder extends AbstractQueryBuilder<PrefixQueryBuilder>
|
|||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PrefixQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
PrefixQueryBuilder prefixQueryBuilder = new PrefixQueryBuilder(in.readString(), in.readString());
|
||||
prefixQueryBuilder.rewrite = in.readOptionalString();
|
||||
return prefixQueryBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeString(value);
|
||||
out.writeOptionalString(rewrite);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final int doHashCode() {
|
||||
return Objects.hash(fieldName, value, rewrite);
|
||||
|
|
|
@ -59,7 +59,6 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQue
|
|||
|
||||
public static final String NAME = "query_string";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final QueryStringQueryBuilder PROTOTYPE = new QueryStringQueryBuilder("");
|
||||
|
||||
public static final boolean DEFAULT_AUTO_GENERATE_PHRASE_QUERIES = false;
|
||||
public static final int DEFAULT_MAX_DETERMINED_STATES = Operations.DEFAULT_MAX_DETERMINIZED_STATES;
|
||||
|
@ -168,6 +167,76 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQue
|
|||
this.queryString = queryString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public QueryStringQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
queryString = in.readString();
|
||||
defaultField = in.readOptionalString();
|
||||
int size = in.readVInt();
|
||||
for (int i = 0; i < size; i++) {
|
||||
fieldsAndWeights.put(in.readString(), in.readFloat());
|
||||
}
|
||||
defaultOperator = Operator.readFromStream(in);
|
||||
analyzer = in.readOptionalString();
|
||||
quoteAnalyzer = in.readOptionalString();
|
||||
quoteFieldSuffix = in.readOptionalString();
|
||||
autoGeneratePhraseQueries = in.readBoolean();
|
||||
allowLeadingWildcard = in.readOptionalBoolean();
|
||||
analyzeWildcard = in.readOptionalBoolean();
|
||||
lowercaseExpandedTerms = in.readBoolean();
|
||||
enablePositionIncrements = in.readBoolean();
|
||||
locale = Locale.forLanguageTag(in.readString());
|
||||
fuzziness = new Fuzziness(in);
|
||||
fuzzyPrefixLength = in.readVInt();
|
||||
fuzzyMaxExpansions = in.readVInt();
|
||||
fuzzyRewrite = in.readOptionalString();
|
||||
phraseSlop = in.readVInt();
|
||||
useDisMax = in.readBoolean();
|
||||
tieBreaker = in.readFloat();
|
||||
rewrite = in.readOptionalString();
|
||||
minimumShouldMatch = in.readOptionalString();
|
||||
lenient = in.readOptionalBoolean();
|
||||
timeZone = in.readOptionalTimeZone();
|
||||
escape = in.readBoolean();
|
||||
maxDeterminizedStates = in.readVInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(this.queryString);
|
||||
out.writeOptionalString(this.defaultField);
|
||||
out.writeVInt(this.fieldsAndWeights.size());
|
||||
for (Map.Entry<String, Float> fieldsEntry : this.fieldsAndWeights.entrySet()) {
|
||||
out.writeString(fieldsEntry.getKey());
|
||||
out.writeFloat(fieldsEntry.getValue());
|
||||
}
|
||||
this.defaultOperator.writeTo(out);
|
||||
out.writeOptionalString(this.analyzer);
|
||||
out.writeOptionalString(this.quoteAnalyzer);
|
||||
out.writeOptionalString(this.quoteFieldSuffix);
|
||||
out.writeBoolean(this.autoGeneratePhraseQueries);
|
||||
out.writeOptionalBoolean(this.allowLeadingWildcard);
|
||||
out.writeOptionalBoolean(this.analyzeWildcard);
|
||||
out.writeBoolean(this.lowercaseExpandedTerms);
|
||||
out.writeBoolean(this.enablePositionIncrements);
|
||||
out.writeString(this.locale.toLanguageTag());
|
||||
this.fuzziness.writeTo(out);
|
||||
out.writeVInt(this.fuzzyPrefixLength);
|
||||
out.writeVInt(this.fuzzyMaxExpansions);
|
||||
out.writeOptionalString(this.fuzzyRewrite);
|
||||
out.writeVInt(this.phraseSlop);
|
||||
out.writeBoolean(this.useDisMax);
|
||||
out.writeFloat(this.tieBreaker);
|
||||
out.writeOptionalString(this.rewrite);
|
||||
out.writeOptionalString(this.minimumShouldMatch);
|
||||
out.writeOptionalBoolean(this.lenient);
|
||||
out.writeOptionalTimeZone(timeZone);
|
||||
out.writeBoolean(this.escape);
|
||||
out.writeVInt(this.maxDeterminizedStates);
|
||||
}
|
||||
|
||||
public String queryString() {
|
||||
return this.queryString;
|
||||
}
|
||||
|
@ -731,81 +800,6 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQue
|
|||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected QueryStringQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
QueryStringQueryBuilder queryStringQueryBuilder = new QueryStringQueryBuilder(in.readString());
|
||||
queryStringQueryBuilder.defaultField = in.readOptionalString();
|
||||
int size = in.readVInt();
|
||||
for (int i = 0; i < size; i++) {
|
||||
queryStringQueryBuilder.fieldsAndWeights.put(in.readString(), in.readFloat());
|
||||
}
|
||||
queryStringQueryBuilder.defaultOperator = Operator.readOperatorFrom(in);
|
||||
queryStringQueryBuilder.analyzer = in.readOptionalString();
|
||||
queryStringQueryBuilder.quoteAnalyzer = in.readOptionalString();
|
||||
queryStringQueryBuilder.quoteFieldSuffix = in.readOptionalString();
|
||||
queryStringQueryBuilder.autoGeneratePhraseQueries = in.readBoolean();
|
||||
queryStringQueryBuilder.allowLeadingWildcard = in.readOptionalBoolean();
|
||||
queryStringQueryBuilder.analyzeWildcard = in.readOptionalBoolean();
|
||||
queryStringQueryBuilder.lowercaseExpandedTerms = in.readBoolean();
|
||||
queryStringQueryBuilder.enablePositionIncrements = in.readBoolean();
|
||||
queryStringQueryBuilder.locale = Locale.forLanguageTag(in.readString());
|
||||
queryStringQueryBuilder.fuzziness = Fuzziness.readFuzzinessFrom(in);
|
||||
queryStringQueryBuilder.fuzzyPrefixLength = in.readVInt();
|
||||
queryStringQueryBuilder.fuzzyMaxExpansions = in.readVInt();
|
||||
queryStringQueryBuilder.fuzzyRewrite = in.readOptionalString();
|
||||
queryStringQueryBuilder.phraseSlop = in.readVInt();
|
||||
queryStringQueryBuilder.useDisMax = in.readBoolean();
|
||||
queryStringQueryBuilder.tieBreaker = in.readFloat();
|
||||
queryStringQueryBuilder.rewrite = in.readOptionalString();
|
||||
queryStringQueryBuilder.minimumShouldMatch = in.readOptionalString();
|
||||
queryStringQueryBuilder.lenient = in.readOptionalBoolean();
|
||||
if (in.readBoolean()) {
|
||||
queryStringQueryBuilder.timeZone = DateTimeZone.forID(in.readString());
|
||||
}
|
||||
queryStringQueryBuilder.escape = in.readBoolean();
|
||||
queryStringQueryBuilder.maxDeterminizedStates = in.readVInt();
|
||||
return queryStringQueryBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(this.queryString);
|
||||
out.writeOptionalString(this.defaultField);
|
||||
out.writeVInt(this.fieldsAndWeights.size());
|
||||
for (Map.Entry<String, Float> fieldsEntry : this.fieldsAndWeights.entrySet()) {
|
||||
out.writeString(fieldsEntry.getKey());
|
||||
out.writeFloat(fieldsEntry.getValue());
|
||||
}
|
||||
this.defaultOperator.writeTo(out);
|
||||
out.writeOptionalString(this.analyzer);
|
||||
out.writeOptionalString(this.quoteAnalyzer);
|
||||
out.writeOptionalString(this.quoteFieldSuffix);
|
||||
out.writeBoolean(this.autoGeneratePhraseQueries);
|
||||
out.writeOptionalBoolean(this.allowLeadingWildcard);
|
||||
out.writeOptionalBoolean(this.analyzeWildcard);
|
||||
out.writeBoolean(this.lowercaseExpandedTerms);
|
||||
out.writeBoolean(this.enablePositionIncrements);
|
||||
out.writeString(this.locale.toLanguageTag());
|
||||
this.fuzziness.writeTo(out);
|
||||
out.writeVInt(this.fuzzyPrefixLength);
|
||||
out.writeVInt(this.fuzzyMaxExpansions);
|
||||
out.writeOptionalString(this.fuzzyRewrite);
|
||||
out.writeVInt(this.phraseSlop);
|
||||
out.writeBoolean(this.useDisMax);
|
||||
out.writeFloat(this.tieBreaker);
|
||||
out.writeOptionalString(this.rewrite);
|
||||
out.writeOptionalString(this.minimumShouldMatch);
|
||||
out.writeOptionalBoolean(this.lenient);
|
||||
if (this.timeZone == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
out.writeString(this.timeZone.getID());
|
||||
}
|
||||
out.writeBoolean(this.escape);
|
||||
out.writeVInt(this.maxDeterminizedStates);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doEquals(QueryStringQueryBuilder other) {
|
||||
return Objects.equals(queryString, other.queryString) &&
|
||||
|
|
|
@ -48,7 +48,6 @@ import java.util.Objects;
|
|||
public class RangeQueryBuilder extends AbstractQueryBuilder<RangeQueryBuilder> implements MultiTermQueryBuilder<RangeQueryBuilder> {
|
||||
public static final String NAME = "range";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final RangeQueryBuilder PROTOTYPE = new RangeQueryBuilder("field");
|
||||
|
||||
public static final boolean DEFAULT_INCLUDE_UPPER = true;
|
||||
public static final boolean DEFAULT_INCLUDE_LOWER = true;
|
||||
|
@ -93,6 +92,38 @@ public class RangeQueryBuilder extends AbstractQueryBuilder<RangeQueryBuilder> i
|
|||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public RangeQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
from = in.readGenericValue();
|
||||
to = in.readGenericValue();
|
||||
includeLower = in.readBoolean();
|
||||
includeUpper = in.readBoolean();
|
||||
timeZone = in.readOptionalTimeZone();
|
||||
String formatString = in.readOptionalString();
|
||||
if (formatString != null) {
|
||||
format = Joda.forPattern(formatString);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(this.fieldName);
|
||||
out.writeGenericValue(this.from);
|
||||
out.writeGenericValue(this.to);
|
||||
out.writeBoolean(this.includeLower);
|
||||
out.writeBoolean(this.includeUpper);
|
||||
out.writeOptionalTimeZone(timeZone);
|
||||
String formatString = null;
|
||||
if (this.format != null) {
|
||||
formatString = this.format.format();
|
||||
}
|
||||
out.writeOptionalString(formatString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field name for this query.
|
||||
*/
|
||||
|
@ -434,43 +465,6 @@ public class RangeQueryBuilder extends AbstractQueryBuilder<RangeQueryBuilder> i
|
|||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RangeQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
RangeQueryBuilder rangeQueryBuilder = new RangeQueryBuilder(in.readString());
|
||||
rangeQueryBuilder.from = in.readGenericValue();
|
||||
rangeQueryBuilder.to = in.readGenericValue();
|
||||
rangeQueryBuilder.includeLower = in.readBoolean();
|
||||
rangeQueryBuilder.includeUpper = in.readBoolean();
|
||||
String timeZoneId = in.readOptionalString();
|
||||
if (timeZoneId != null) {
|
||||
rangeQueryBuilder.timeZone = DateTimeZone.forID(timeZoneId);
|
||||
}
|
||||
String formatString = in.readOptionalString();
|
||||
if (formatString != null) {
|
||||
rangeQueryBuilder.format = Joda.forPattern(formatString);
|
||||
}
|
||||
return rangeQueryBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(this.fieldName);
|
||||
out.writeGenericValue(this.from);
|
||||
out.writeGenericValue(this.to);
|
||||
out.writeBoolean(this.includeLower);
|
||||
out.writeBoolean(this.includeUpper);
|
||||
String timeZoneId = null;
|
||||
if (this.timeZone != null) {
|
||||
timeZoneId = this.timeZone.getID();
|
||||
}
|
||||
out.writeOptionalString(timeZoneId);
|
||||
String formatString = null;
|
||||
if (this.format != null) {
|
||||
formatString = this.format.format();
|
||||
}
|
||||
out.writeOptionalString(formatString);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
String timeZoneId = timeZone == null ? null : timeZone.getID();
|
||||
|
|
|
@ -45,7 +45,6 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder<RegexpQueryBuilder>
|
|||
|
||||
public static final String NAME = "regexp";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final RegexpQueryBuilder PROTOTYPE = new RegexpQueryBuilder("field", "value");
|
||||
|
||||
public static final int DEFAULT_FLAGS_VALUE = RegexpFlag.ALL.value();
|
||||
public static final int DEFAULT_MAX_DETERMINIZED_STATES = Operations.DEFAULT_MAX_DETERMINIZED_STATES;
|
||||
|
@ -85,6 +84,27 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder<RegexpQueryBuilder>
|
|||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public RegexpQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
value = in.readString();
|
||||
flagsValue = in.readVInt();
|
||||
maxDeterminizedStates = in.readVInt();
|
||||
rewrite = in.readOptionalString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeString(value);
|
||||
out.writeVInt(flagsValue);
|
||||
out.writeVInt(maxDeterminizedStates);
|
||||
out.writeOptionalString(rewrite);
|
||||
}
|
||||
|
||||
/** Returns the field name used in this query. */
|
||||
public String fieldName() {
|
||||
return this.fieldName;
|
||||
|
@ -249,24 +269,6 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder<RegexpQueryBuilder>
|
|||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RegexpQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
RegexpQueryBuilder regexpQueryBuilder = new RegexpQueryBuilder(in.readString(), in.readString());
|
||||
regexpQueryBuilder.flagsValue = in.readVInt();
|
||||
regexpQueryBuilder.maxDeterminizedStates = in.readVInt();
|
||||
regexpQueryBuilder.rewrite = in.readOptionalString();
|
||||
return regexpQueryBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeString(value);
|
||||
out.writeVInt(flagsValue);
|
||||
out.writeVInt(maxDeterminizedStates);
|
||||
out.writeOptionalString(rewrite);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(fieldName, value, flagsValue, maxDeterminizedStates, rewrite);
|
||||
|
|
|
@ -52,8 +52,6 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder<ScriptQueryBuilder>
|
|||
public static final String NAME = "script";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
|
||||
public static final ScriptQueryBuilder PROTOTYPE = new ScriptQueryBuilder(new Script(""));
|
||||
|
||||
private static final ParseField PARAMS_FIELD = new ParseField("params");
|
||||
|
||||
private final Script script;
|
||||
|
@ -65,6 +63,19 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder<ScriptQueryBuilder>
|
|||
this.script = script;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public ScriptQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
script = Script.readScript(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
script.writeTo(out);
|
||||
}
|
||||
|
||||
public Script script() {
|
||||
return this.script;
|
||||
}
|
||||
|
@ -217,16 +228,6 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder<ScriptQueryBuilder>
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ScriptQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
return new ScriptQueryBuilder(Script.readScript(in));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
script.writeTo(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(script);
|
||||
|
|
|
@ -94,8 +94,6 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
|||
public static final String NAME = "simple_query_string";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
|
||||
public static final SimpleQueryStringBuilder PROTOTYPE = new SimpleQueryStringBuilder("");
|
||||
|
||||
private static final ParseField MINIMUM_SHOULD_MATCH_FIELD = new ParseField("minimum_should_match");
|
||||
private static final ParseField ANALYZE_WILDCARD_FIELD = new ParseField("analyze_wildcard");
|
||||
private static final ParseField LENIENT_FIELD = new ParseField("lenient");
|
||||
|
@ -138,6 +136,48 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
|||
this.queryText = queryText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public SimpleQueryStringBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
queryText = in.readString();
|
||||
int size = in.readInt();
|
||||
Map<String, Float> fields = new HashMap<>();
|
||||
for (int i = 0; i < size; i++) {
|
||||
String field = in.readString();
|
||||
Float weight = in.readFloat();
|
||||
fields.put(field, weight);
|
||||
}
|
||||
fieldsAndWeights.putAll(fields);
|
||||
flags = in.readInt();
|
||||
analyzer = in.readOptionalString();
|
||||
defaultOperator = Operator.readFromStream(in);
|
||||
settings.lowercaseExpandedTerms(in.readBoolean());
|
||||
settings.lenient(in.readBoolean());
|
||||
settings.analyzeWildcard(in.readBoolean());
|
||||
settings.locale(Locale.forLanguageTag(in.readString()));
|
||||
minimumShouldMatch = in.readOptionalString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(queryText);
|
||||
out.writeInt(fieldsAndWeights.size());
|
||||
for (Map.Entry<String, Float> entry : fieldsAndWeights.entrySet()) {
|
||||
out.writeString(entry.getKey());
|
||||
out.writeFloat(entry.getValue());
|
||||
}
|
||||
out.writeInt(flags);
|
||||
out.writeOptionalString(analyzer);
|
||||
defaultOperator.writeTo(out);
|
||||
out.writeBoolean(settings.lowercaseExpandedTerms());
|
||||
out.writeBoolean(settings.lenient());
|
||||
out.writeBoolean(settings.analyzeWildcard());
|
||||
out.writeString(settings.locale().toLanguageTag());
|
||||
out.writeOptionalString(minimumShouldMatch);
|
||||
}
|
||||
|
||||
/** Returns the text to parse the query from. */
|
||||
public String value() {
|
||||
return this.queryText;
|
||||
|
@ -482,47 +522,6 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
|||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleQueryStringBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
SimpleQueryStringBuilder result = new SimpleQueryStringBuilder(in.readString());
|
||||
int size = in.readInt();
|
||||
Map<String, Float> fields = new HashMap<>();
|
||||
for (int i = 0; i < size; i++) {
|
||||
String field = in.readString();
|
||||
Float weight = in.readFloat();
|
||||
fields.put(field, weight);
|
||||
}
|
||||
result.fieldsAndWeights.putAll(fields);
|
||||
result.flags = in.readInt();
|
||||
result.analyzer = in.readOptionalString();
|
||||
result.defaultOperator = Operator.readOperatorFrom(in);
|
||||
result.settings.lowercaseExpandedTerms(in.readBoolean());
|
||||
result.settings.lenient(in.readBoolean());
|
||||
result.settings.analyzeWildcard(in.readBoolean());
|
||||
String localeStr = in.readString();
|
||||
result.settings.locale(Locale.forLanguageTag(localeStr));
|
||||
result.minimumShouldMatch = in.readOptionalString();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(queryText);
|
||||
out.writeInt(fieldsAndWeights.size());
|
||||
for (Map.Entry<String, Float> entry : fieldsAndWeights.entrySet()) {
|
||||
out.writeString(entry.getKey());
|
||||
out.writeFloat(entry.getValue());
|
||||
}
|
||||
out.writeInt(flags);
|
||||
out.writeOptionalString(analyzer);
|
||||
defaultOperator.writeTo(out);
|
||||
out.writeBoolean(settings.lowercaseExpandedTerms());
|
||||
out.writeBoolean(settings.lenient());
|
||||
out.writeBoolean(settings.analyzeWildcard());
|
||||
out.writeString(settings.locale().toLanguageTag());
|
||||
out.writeOptionalString(minimumShouldMatch);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(fieldsAndWeights, analyzer, defaultOperator, queryText, minimumShouldMatch, settings, flags);
|
||||
|
|
|
@ -40,20 +40,18 @@ public class SpanContainingQueryBuilder extends AbstractQueryBuilder<SpanContain
|
|||
|
||||
public static final String NAME = "span_containing";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final SpanContainingQueryBuilder PROTOTYPE =
|
||||
new SpanContainingQueryBuilder(SpanTermQueryBuilder.PROTOTYPE, SpanTermQueryBuilder.PROTOTYPE);
|
||||
|
||||
private static final ParseField BIG_FIELD = new ParseField("big");
|
||||
private static final ParseField LITTLE_FIELD = new ParseField("little");
|
||||
|
||||
private final SpanQueryBuilder big;
|
||||
private final SpanQueryBuilder little;
|
||||
private final SpanQueryBuilder<?> big;
|
||||
private final SpanQueryBuilder<?> little;
|
||||
|
||||
/**
|
||||
* @param big the big clause, it must enclose {@code little} for a match.
|
||||
* @param little the little clause, it must be contained within {@code big} for a match.
|
||||
*/
|
||||
public SpanContainingQueryBuilder(SpanQueryBuilder big, SpanQueryBuilder little) {
|
||||
public SpanContainingQueryBuilder(SpanQueryBuilder<?> big, SpanQueryBuilder<?> little) {
|
||||
if (big == null) {
|
||||
throw new IllegalArgumentException("inner clause [big] cannot be null.");
|
||||
}
|
||||
|
@ -64,6 +62,21 @@ public class SpanContainingQueryBuilder extends AbstractQueryBuilder<SpanContain
|
|||
this.big = big;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public SpanContainingQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
big = (SpanQueryBuilder<?>) in.readQuery();
|
||||
little = (SpanQueryBuilder<?>) in.readQuery();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(big);
|
||||
out.writeQuery(little);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the big clause, it must enclose {@code little} for a match.
|
||||
*/
|
||||
|
@ -142,19 +155,6 @@ public class SpanContainingQueryBuilder extends AbstractQueryBuilder<SpanContain
|
|||
return new SpanContainingQuery((SpanQuery) innerBig, (SpanQuery) innerLittle);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpanContainingQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
SpanQueryBuilder big = (SpanQueryBuilder)in.readQuery();
|
||||
SpanQueryBuilder little = (SpanQueryBuilder)in.readQuery();
|
||||
return new SpanContainingQueryBuilder(big, little);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(big);
|
||||
out.writeQuery(little);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(big, little);
|
||||
|
|
|
@ -36,12 +36,11 @@ public class SpanFirstQueryBuilder extends AbstractQueryBuilder<SpanFirstQueryBu
|
|||
|
||||
public static final String NAME = "span_first";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final SpanFirstQueryBuilder PROTOTYPE = new SpanFirstQueryBuilder(SpanTermQueryBuilder.PROTOTYPE, 0);
|
||||
|
||||
private static final ParseField MATCH_FIELD = new ParseField("match");
|
||||
private static final ParseField END_FIELD = new ParseField("end");
|
||||
|
||||
private final SpanQueryBuilder matchBuilder;
|
||||
private final SpanQueryBuilder<?> matchBuilder;
|
||||
|
||||
private final int end;
|
||||
|
||||
|
@ -52,7 +51,7 @@ public class SpanFirstQueryBuilder extends AbstractQueryBuilder<SpanFirstQueryBu
|
|||
* @param end maximum end position of the match, needs to be positive
|
||||
* @throws IllegalArgumentException for negative <code>end</code> positions
|
||||
*/
|
||||
public SpanFirstQueryBuilder(SpanQueryBuilder matchBuilder, int end) {
|
||||
public SpanFirstQueryBuilder(SpanQueryBuilder<?> matchBuilder, int end) {
|
||||
if (matchBuilder == null) {
|
||||
throw new IllegalArgumentException("inner span query cannot be null");
|
||||
}
|
||||
|
@ -63,10 +62,25 @@ public class SpanFirstQueryBuilder extends AbstractQueryBuilder<SpanFirstQueryBu
|
|||
this.end = end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public SpanFirstQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
matchBuilder = (SpanQueryBuilder<?>)in.readQuery();
|
||||
end = in.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(matchBuilder);
|
||||
out.writeInt(end);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the inner {@link SpanQueryBuilder} defined in this query
|
||||
*/
|
||||
public SpanQueryBuilder innerQuery() {
|
||||
public SpanQueryBuilder<?> innerQuery() {
|
||||
return this.matchBuilder;
|
||||
}
|
||||
|
||||
|
@ -141,19 +155,6 @@ public class SpanFirstQueryBuilder extends AbstractQueryBuilder<SpanFirstQueryBu
|
|||
return new SpanFirstQuery((SpanQuery) innerSpanQuery, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpanFirstQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
SpanQueryBuilder matchBuilder = (SpanQueryBuilder)in.readQuery();
|
||||
int end = in.readInt();
|
||||
return new SpanFirstQueryBuilder(matchBuilder, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(matchBuilder);
|
||||
out.writeInt(end);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(matchBuilder, end);
|
||||
|
|
|
@ -44,20 +44,31 @@ public class SpanMultiTermQueryBuilder extends AbstractQueryBuilder<SpanMultiTer
|
|||
public static final String NAME = "span_multi";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
|
||||
public static final SpanMultiTermQueryBuilder PROTOTYPE = new SpanMultiTermQueryBuilder(RangeQueryBuilder.PROTOTYPE);
|
||||
|
||||
private static final ParseField MATCH_FIELD = new ParseField("match");
|
||||
|
||||
private final MultiTermQueryBuilder multiTermQueryBuilder;
|
||||
private final MultiTermQueryBuilder<?> multiTermQueryBuilder;
|
||||
|
||||
public SpanMultiTermQueryBuilder(MultiTermQueryBuilder multiTermQueryBuilder) {
|
||||
public SpanMultiTermQueryBuilder(MultiTermQueryBuilder<?> multiTermQueryBuilder) {
|
||||
if (multiTermQueryBuilder == null) {
|
||||
throw new IllegalArgumentException("inner multi term query cannot be null");
|
||||
}
|
||||
this.multiTermQueryBuilder = multiTermQueryBuilder;
|
||||
}
|
||||
|
||||
public MultiTermQueryBuilder innerQuery() {
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public SpanMultiTermQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
multiTermQueryBuilder = (MultiTermQueryBuilder<?>) in.readQuery();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(multiTermQueryBuilder);
|
||||
}
|
||||
|
||||
public MultiTermQueryBuilder<?> innerQuery() {
|
||||
return this.multiTermQueryBuilder;
|
||||
}
|
||||
|
||||
|
@ -133,17 +144,6 @@ public class SpanMultiTermQueryBuilder extends AbstractQueryBuilder<SpanMultiTer
|
|||
return wrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpanMultiTermQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
MultiTermQueryBuilder multiTermBuilder = (MultiTermQueryBuilder)in.readQuery();
|
||||
return new SpanMultiTermQueryBuilder(multiTermBuilder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(multiTermQueryBuilder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(multiTermQueryBuilder);
|
||||
|
|
|
@ -43,7 +43,6 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
|
|||
|
||||
public static final String NAME = "span_near";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final SpanNearQueryBuilder PROTOTYPE = new SpanNearQueryBuilder(SpanTermQueryBuilder.PROTOTYPE, 0);
|
||||
|
||||
/** Default for flag controlling whether matches are required to be in-order */
|
||||
public static boolean DEFAULT_IN_ORDER = true;
|
||||
|
@ -71,6 +70,25 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
|
|||
this.slop = slop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public SpanNearQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
for (QueryBuilder<?> clause : readQueries(in)) {
|
||||
this.clauses.add((SpanQueryBuilder<?>) clause);
|
||||
}
|
||||
slop = in.readVInt();
|
||||
inOrder = in.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
writeQueries(out, clauses);
|
||||
out.writeVInt(slop);
|
||||
out.writeBoolean(inOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maximum number of intervening unmatched positions permitted
|
||||
*/
|
||||
|
@ -199,25 +217,6 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
|
|||
return new SpanNearQuery(spanQueries, slop, inOrder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpanNearQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
List<QueryBuilder<?>> clauses = readQueries(in);
|
||||
SpanNearQueryBuilder queryBuilder = new SpanNearQueryBuilder((SpanQueryBuilder<?>)clauses.get(0), in.readVInt());
|
||||
for (int i = 1; i < clauses.size(); i++) {
|
||||
queryBuilder.clauses.add((SpanQueryBuilder<?>)clauses.get(i));
|
||||
}
|
||||
queryBuilder.inOrder = in.readBoolean();
|
||||
return queryBuilder;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
writeQueries(out, clauses);
|
||||
out.writeVInt(slop);
|
||||
out.writeBoolean(inOrder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(clauses, slop, inOrder);
|
||||
|
|
|
@ -36,8 +36,6 @@ public class SpanNotQueryBuilder extends AbstractQueryBuilder<SpanNotQueryBuilde
|
|||
|
||||
public static final String NAME = "span_not";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final SpanNotQueryBuilder PROTOTYPE = new SpanNotQueryBuilder(SpanTermQueryBuilder.PROTOTYPE,
|
||||
SpanTermQueryBuilder.PROTOTYPE);
|
||||
|
||||
/** the default pre parameter size */
|
||||
public static final int DEFAULT_PRE = 0;
|
||||
|
@ -50,9 +48,9 @@ public class SpanNotQueryBuilder extends AbstractQueryBuilder<SpanNotQueryBuilde
|
|||
private static final ParseField EXCLUDE_FIELD = new ParseField("exclude");
|
||||
private static final ParseField INCLUDE_FIELD = new ParseField("include");
|
||||
|
||||
private final SpanQueryBuilder include;
|
||||
private final SpanQueryBuilder<?> include;
|
||||
|
||||
private final SpanQueryBuilder exclude;
|
||||
private final SpanQueryBuilder<?> exclude;
|
||||
|
||||
private int pre = DEFAULT_PRE;
|
||||
|
||||
|
@ -64,7 +62,7 @@ public class SpanNotQueryBuilder extends AbstractQueryBuilder<SpanNotQueryBuilde
|
|||
* @param include the span query whose matches are filtered
|
||||
* @param exclude the span query whose matches must not overlap
|
||||
*/
|
||||
public SpanNotQueryBuilder(SpanQueryBuilder include, SpanQueryBuilder exclude) {
|
||||
public SpanNotQueryBuilder(SpanQueryBuilder<?> include, SpanQueryBuilder<?> exclude) {
|
||||
if (include == null) {
|
||||
throw new IllegalArgumentException("inner clause [include] cannot be null.");
|
||||
}
|
||||
|
@ -75,6 +73,25 @@ public class SpanNotQueryBuilder extends AbstractQueryBuilder<SpanNotQueryBuilde
|
|||
this.exclude = exclude;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public SpanNotQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
include = (SpanQueryBuilder<?>) in.readQuery();
|
||||
exclude = (SpanQueryBuilder<?>) in.readQuery();
|
||||
pre = in.readVInt();
|
||||
post = in.readVInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(include);
|
||||
out.writeQuery(exclude);
|
||||
out.writeVInt(pre);
|
||||
out.writeVInt(post);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the span query whose matches are filtered
|
||||
*/
|
||||
|
@ -232,24 +249,6 @@ public class SpanNotQueryBuilder extends AbstractQueryBuilder<SpanNotQueryBuilde
|
|||
return new SpanNotQuery((SpanQuery) includeQuery, (SpanQuery) excludeQuery, pre, post);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpanNotQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
SpanQueryBuilder include = (SpanQueryBuilder)in.readQuery();
|
||||
SpanQueryBuilder exclude = (SpanQueryBuilder)in.readQuery();
|
||||
SpanNotQueryBuilder queryBuilder = new SpanNotQueryBuilder(include, exclude);
|
||||
queryBuilder.pre(in.readVInt());
|
||||
queryBuilder.post(in.readVInt());
|
||||
return queryBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(include);
|
||||
out.writeQuery(exclude);
|
||||
out.writeVInt(pre);
|
||||
out.writeVInt(post);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(include, exclude, pre, post);
|
||||
|
|
|
@ -41,7 +41,6 @@ public class SpanOrQueryBuilder extends AbstractQueryBuilder<SpanOrQueryBuilder>
|
|||
|
||||
public static final String NAME = "span_or";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final SpanOrQueryBuilder PROTOTYPE = new SpanOrQueryBuilder(SpanTermQueryBuilder.PROTOTYPE);
|
||||
|
||||
private static final ParseField CLAUSES_FIELD = new ParseField("clauses");
|
||||
|
||||
|
@ -54,6 +53,21 @@ public class SpanOrQueryBuilder extends AbstractQueryBuilder<SpanOrQueryBuilder>
|
|||
clauses.add(initialClause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public SpanOrQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
for (QueryBuilder<?> clause: readQueries(in)) {
|
||||
clauses.add((SpanQueryBuilder<?>) clause);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
writeQueries(out, clauses);
|
||||
}
|
||||
|
||||
public SpanOrQueryBuilder clause(SpanQueryBuilder<?> clause) {
|
||||
if (clause == null) {
|
||||
throw new IllegalArgumentException("inner bool query clause cannot be null");
|
||||
|
@ -141,22 +155,6 @@ public class SpanOrQueryBuilder extends AbstractQueryBuilder<SpanOrQueryBuilder>
|
|||
return new SpanOrQuery(spanQueries);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpanOrQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
List<QueryBuilder<?>> clauses = readQueries(in);
|
||||
SpanOrQueryBuilder queryBuilder = new SpanOrQueryBuilder((SpanQueryBuilder<?>)clauses.get(0));
|
||||
for (int i = 1; i < clauses.size(); i++) {
|
||||
queryBuilder.clauses.add((SpanQueryBuilder<?>)clauses.get(i));
|
||||
}
|
||||
return queryBuilder;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
writeQueries(out, clauses);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(clauses);
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.lucene.search.spans.SpanQuery;
|
|||
import org.apache.lucene.search.spans.SpanTermQuery;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.lucene.BytesRefs;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
|
@ -73,6 +74,13 @@ public class SpanTermQueryBuilder extends BaseTermQueryBuilder<SpanTermQueryBuil
|
|||
super(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public SpanTermQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpanQuery doToQuery(QueryShardContext context) throws IOException {
|
||||
MappedFieldType mapper = context.fieldMapper(fieldName);
|
||||
|
@ -138,11 +146,6 @@ public class SpanTermQueryBuilder extends BaseTermQueryBuilder<SpanTermQueryBuil
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpanTermQueryBuilder createBuilder(String fieldName, Object value) {
|
||||
return new SpanTermQueryBuilder(fieldName, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWriteableName() {
|
||||
return NAME;
|
||||
|
|
|
@ -40,21 +40,19 @@ public class SpanWithinQueryBuilder extends AbstractQueryBuilder<SpanWithinQuery
|
|||
|
||||
public static final String NAME = "span_within";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final SpanWithinQueryBuilder PROTOTYPE =
|
||||
new SpanWithinQueryBuilder(SpanTermQueryBuilder.PROTOTYPE, SpanTermQueryBuilder.PROTOTYPE);
|
||||
|
||||
private static final ParseField BIG_FIELD = new ParseField("big");
|
||||
private static final ParseField LITTLE_FIELD = new ParseField("little");
|
||||
|
||||
private final SpanQueryBuilder big;
|
||||
private final SpanQueryBuilder little;
|
||||
private final SpanQueryBuilder<?> big;
|
||||
private final SpanQueryBuilder<?> little;
|
||||
|
||||
/**
|
||||
* Query that returns spans from <code>little</code> that are contained in a spans from <code>big</code>.
|
||||
* @param big clause that must enclose {@code little} for a match.
|
||||
* @param little the little clause, it must be contained within {@code big} for a match.
|
||||
*/
|
||||
public SpanWithinQueryBuilder(SpanQueryBuilder big, SpanQueryBuilder little) {
|
||||
public SpanWithinQueryBuilder(SpanQueryBuilder<?> big, SpanQueryBuilder<?> little) {
|
||||
if (big == null) {
|
||||
throw new IllegalArgumentException("inner clause [big] cannot be null.");
|
||||
}
|
||||
|
@ -65,6 +63,21 @@ public class SpanWithinQueryBuilder extends AbstractQueryBuilder<SpanWithinQuery
|
|||
this.big = big;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public SpanWithinQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
big = (SpanQueryBuilder<?>) in.readQuery();
|
||||
little = (SpanQueryBuilder<?>) in.readQuery();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(big);
|
||||
out.writeQuery(little);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the little clause, contained within {@code big} for a match.
|
||||
*/
|
||||
|
@ -154,19 +167,6 @@ public class SpanWithinQueryBuilder extends AbstractQueryBuilder<SpanWithinQuery
|
|||
return new SpanWithinQuery((SpanQuery) innerBig, (SpanQuery) innerLittle);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpanWithinQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
SpanQueryBuilder big = (SpanQueryBuilder)in.readQuery();
|
||||
SpanQueryBuilder little = (SpanQueryBuilder)in.readQuery();
|
||||
return new SpanWithinQueryBuilder(big, little);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(big);
|
||||
out.writeQuery(little);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(big, little);
|
||||
|
|
|
@ -56,8 +56,6 @@ public class TemplateQueryBuilder extends AbstractQueryBuilder<TemplateQueryBuil
|
|||
/** Template to fill. */
|
||||
private final Template template;
|
||||
|
||||
public static final TemplateQueryBuilder PROTOTYPE = new TemplateQueryBuilder(new Template("proto"));
|
||||
|
||||
/**
|
||||
* @param template
|
||||
* the template to use for that query.
|
||||
|
@ -99,6 +97,19 @@ public class TemplateQueryBuilder extends AbstractQueryBuilder<TemplateQueryBuil
|
|||
this(new Template(template, templateType, null, null, vars));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public TemplateQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
template = Template.readTemplate(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
template.writeTo(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params builderParams) throws IOException {
|
||||
builder.field(TemplateQueryBuilder.NAME);
|
||||
|
@ -151,17 +162,6 @@ public class TemplateQueryBuilder extends AbstractQueryBuilder<TemplateQueryBuil
|
|||
throw new UnsupportedOperationException("this query must be rewritten first");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TemplateQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
TemplateQueryBuilder templateQueryBuilder = new TemplateQueryBuilder(Template.readTemplate(in));
|
||||
return templateQueryBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
template.writeTo(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(template);
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.lucene.search.Query;
|
|||
import org.apache.lucene.search.TermQuery;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.lucene.BytesRefs;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
|
@ -37,7 +38,6 @@ public class TermQueryBuilder extends BaseTermQueryBuilder<TermQueryBuilder> {
|
|||
|
||||
public static final String NAME = "term";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final TermQueryBuilder PROTOTYPE = new TermQueryBuilder("name", "value");
|
||||
|
||||
private static final ParseField TERM_FIELD = new ParseField("term");
|
||||
private static final ParseField VALUE_FIELD = new ParseField("value");
|
||||
|
@ -77,6 +77,13 @@ public class TermQueryBuilder extends BaseTermQueryBuilder<TermQueryBuilder> {
|
|||
super(fieldName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public TermQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
}
|
||||
|
||||
public static TermQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
|
||||
XContentParser parser = parseContext.parser();
|
||||
|
||||
|
@ -149,11 +156,6 @@ public class TermQueryBuilder extends BaseTermQueryBuilder<TermQueryBuilder> {
|
|||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TermQueryBuilder createBuilder(String fieldName, Object value) {
|
||||
return new TermQueryBuilder(fieldName, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWriteableName() {
|
||||
return NAME;
|
||||
|
|
|
@ -57,10 +57,9 @@ public class TermsQueryBuilder extends AbstractQueryBuilder<TermsQueryBuilder> {
|
|||
|
||||
public static final String NAME = "terms";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME, "in");
|
||||
public static final TermsQueryBuilder PROTOTYPE = new TermsQueryBuilder("field", "value");
|
||||
|
||||
private final String fieldName;
|
||||
private final List<Object> values;
|
||||
private final List<?> values;
|
||||
private final TermsLookup termsLookup;
|
||||
|
||||
public TermsQueryBuilder(String fieldName, TermsLookup termsLookup) {
|
||||
|
@ -164,6 +163,23 @@ public class TermsQueryBuilder extends AbstractQueryBuilder<TermsQueryBuilder> {
|
|||
this.termsLookup = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public TermsQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
termsLookup = in.readOptionalWriteable(TermsLookup::new);
|
||||
values = (List<?>) in.readGenericValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeOptionalWriteable(termsLookup);
|
||||
out.writeGenericValue(values);
|
||||
}
|
||||
|
||||
public String fieldName() {
|
||||
return this.fieldName;
|
||||
}
|
||||
|
@ -318,7 +334,7 @@ public class TermsQueryBuilder extends AbstractQueryBuilder<TermsQueryBuilder> {
|
|||
return terms;
|
||||
}
|
||||
|
||||
private static Query handleTermsQuery(List<Object> terms, String fieldName, QueryShardContext context) {
|
||||
private static Query handleTermsQuery(List<?> terms, String fieldName, QueryShardContext context) {
|
||||
MappedFieldType fieldType = context.fieldMapper(fieldName);
|
||||
String indexFieldName;
|
||||
if (fieldType != null) {
|
||||
|
@ -352,28 +368,6 @@ public class TermsQueryBuilder extends AbstractQueryBuilder<TermsQueryBuilder> {
|
|||
return query;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected TermsQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
String field = in.readString();
|
||||
TermsLookup lookup = null;
|
||||
if (in.readBoolean()) {
|
||||
lookup = TermsLookup.readTermsLookupFrom(in);
|
||||
}
|
||||
List<Object> values = (List<Object>) in.readGenericValue();
|
||||
return new TermsQueryBuilder(field, values, lookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeBoolean(termsLookup != null);
|
||||
if (termsLookup != null) {
|
||||
termsLookup.writeTo(out);
|
||||
}
|
||||
out.writeGenericValue(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(fieldName, values, termsLookup);
|
||||
|
|
|
@ -42,8 +42,6 @@ public class TypeQueryBuilder extends AbstractQueryBuilder<TypeQueryBuilder> {
|
|||
|
||||
private final BytesRef type;
|
||||
|
||||
public static final TypeQueryBuilder PROTOTYPE = new TypeQueryBuilder("type");
|
||||
|
||||
public TypeQueryBuilder(String type) {
|
||||
if (type == null) {
|
||||
throw new IllegalArgumentException("[type] cannot be null");
|
||||
|
@ -58,6 +56,19 @@ public class TypeQueryBuilder extends AbstractQueryBuilder<TypeQueryBuilder> {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public TypeQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
type = in.readBytesRef();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeBytesRef(type);
|
||||
}
|
||||
|
||||
public String type() {
|
||||
return BytesRefs.toString(this.type);
|
||||
}
|
||||
|
@ -126,16 +137,6 @@ public class TypeQueryBuilder extends AbstractQueryBuilder<TypeQueryBuilder> {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
return new TypeQueryBuilder(in.readBytesRef());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeBytesRef(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(type);
|
||||
|
|
|
@ -50,7 +50,6 @@ public class WildcardQueryBuilder extends AbstractQueryBuilder<WildcardQueryBuil
|
|||
|
||||
public static final String NAME = "wildcard";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
public static final WildcardQueryBuilder PROTOTYPE = new WildcardQueryBuilder("field", "value");
|
||||
|
||||
private static final ParseField WILDCARD_FIELD = new ParseField("wildcard");
|
||||
private static final ParseField VALUE_FIELD = new ParseField("value");
|
||||
|
@ -84,6 +83,23 @@ public class WildcardQueryBuilder extends AbstractQueryBuilder<WildcardQueryBuil
|
|||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public WildcardQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
fieldName = in.readString();
|
||||
value = in.readString();
|
||||
rewrite = in.readOptionalString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeString(value);
|
||||
out.writeOptionalString(rewrite);
|
||||
}
|
||||
|
||||
public String fieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
@ -162,7 +178,7 @@ public class WildcardQueryBuilder extends AbstractQueryBuilder<WildcardQueryBuil
|
|||
}
|
||||
|
||||
if (value == null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "No value specified for prefix query");
|
||||
throw new ParsingException(parser.getTokenLocation(), "No value specified for wildcard query");
|
||||
}
|
||||
return new WildcardQueryBuilder(fieldName, value)
|
||||
.rewrite(rewrite)
|
||||
|
@ -187,20 +203,6 @@ public class WildcardQueryBuilder extends AbstractQueryBuilder<WildcardQueryBuil
|
|||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WildcardQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
WildcardQueryBuilder wildcardQueryBuilder = new WildcardQueryBuilder(in.readString(), in.readString());
|
||||
wildcardQueryBuilder.rewrite = in.readOptionalString();
|
||||
return wildcardQueryBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeString(value);
|
||||
out.writeOptionalString(rewrite);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(fieldName, value, rewrite);
|
||||
|
|
|
@ -53,8 +53,6 @@ public class WrapperQueryBuilder extends AbstractQueryBuilder<WrapperQueryBuilde
|
|||
public static final String NAME = "wrapper";
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
|
||||
public static final WrapperQueryBuilder PROTOTYPE = new WrapperQueryBuilder((byte[]) new byte[]{0});
|
||||
|
||||
private static final ParseField QUERY_FIELD = new ParseField("query");
|
||||
|
||||
private final byte[] source;
|
||||
|
@ -89,6 +87,19 @@ public class WrapperQueryBuilder extends AbstractQueryBuilder<WrapperQueryBuilde
|
|||
this.source = source.array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public WrapperQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
source = in.readByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeByteArray(this.source);
|
||||
}
|
||||
|
||||
public byte[] source() {
|
||||
return this.source;
|
||||
}
|
||||
|
@ -138,16 +149,6 @@ public class WrapperQueryBuilder extends AbstractQueryBuilder<WrapperQueryBuilde
|
|||
throw new UnsupportedOperationException("this query must be rewritten first");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WrapperQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
return new WrapperQueryBuilder(in.readByteArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeByteArray(this.source);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Arrays.hashCode(source);
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.common.xcontent.XContentLocation;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.query.AbstractQueryBuilder;
|
||||
import org.elasticsearch.index.query.EmptyQueryBuilder;
|
||||
import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
|
@ -55,12 +54,7 @@ import java.util.Objects;
|
|||
* score.
|
||||
*/
|
||||
public class FunctionScoreQueryBuilder extends AbstractQueryBuilder<FunctionScoreQueryBuilder> {
|
||||
|
||||
public static final FunctionScoreQueryBuilder PROTOTYPE = new FunctionScoreQueryBuilder(EmptyQueryBuilder.PROTOTYPE,
|
||||
new FunctionScoreQueryBuilder.FilterFunctionBuilder[0]);
|
||||
|
||||
public static final String NAME = "function_score";
|
||||
|
||||
public static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
|
||||
// For better readability of error message
|
||||
|
@ -149,6 +143,29 @@ public class FunctionScoreQueryBuilder extends AbstractQueryBuilder<FunctionScor
|
|||
this.filterFunctionBuilders = filterFunctionBuilders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public FunctionScoreQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
query = in.readQuery();
|
||||
filterFunctionBuilders = in.readList(FilterFunctionBuilder::new).toArray(new FilterFunctionBuilder[0]);
|
||||
maxBoost = in.readFloat();
|
||||
minScore = in.readOptionalFloat();
|
||||
boostMode = in.readOptionalWriteable(CombineFunction::readFromStream);
|
||||
scoreMode = FiltersFunctionScoreQuery.ScoreMode.readFromStream(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(query);
|
||||
out.writeList(Arrays.asList(filterFunctionBuilders));
|
||||
out.writeFloat(maxBoost);
|
||||
out.writeOptionalFloat(minScore);
|
||||
out.writeOptionalWriteable(boostMode);
|
||||
scoreMode.writeTo(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the query that defines which documents the function_score query will be executed on.
|
||||
*/
|
||||
|
@ -275,49 +292,6 @@ public class FunctionScoreQueryBuilder extends AbstractQueryBuilder<FunctionScor
|
|||
this.maxBoost);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionScoreQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
QueryBuilder<?> query = in.readQuery();
|
||||
int size = in.readVInt();
|
||||
FilterFunctionBuilder[] filterFunctionBuilders = new FilterFunctionBuilder[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
filterFunctionBuilders[i] = new FilterFunctionBuilder(in);
|
||||
}
|
||||
FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(query, filterFunctionBuilders);
|
||||
functionScoreQueryBuilder.maxBoost(in.readFloat());
|
||||
if (in.readBoolean()) {
|
||||
functionScoreQueryBuilder.setMinScore(in.readFloat());
|
||||
}
|
||||
if (in.readBoolean()) {
|
||||
functionScoreQueryBuilder.boostMode(CombineFunction.readCombineFunctionFrom(in));
|
||||
}
|
||||
functionScoreQueryBuilder.scoreMode(FiltersFunctionScoreQuery.ScoreMode.readScoreModeFrom(in));
|
||||
return functionScoreQueryBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeQuery(query);
|
||||
out.writeVInt(filterFunctionBuilders.length);
|
||||
for (FilterFunctionBuilder filterFunctionBuilder : filterFunctionBuilders) {
|
||||
filterFunctionBuilder.writeTo(out);
|
||||
}
|
||||
out.writeFloat(maxBoost);
|
||||
if (minScore == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
out.writeFloat(minScore);
|
||||
}
|
||||
if (boostMode == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
boostMode.writeTo(out);
|
||||
}
|
||||
scoreMode.writeTo(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query doToQuery(QueryShardContext context) throws IOException {
|
||||
FilterFunction[] filterFunctions = new FilterFunction[filterFunctionBuilders.length];
|
||||
|
|
|
@ -116,14 +116,6 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl
|
|||
}, SearchSourceBuilder.INNER_HITS_FIELD);
|
||||
}
|
||||
|
||||
public static InnerHitBuilder optionalReadFromStream(StreamInput in) throws IOException {
|
||||
if (in.readBoolean()) {
|
||||
return new InnerHitBuilder(in);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String name;
|
||||
private String nestedPath;
|
||||
private String parentChildType;
|
||||
|
@ -143,8 +135,13 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl
|
|||
private InnerHitsBuilder innerHitsBuilder;
|
||||
private FetchSourceContext fetchSourceContext;
|
||||
|
||||
// pkg protected, because is used in InnerHitsBuilder
|
||||
InnerHitBuilder(StreamInput in) throws IOException {
|
||||
public InnerHitBuilder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public InnerHitBuilder(StreamInput in) throws IOException {
|
||||
name = in.readOptionalString();
|
||||
nestedPath = in.readOptionalString();
|
||||
parentChildType = in.readOptionalString();
|
||||
|
@ -156,9 +153,9 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl
|
|||
fieldNames = (List<String>) in.readGenericValue();
|
||||
fieldDataFields = (List<String>) in.readGenericValue();
|
||||
if (in.readBoolean()) {
|
||||
scriptFields = in.readList(t -> ScriptField.PROTOTYPE.readFrom(in));
|
||||
scriptFields = in.readList(ScriptField.PROTOTYPE::readFrom);
|
||||
}
|
||||
fetchSourceContext = FetchSourceContext.optionalReadFromStream(in);
|
||||
fetchSourceContext = in.readOptionalStreamable(FetchSourceContext::new);
|
||||
if (in.readBoolean()) {
|
||||
int size = in.readVInt();
|
||||
sorts = new ArrayList<>(size);
|
||||
|
@ -171,7 +168,35 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl
|
|||
innerHitsBuilder = in.readOptionalWriteable(InnerHitsBuilder.PROTO::readFrom);
|
||||
}
|
||||
|
||||
public InnerHitBuilder() {
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeOptionalString(name);
|
||||
out.writeOptionalString(nestedPath);
|
||||
out.writeOptionalString(parentChildType);
|
||||
out.writeVInt(from);
|
||||
out.writeVInt(size);
|
||||
out.writeBoolean(explain);
|
||||
out.writeBoolean(version);
|
||||
out.writeBoolean(trackScores);
|
||||
out.writeGenericValue(fieldNames);
|
||||
out.writeGenericValue(fieldDataFields);
|
||||
boolean hasScriptFields = scriptFields != null;
|
||||
out.writeBoolean(hasScriptFields);
|
||||
if (hasScriptFields) {
|
||||
out.writeList(scriptFields);
|
||||
}
|
||||
out.writeOptionalStreamable(fetchSourceContext);
|
||||
boolean hasSorts = sorts != null;
|
||||
out.writeBoolean(hasSorts);
|
||||
if (hasSorts) {
|
||||
out.writeVInt(sorts.size());
|
||||
for (SortBuilder<?> sort : sorts) {
|
||||
out.writeSortBuilder(sort);
|
||||
}
|
||||
}
|
||||
out.writeOptionalWriteable(highlightBuilder);
|
||||
out.writeQuery(query);
|
||||
out.writeOptionalWriteable(innerHitsBuilder);
|
||||
}
|
||||
|
||||
public InnerHitBuilder setParentChildType(String parentChildType) {
|
||||
|
@ -460,37 +485,6 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl
|
|||
innerHitsContext.parsedQuery(parsedQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeOptionalString(name);
|
||||
out.writeOptionalString(nestedPath);
|
||||
out.writeOptionalString(parentChildType);
|
||||
out.writeVInt(from);
|
||||
out.writeVInt(size);
|
||||
out.writeBoolean(explain);
|
||||
out.writeBoolean(version);
|
||||
out.writeBoolean(trackScores);
|
||||
out.writeGenericValue(fieldNames);
|
||||
out.writeGenericValue(fieldDataFields);
|
||||
boolean hasScriptFields = scriptFields != null;
|
||||
out.writeBoolean(hasScriptFields);
|
||||
if (hasScriptFields) {
|
||||
out.writeList(scriptFields);
|
||||
}
|
||||
FetchSourceContext.optionalWriteToStream(fetchSourceContext, out);
|
||||
boolean hasSorts = sorts != null;
|
||||
out.writeBoolean(hasSorts);
|
||||
if (hasSorts) {
|
||||
out.writeVInt(sorts.size());
|
||||
for (SortBuilder<?> sort : sorts) {
|
||||
out.writeSortBuilder(sort);
|
||||
}
|
||||
}
|
||||
out.writeOptionalWriteable(highlightBuilder);
|
||||
out.writeQuery(query);
|
||||
out.writeOptionalWriteable(innerHitsBuilder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
|
|
|
@ -64,14 +64,11 @@ public class MatchQuery {
|
|||
|
||||
private final int ordinal;
|
||||
|
||||
private static final Type PROTOTYPE = BOOLEAN;
|
||||
|
||||
private Type(int ordinal) {
|
||||
this.ordinal = ordinal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type readFrom(StreamInput in) throws IOException {
|
||||
public static Type readFromStream(StreamInput in) throws IOException {
|
||||
int ord = in.readVInt();
|
||||
for (Type type : Type.values()) {
|
||||
if (type.ordinal == ord) {
|
||||
|
@ -81,10 +78,6 @@ public class MatchQuery {
|
|||
throw new ElasticsearchException("unknown serialized type [" + ord + "]");
|
||||
}
|
||||
|
||||
public static Type readTypeFrom(StreamInput in) throws IOException {
|
||||
return PROTOTYPE.readFrom(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(this.ordinal);
|
||||
|
@ -97,14 +90,11 @@ public class MatchQuery {
|
|||
|
||||
private final int ordinal;
|
||||
|
||||
private static final ZeroTermsQuery PROTOTYPE = NONE;
|
||||
|
||||
private ZeroTermsQuery(int ordinal) {
|
||||
this.ordinal = ordinal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZeroTermsQuery readFrom(StreamInput in) throws IOException {
|
||||
public static ZeroTermsQuery readFromStream(StreamInput in) throws IOException {
|
||||
int ord = in.readVInt();
|
||||
for (ZeroTermsQuery zeroTermsQuery : ZeroTermsQuery.values()) {
|
||||
if (zeroTermsQuery.ordinal == ord) {
|
||||
|
@ -114,10 +104,6 @@ public class MatchQuery {
|
|||
throw new ElasticsearchException("unknown serialized type [" + ord + "]");
|
||||
}
|
||||
|
||||
public static ZeroTermsQuery readZeroTermsQueryFrom(StreamInput in) throws IOException {
|
||||
return PROTOTYPE.readFrom(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(this.ordinal);
|
||||
|
|
|
@ -35,8 +35,6 @@ import java.util.Objects;
|
|||
* Encapsulates the parameters needed to fetch terms.
|
||||
*/
|
||||
public class TermsLookup implements Writeable<TermsLookup>, ToXContent {
|
||||
static final TermsLookup PROTOTYPE = new TermsLookup("index", "type", "id", "path");
|
||||
|
||||
private String index;
|
||||
private final String type;
|
||||
private final String id;
|
||||
|
@ -64,6 +62,26 @@ public class TermsLookup implements Writeable<TermsLookup>, ToXContent {
|
|||
this.path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public TermsLookup(StreamInput in) throws IOException {
|
||||
type = in.readString();
|
||||
id = in.readString();
|
||||
path = in.readString();
|
||||
index = in.readOptionalString();
|
||||
routing = in.readOptionalString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeString(type);
|
||||
out.writeString(id);
|
||||
out.writeString(path);
|
||||
out.writeOptionalString(index);
|
||||
out.writeOptionalString(routing);
|
||||
}
|
||||
|
||||
public String index() {
|
||||
return index;
|
||||
}
|
||||
|
@ -139,30 +157,6 @@ public class TermsLookup implements Writeable<TermsLookup>, ToXContent {
|
|||
return index + "/" + type + "/" + id + "/" + path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TermsLookup readFrom(StreamInput in) throws IOException {
|
||||
String type = in.readString();
|
||||
String id = in.readString();
|
||||
String path = in.readString();
|
||||
String index = in.readOptionalString();
|
||||
TermsLookup termsLookup = new TermsLookup(index, type, id, path);
|
||||
termsLookup.routing = in.readOptionalString();
|
||||
return termsLookup;
|
||||
}
|
||||
|
||||
public static TermsLookup readTermsLookupFrom(StreamInput in) throws IOException {
|
||||
return PROTOTYPE.readFrom(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeString(type);
|
||||
out.writeString(id);
|
||||
out.writeString(path);
|
||||
out.writeOptionalString(index);
|
||||
out.writeOptionalString(routing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
if (index != null) {
|
||||
|
|
|
@ -535,85 +535,68 @@ public class SearchModule extends AbstractModule {
|
|||
}
|
||||
|
||||
private void registerBuiltinQueryParsers() {
|
||||
registerQuery(MatchQueryBuilder.PROTOTYPE::readFrom, MatchQueryBuilder::fromXContent, MatchQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(MatchPhraseQueryBuilder.PROTOTYPE::readFrom, MatchPhraseQueryBuilder::fromXContent,
|
||||
MatchPhraseQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(MatchPhrasePrefixQueryBuilder.PROTOTYPE::readFrom, MatchPhrasePrefixQueryBuilder::fromXContent,
|
||||
registerQuery(MatchQueryBuilder::new, MatchQueryBuilder::fromXContent, MatchQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(MatchPhraseQueryBuilder::new, MatchPhraseQueryBuilder::fromXContent, MatchPhraseQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(MatchPhrasePrefixQueryBuilder::new, MatchPhrasePrefixQueryBuilder::fromXContent,
|
||||
MatchPhrasePrefixQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(MultiMatchQueryBuilder.PROTOTYPE::readFrom, MultiMatchQueryBuilder::fromXContent,
|
||||
MultiMatchQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(NestedQueryBuilder.PROTOTYPE::readFrom, NestedQueryBuilder::fromXContent, NestedQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(HasChildQueryBuilder.PROTOTYPE::readFrom, HasChildQueryBuilder::fromXContent, HasChildQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(HasParentQueryBuilder.PROTOTYPE::readFrom, HasParentQueryBuilder::fromXContent,
|
||||
HasParentQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(DisMaxQueryBuilder.PROTOTYPE::readFrom, DisMaxQueryBuilder::fromXContent, DisMaxQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(IdsQueryBuilder.PROTOTYPE::readFrom, IdsQueryBuilder::fromXContent, IdsQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(MatchAllQueryBuilder.PROTOTYPE::readFrom, MatchAllQueryBuilder::fromXContent, MatchAllQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(QueryStringQueryBuilder.PROTOTYPE::readFrom, QueryStringQueryBuilder::fromXContent,
|
||||
QueryStringQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(BoostingQueryBuilder.PROTOTYPE::readFrom, BoostingQueryBuilder::fromXContent, BoostingQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(MultiMatchQueryBuilder::new, MultiMatchQueryBuilder::fromXContent, MultiMatchQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(NestedQueryBuilder::new, NestedQueryBuilder::fromXContent, NestedQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(HasChildQueryBuilder::new, HasChildQueryBuilder::fromXContent, HasChildQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(HasParentQueryBuilder::new, HasParentQueryBuilder::fromXContent, HasParentQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(DisMaxQueryBuilder::new, DisMaxQueryBuilder::fromXContent, DisMaxQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(IdsQueryBuilder::new, IdsQueryBuilder::fromXContent, IdsQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(MatchAllQueryBuilder::new, MatchAllQueryBuilder::fromXContent, MatchAllQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(QueryStringQueryBuilder::new, QueryStringQueryBuilder::fromXContent, QueryStringQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(BoostingQueryBuilder::new, BoostingQueryBuilder::fromXContent, BoostingQueryBuilder.QUERY_NAME_FIELD);
|
||||
BooleanQuery.setMaxClauseCount(settings.getAsInt("index.query.bool.max_clause_count",
|
||||
settings.getAsInt("indices.query.bool.max_clause_count", BooleanQuery.getMaxClauseCount())));
|
||||
registerQuery(BoolQueryBuilder.PROTOTYPE::readFrom, BoolQueryBuilder::fromXContent, BoolQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(TermQueryBuilder.PROTOTYPE::readFrom, TermQueryBuilder::fromXContent, TermQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(TermsQueryBuilder.PROTOTYPE::readFrom, TermsQueryBuilder::fromXContent, TermsQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(FuzzyQueryBuilder.PROTOTYPE::readFrom, FuzzyQueryBuilder::fromXContent, FuzzyQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(RegexpQueryBuilder.PROTOTYPE::readFrom, RegexpQueryBuilder::fromXContent, RegexpQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(RangeQueryBuilder.PROTOTYPE::readFrom, RangeQueryBuilder::fromXContent, RangeQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(PrefixQueryBuilder.PROTOTYPE::readFrom, PrefixQueryBuilder::fromXContent, PrefixQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(WildcardQueryBuilder.PROTOTYPE::readFrom, WildcardQueryBuilder::fromXContent, WildcardQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(ConstantScoreQueryBuilder.PROTOTYPE::readFrom, ConstantScoreQueryBuilder::fromXContent,
|
||||
ConstantScoreQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(SpanTermQueryBuilder.PROTOTYPE::readFrom, SpanTermQueryBuilder::fromXContent, SpanTermQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(SpanNotQueryBuilder.PROTOTYPE::readFrom, SpanNotQueryBuilder::fromXContent, SpanNotQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(SpanWithinQueryBuilder.PROTOTYPE::readFrom, SpanWithinQueryBuilder::fromXContent,
|
||||
SpanWithinQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(SpanContainingQueryBuilder.PROTOTYPE::readFrom, SpanContainingQueryBuilder::fromXContent,
|
||||
registerQuery(BoolQueryBuilder::new, BoolQueryBuilder::fromXContent, BoolQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(TermQueryBuilder::new, TermQueryBuilder::fromXContent, TermQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(TermsQueryBuilder::new, TermsQueryBuilder::fromXContent, TermsQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(FuzzyQueryBuilder::new, FuzzyQueryBuilder::fromXContent, FuzzyQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(RegexpQueryBuilder::new, RegexpQueryBuilder::fromXContent, RegexpQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(RangeQueryBuilder::new, RangeQueryBuilder::fromXContent, RangeQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(PrefixQueryBuilder::new, PrefixQueryBuilder::fromXContent, PrefixQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(WildcardQueryBuilder::new, WildcardQueryBuilder::fromXContent, WildcardQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(ConstantScoreQueryBuilder::new, ConstantScoreQueryBuilder::fromXContent, ConstantScoreQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(SpanTermQueryBuilder::new, SpanTermQueryBuilder::fromXContent, SpanTermQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(SpanNotQueryBuilder::new, SpanNotQueryBuilder::fromXContent, SpanNotQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(SpanWithinQueryBuilder::new, SpanWithinQueryBuilder::fromXContent, SpanWithinQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(SpanContainingQueryBuilder::new, SpanContainingQueryBuilder::fromXContent,
|
||||
SpanContainingQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(FieldMaskingSpanQueryBuilder.PROTOTYPE::readFrom, FieldMaskingSpanQueryBuilder::fromXContent,
|
||||
registerQuery(FieldMaskingSpanQueryBuilder::new, FieldMaskingSpanQueryBuilder::fromXContent,
|
||||
FieldMaskingSpanQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(SpanFirstQueryBuilder.PROTOTYPE::readFrom, SpanFirstQueryBuilder::fromXContent,
|
||||
SpanFirstQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(SpanNearQueryBuilder.PROTOTYPE::readFrom, SpanNearQueryBuilder::fromXContent, SpanNearQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(SpanOrQueryBuilder.PROTOTYPE::readFrom, SpanOrQueryBuilder::fromXContent, SpanOrQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(MoreLikeThisQueryBuilder.PROTOTYPE::readFrom, MoreLikeThisQueryBuilder::fromXContent,
|
||||
MoreLikeThisQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(WrapperQueryBuilder.PROTOTYPE::readFrom, WrapperQueryBuilder::fromXContent, WrapperQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(IndicesQueryBuilder.PROTOTYPE::readFrom, IndicesQueryBuilder::fromXContent, IndicesQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(CommonTermsQueryBuilder.PROTOTYPE::readFrom, CommonTermsQueryBuilder::fromXContent,
|
||||
CommonTermsQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(SpanMultiTermQueryBuilder.PROTOTYPE::readFrom, SpanMultiTermQueryBuilder::fromXContent,
|
||||
SpanMultiTermQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(FunctionScoreQueryBuilder.PROTOTYPE::readFrom, c -> FunctionScoreQueryBuilder.fromXContent(scoreFunctionsRegistry, c),
|
||||
registerQuery(SpanFirstQueryBuilder::new, SpanFirstQueryBuilder::fromXContent, SpanFirstQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(SpanNearQueryBuilder::new, SpanNearQueryBuilder::fromXContent, SpanNearQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(SpanOrQueryBuilder::new, SpanOrQueryBuilder::fromXContent, SpanOrQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(MoreLikeThisQueryBuilder::new, MoreLikeThisQueryBuilder::fromXContent, MoreLikeThisQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(WrapperQueryBuilder::new, WrapperQueryBuilder::fromXContent, WrapperQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(IndicesQueryBuilder::new, IndicesQueryBuilder::fromXContent, IndicesQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(CommonTermsQueryBuilder::new, CommonTermsQueryBuilder::fromXContent, CommonTermsQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(SpanMultiTermQueryBuilder::new, SpanMultiTermQueryBuilder::fromXContent, SpanMultiTermQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(FunctionScoreQueryBuilder::new, c -> FunctionScoreQueryBuilder.fromXContent(scoreFunctionsRegistry, c),
|
||||
FunctionScoreQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(SimpleQueryStringBuilder.PROTOTYPE::readFrom, SimpleQueryStringBuilder::fromXContent,
|
||||
SimpleQueryStringBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(TemplateQueryBuilder.PROTOTYPE::readFrom, TemplateQueryBuilder::fromXContent, TemplateQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(TypeQueryBuilder.PROTOTYPE::readFrom, TypeQueryBuilder::fromXContent, TypeQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(ScriptQueryBuilder.PROTOTYPE::readFrom, ScriptQueryBuilder::fromXContent, ScriptQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(GeoDistanceQueryBuilder.PROTOTYPE::readFrom, GeoDistanceQueryBuilder::fromXContent,
|
||||
GeoDistanceQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(GeoDistanceRangeQueryBuilder.PROTOTYPE::readFrom, GeoDistanceRangeQueryBuilder::fromXContent,
|
||||
registerQuery(SimpleQueryStringBuilder::new, SimpleQueryStringBuilder::fromXContent, SimpleQueryStringBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(TemplateQueryBuilder::new, TemplateQueryBuilder::fromXContent, TemplateQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(TypeQueryBuilder::new, TypeQueryBuilder::fromXContent, TypeQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(ScriptQueryBuilder::new, ScriptQueryBuilder::fromXContent, ScriptQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(GeoDistanceQueryBuilder::new, GeoDistanceQueryBuilder::fromXContent, GeoDistanceQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(GeoDistanceRangeQueryBuilder::new, GeoDistanceRangeQueryBuilder::fromXContent,
|
||||
GeoDistanceRangeQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(GeoBoundingBoxQueryBuilder.PROTOTYPE::readFrom, GeoBoundingBoxQueryBuilder::fromXContent,
|
||||
registerQuery(GeoBoundingBoxQueryBuilder::new, GeoBoundingBoxQueryBuilder::fromXContent,
|
||||
GeoBoundingBoxQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(GeohashCellQuery.Builder.PROTOTYPE::readFrom, GeohashCellQuery.Builder::fromXContent,
|
||||
GeohashCellQuery.QUERY_NAME_FIELD);
|
||||
registerQuery(GeoPolygonQueryBuilder.PROTOTYPE::readFrom, GeoPolygonQueryBuilder::fromXContent,
|
||||
GeoPolygonQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(ExistsQueryBuilder.PROTOTYPE::readFrom, ExistsQueryBuilder::fromXContent, ExistsQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(MatchNoneQueryBuilder.PROTOTYPE::readFrom, MatchNoneQueryBuilder::fromXContent,
|
||||
MatchNoneQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(ParentIdQueryBuilder.PROTO::readFrom, ParentIdQueryBuilder::fromXContent, ParentIdQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(PercolatorQueryBuilder.PROTO::readFrom, PercolatorQueryBuilder::fromXContent,
|
||||
PercolatorQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(GeohashCellQuery.Builder::new, GeohashCellQuery.Builder::fromXContent, GeohashCellQuery.QUERY_NAME_FIELD);
|
||||
registerQuery(GeoPolygonQueryBuilder::new, GeoPolygonQueryBuilder::fromXContent, GeoPolygonQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(ExistsQueryBuilder::new, ExistsQueryBuilder::fromXContent, ExistsQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(MatchNoneQueryBuilder::new, MatchNoneQueryBuilder::fromXContent, MatchNoneQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(ParentIdQueryBuilder::new, ParentIdQueryBuilder::fromXContent, ParentIdQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(PercolatorQueryBuilder::new, PercolatorQueryBuilder::fromXContent, PercolatorQueryBuilder.QUERY_NAME_FIELD);
|
||||
if (ShapesAvailability.JTS_AVAILABLE && ShapesAvailability.SPATIAL4J_AVAILABLE) {
|
||||
registerQuery(GeoShapeQueryBuilder.PROTOTYPE::readFrom, GeoShapeQueryBuilder::fromXContent,
|
||||
GeoShapeQueryBuilder.QUERY_NAME_FIELD);
|
||||
registerQuery(GeoShapeQueryBuilder::new, GeoShapeQueryBuilder::fromXContent, GeoShapeQueryBuilder.QUERY_NAME_FIELD);
|
||||
}
|
||||
// EmptyQueryBuilder is not registered as query parser but used internally.
|
||||
// We need to register it with the NamedWriteableRegistry in order to serialize it
|
||||
namedWriteableRegistry.registerPrototype(QueryBuilder.class, EmptyQueryBuilder.PROTOTYPE);
|
||||
namedWriteableRegistry.register(QueryBuilder.class, EmptyQueryBuilder.NAME, EmptyQueryBuilder::new);
|
||||
}
|
||||
|
||||
static {
|
||||
|
|
|
@ -210,7 +210,7 @@ public class GeoDistanceAggregatorBuilder extends ValuesSourceAggregatorBuilder<
|
|||
factory.addRange(Range.PROTOTYPE.readFrom(in));
|
||||
}
|
||||
factory.keyed = in.readBoolean();
|
||||
factory.distanceType = GeoDistance.readGeoDistanceFrom(in);
|
||||
factory.distanceType = GeoDistance.readFromStream(in);
|
||||
factory.unit = DistanceUnit.readFromStream(in);
|
||||
return factory;
|
||||
}
|
||||
|
|
|
@ -522,7 +522,7 @@ public class TopHitsAggregatorBuilder extends AggregatorBuilder<TopHitsAggregato
|
|||
protected TopHitsAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException {
|
||||
TopHitsAggregatorBuilder factory = new TopHitsAggregatorBuilder(name);
|
||||
factory.explain = in.readBoolean();
|
||||
factory.fetchSourceContext = FetchSourceContext.optionalReadFromStream(in);
|
||||
factory.fetchSourceContext = in.readOptionalStreamable(FetchSourceContext::new);
|
||||
if (in.readBoolean()) {
|
||||
int size = in.readVInt();
|
||||
List<String> fieldDataFields = new ArrayList<>(size);
|
||||
|
@ -566,7 +566,7 @@ public class TopHitsAggregatorBuilder extends AggregatorBuilder<TopHitsAggregato
|
|||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeBoolean(explain);
|
||||
FetchSourceContext.optionalWriteToStream(fetchSourceContext, out);
|
||||
out.writeOptionalStreamable(fetchSourceContext);
|
||||
boolean hasFieldDataFields = fieldDataFields != null;
|
||||
out.writeBoolean(hasFieldDataFields);
|
||||
if (hasFieldDataFields) {
|
||||
|
|
|
@ -1196,7 +1196,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ
|
|||
builder.aggregations = AggregatorFactories.Builder.PROTOTYPE.readFrom(in);
|
||||
}
|
||||
builder.explain = in.readOptionalBoolean();
|
||||
builder.fetchSourceContext = FetchSourceContext.optionalReadFromStream(in);
|
||||
builder.fetchSourceContext = in.readOptionalStreamable(FetchSourceContext::new);
|
||||
boolean hasFieldDataFields = in.readBoolean();
|
||||
if (hasFieldDataFields) {
|
||||
int size = in.readVInt();
|
||||
|
@ -1300,7 +1300,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ
|
|||
aggregations.writeTo(out);
|
||||
}
|
||||
out.writeOptionalBoolean(explain);
|
||||
FetchSourceContext.optionalWriteToStream(fetchSourceContext, out);
|
||||
out.writeOptionalStreamable(fetchSourceContext);
|
||||
boolean hasFieldDataFields = fieldDataFields != null;
|
||||
out.writeBoolean(hasFieldDataFields);
|
||||
if (hasFieldDataFields) {
|
||||
|
|
|
@ -56,8 +56,7 @@ public class FetchSourceContext implements Streamable, ToXContent {
|
|||
return fetchSourceContext;
|
||||
}
|
||||
|
||||
FetchSourceContext() {
|
||||
|
||||
public FetchSourceContext() {
|
||||
}
|
||||
|
||||
public FetchSourceContext(boolean fetchSource) {
|
||||
|
@ -115,24 +114,6 @@ public class FetchSourceContext implements Streamable, ToXContent {
|
|||
return this;
|
||||
}
|
||||
|
||||
public static FetchSourceContext optionalReadFromStream(StreamInput in) throws IOException {
|
||||
if (!in.readBoolean()) {
|
||||
return null;
|
||||
}
|
||||
FetchSourceContext context = new FetchSourceContext();
|
||||
context.readFrom(in);
|
||||
return context;
|
||||
}
|
||||
|
||||
public static void optionalWriteToStream(FetchSourceContext context, StreamOutput out) throws IOException {
|
||||
if (context == null) {
|
||||
out.writeBoolean(false);
|
||||
return;
|
||||
}
|
||||
out.writeBoolean(true);
|
||||
context.writeTo(out);
|
||||
}
|
||||
|
||||
public static FetchSourceContext parseFromRestRequest(RestRequest request) {
|
||||
Boolean fetchSource = null;
|
||||
String[] source_excludes = null;
|
||||
|
|
|
@ -155,7 +155,7 @@ public class GeoDistanceSortBuilder extends SortBuilder<GeoDistanceSortBuilder>
|
|||
public GeoDistanceSortBuilder(StreamInput in) throws IOException {
|
||||
fieldName = in.readString();
|
||||
points.addAll((List<GeoPoint>) in.readGenericValue());
|
||||
geoDistance = GeoDistance.readGeoDistanceFrom(in);
|
||||
geoDistance = GeoDistance.readFromStream(in);
|
||||
unit = DistanceUnit.readFromStream(in);
|
||||
order = SortOrder.readFromStream(in);
|
||||
sortMode = in.readOptionalWriteable(SortMode::readFromStream);
|
||||
|
|
|
@ -47,7 +47,7 @@ public class GeoDistanceTests extends ESTestCase {
|
|||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
geoDistance.writeTo(out);
|
||||
try (StreamInput in = StreamInput.wrap(out.bytes())) {;
|
||||
GeoDistance copy = GeoDistance.readGeoDistanceFrom(in);
|
||||
GeoDistance copy = GeoDistance.readFromStream(in);
|
||||
assertEquals(copy.toString() + " vs. " + geoDistance.toString(), copy, geoDistance);
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class GeoDistanceTests extends ESTestCase {
|
|||
out.writeVInt(randomIntBetween(Integer.MIN_VALUE, -1));
|
||||
}
|
||||
try (StreamInput in = StreamInput.wrap(out.bytes())) {
|
||||
GeoDistance.readGeoDistanceFrom(in);
|
||||
GeoDistance.readFromStream(in);
|
||||
} catch (IOException e) {
|
||||
assertThat(e.getMessage(), containsString("Unknown GeoDistance ordinal ["));
|
||||
}
|
||||
|
|
|
@ -285,6 +285,9 @@ public class BytesStreamsTests extends ESTestCase {
|
|||
out.writeOptionalBytesReference(new BytesArray("test"));
|
||||
out.writeOptionalDouble(null);
|
||||
out.writeOptionalDouble(1.2);
|
||||
out.writeTimeZone(DateTimeZone.forID("CET"));
|
||||
out.writeOptionalTimeZone(DateTimeZone.getDefault());
|
||||
out.writeOptionalTimeZone(null);
|
||||
final byte[] bytes = out.bytes().toBytes();
|
||||
StreamInput in = StreamInput.wrap(out.bytes().toBytes());
|
||||
assertEquals(in.available(), bytes.length);
|
||||
|
@ -311,6 +314,9 @@ public class BytesStreamsTests extends ESTestCase {
|
|||
assertThat(in.readOptionalBytesReference(), equalTo(new BytesArray("test")));
|
||||
assertNull(in.readOptionalDouble());
|
||||
assertThat(in.readOptionalDouble(), closeTo(1.2, 0.0001));
|
||||
assertEquals(DateTimeZone.forID("CET"), in.readTimeZone());
|
||||
assertEquals(DateTimeZone.getDefault(), in.readOptionalTimeZone());
|
||||
assertNull(in.readOptionalTimeZone());
|
||||
assertEquals(0, in.available());
|
||||
in.close();
|
||||
out.close();
|
||||
|
@ -543,5 +549,4 @@ public class BytesStreamsTests extends ESTestCase {
|
|||
assertEquals(point, geoPoint);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -179,6 +179,6 @@ public class FuzzinessTests extends ESTestCase {
|
|||
BytesStreamOutput output = new BytesStreamOutput();
|
||||
in.writeTo(output);
|
||||
StreamInput streamInput = StreamInput.wrap(output.bytes());
|
||||
return Fuzziness.readFuzzinessFrom(streamInput);
|
||||
return new Fuzziness(streamInput);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -656,9 +656,9 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|||
output.writeQuery(testQuery);
|
||||
try (StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(output.bytes()), namedWriteableRegistry)) {
|
||||
QueryBuilder<?> deserializedQuery = in.readQuery();
|
||||
assertEquals(deserializedQuery, testQuery);
|
||||
assertEquals(deserializedQuery.hashCode(), testQuery.hashCode());
|
||||
assertNotSame(deserializedQuery, testQuery);
|
||||
assertEquals(testQuery, deserializedQuery);
|
||||
assertEquals(testQuery.hashCode(), deserializedQuery.hashCode());
|
||||
assertNotSame(testQuery, deserializedQuery);
|
||||
return (QB) deserializedQuery;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,37 +84,37 @@ public class CombineFunctionTests extends ESTestCase {
|
|||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
out.writeVInt(0);
|
||||
try (StreamInput in = StreamInput.wrap(out.bytes())) {
|
||||
assertThat(CombineFunction.readCombineFunctionFrom(in), equalTo(CombineFunction.MULTIPLY));
|
||||
assertThat(CombineFunction.readFromStream(in), equalTo(CombineFunction.MULTIPLY));
|
||||
}
|
||||
}
|
||||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
out.writeVInt(1);
|
||||
try (StreamInput in = StreamInput.wrap(out.bytes())) {
|
||||
assertThat(CombineFunction.readCombineFunctionFrom(in), equalTo(CombineFunction.REPLACE));
|
||||
assertThat(CombineFunction.readFromStream(in), equalTo(CombineFunction.REPLACE));
|
||||
}
|
||||
}
|
||||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
out.writeVInt(2);
|
||||
try (StreamInput in = StreamInput.wrap(out.bytes())) {
|
||||
assertThat(CombineFunction.readCombineFunctionFrom(in), equalTo(CombineFunction.SUM));
|
||||
assertThat(CombineFunction.readFromStream(in), equalTo(CombineFunction.SUM));
|
||||
}
|
||||
}
|
||||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
out.writeVInt(3);
|
||||
try (StreamInput in = StreamInput.wrap(out.bytes())) {
|
||||
assertThat(CombineFunction.readCombineFunctionFrom(in), equalTo(CombineFunction.AVG));
|
||||
assertThat(CombineFunction.readFromStream(in), equalTo(CombineFunction.AVG));
|
||||
}
|
||||
}
|
||||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
out.writeVInt(4);
|
||||
try (StreamInput in = StreamInput.wrap(out.bytes())) {
|
||||
assertThat(CombineFunction.readCombineFunctionFrom(in), equalTo(CombineFunction.MIN));
|
||||
assertThat(CombineFunction.readFromStream(in), equalTo(CombineFunction.MIN));
|
||||
}
|
||||
}
|
||||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
out.writeVInt(5);
|
||||
try (StreamInput in = StreamInput.wrap(out.bytes())) {
|
||||
assertThat(CombineFunction.readCombineFunctionFrom(in), equalTo(CombineFunction.MAX));
|
||||
assertThat(CombineFunction.readFromStream(in), equalTo(CombineFunction.MAX));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,12 +96,7 @@ public class ConstantScoreQueryBuilderTests extends AbstractQueryTestCase<Consta
|
|||
}
|
||||
|
||||
public void testIllegalArguments() {
|
||||
try {
|
||||
new ConstantScoreQueryBuilder(null);
|
||||
fail("must not be null");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
expectThrows(IllegalArgumentException.class, () -> new ConstantScoreQueryBuilder((QueryBuilder<?>) null));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -73,16 +73,8 @@ public class ExistsQueryBuilderTests extends AbstractQueryTestCase<ExistsQueryBu
|
|||
}
|
||||
|
||||
public void testIllegalArguments() {
|
||||
try {
|
||||
if (randomBoolean()) {
|
||||
new ExistsQueryBuilder(null);
|
||||
} else {
|
||||
new ExistsQueryBuilder("");
|
||||
}
|
||||
fail("must not be null or empty");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
expectThrows(IllegalArgumentException.class, () -> new ExistsQueryBuilder((String) null));
|
||||
expectThrows(IllegalArgumentException.class, () -> new ExistsQueryBuilder(""));
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
|
|
|
@ -19,9 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.locationtech.spatial4j.io.GeohashUtils;
|
||||
import org.locationtech.spatial4j.shape.Rectangle;
|
||||
import org.apache.lucene.search.BooleanClause;
|
||||
import org.apache.lucene.search.BooleanQuery;
|
||||
import org.apache.lucene.search.ConstantScoreQuery;
|
||||
|
@ -29,10 +26,13 @@ import org.apache.lucene.search.LegacyNumericRangeQuery;
|
|||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.spatial.geopoint.search.GeoPointInBBoxQuery;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.geo.GeoUtils;
|
||||
import org.elasticsearch.index.search.geo.InMemoryGeoBoundingBoxQuery;
|
||||
import org.elasticsearch.test.geo.RandomShapeGenerator;
|
||||
import org.locationtech.spatial4j.io.GeohashUtils;
|
||||
import org.locationtech.spatial4j.shape.Rectangle;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -89,12 +89,8 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|||
}
|
||||
|
||||
public void testValidationNullFieldname() {
|
||||
try {
|
||||
new GeoBoundingBoxQueryBuilder(null);
|
||||
fail("Expected IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertThat(e.getMessage(), is("Field name must not be empty."));
|
||||
}
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new GeoBoundingBoxQueryBuilder((String) null));
|
||||
assertEquals("Field name must not be empty.", e.getMessage());
|
||||
}
|
||||
|
||||
public void testValidationNullType() {
|
||||
|
|
|
@ -81,7 +81,7 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
if (randomBoolean()) {
|
||||
new GeoDistanceQueryBuilder("");
|
||||
} else {
|
||||
new GeoDistanceQueryBuilder(null);
|
||||
new GeoDistanceQueryBuilder((String) null);
|
||||
}
|
||||
fail("must not be null or empty");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
|
|
|
@ -54,13 +54,13 @@ public class OperatorTests extends ESTestCase {
|
|||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
out.writeVInt(0);
|
||||
try (StreamInput in = StreamInput.wrap(out.bytes())) {
|
||||
assertThat(Operator.readOperatorFrom(in), equalTo(Operator.OR));
|
||||
assertThat(Operator.readFromStream(in), equalTo(Operator.OR));
|
||||
}
|
||||
}
|
||||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
out.writeVInt(1);
|
||||
try (StreamInput in = StreamInput.wrap(out.bytes())) {
|
||||
assertThat(Operator.readOperatorFrom(in), equalTo(Operator.AND));
|
||||
assertThat(Operator.readFromStream(in), equalTo(Operator.AND));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.elasticsearch.common.compress.CompressedXContent;
|
|||
import org.elasticsearch.index.fielddata.IndexFieldDataService;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
|
||||
import org.elasticsearch.search.fetch.innerhits.InnerHitsContext;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.elasticsearch.test.TestSearchContext;
|
||||
import org.hamcrest.Matchers;
|
||||
|
|
|
@ -155,12 +155,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testIllegalArguments() {
|
||||
try {
|
||||
new QueryStringQueryBuilder(null);
|
||||
fail("null is not allowed");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
expectThrows(IllegalArgumentException.class, () -> new QueryStringQueryBuilder((String) null));
|
||||
}
|
||||
|
||||
public void testToQueryMatchAllQuery() throws Exception {
|
||||
|
|
|
@ -135,16 +135,8 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
|
|||
}
|
||||
|
||||
public void testIllegalArguments() {
|
||||
try {
|
||||
if (randomBoolean()) {
|
||||
new RangeQueryBuilder(null);
|
||||
} else {
|
||||
new RangeQueryBuilder("");
|
||||
}
|
||||
fail("cannot be null or empty");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
expectThrows(IllegalArgumentException.class, () -> new RangeQueryBuilder((String) null));
|
||||
expectThrows(IllegalArgumentException.class, () -> new RangeQueryBuilder(""));
|
||||
|
||||
RangeQueryBuilder rangeQueryBuilder = new RangeQueryBuilder("test");
|
||||
try {
|
||||
|
|
|
@ -84,37 +84,37 @@ public class ScoreModeTests extends ESTestCase {
|
|||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
out.writeVInt(0);
|
||||
try (StreamInput in = StreamInput.wrap(out.bytes())) {
|
||||
assertThat(FiltersFunctionScoreQuery.ScoreMode.readScoreModeFrom(in), equalTo(FiltersFunctionScoreQuery.ScoreMode.FIRST));
|
||||
assertThat(FiltersFunctionScoreQuery.ScoreMode.readFromStream(in), equalTo(FiltersFunctionScoreQuery.ScoreMode.FIRST));
|
||||
}
|
||||
}
|
||||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
out.writeVInt(1);
|
||||
try (StreamInput in = StreamInput.wrap(out.bytes())) {
|
||||
assertThat(FiltersFunctionScoreQuery.ScoreMode.readScoreModeFrom(in), equalTo(FiltersFunctionScoreQuery.ScoreMode.AVG));
|
||||
assertThat(FiltersFunctionScoreQuery.ScoreMode.readFromStream(in), equalTo(FiltersFunctionScoreQuery.ScoreMode.AVG));
|
||||
}
|
||||
}
|
||||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
out.writeVInt(2);
|
||||
try (StreamInput in = StreamInput.wrap(out.bytes())) {
|
||||
assertThat(FiltersFunctionScoreQuery.ScoreMode.readScoreModeFrom(in), equalTo(FiltersFunctionScoreQuery.ScoreMode.MAX));
|
||||
assertThat(FiltersFunctionScoreQuery.ScoreMode.readFromStream(in), equalTo(FiltersFunctionScoreQuery.ScoreMode.MAX));
|
||||
}
|
||||
}
|
||||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
out.writeVInt(3);
|
||||
try (StreamInput in = StreamInput.wrap(out.bytes())) {
|
||||
assertThat(FiltersFunctionScoreQuery.ScoreMode.readScoreModeFrom(in), equalTo(FiltersFunctionScoreQuery.ScoreMode.SUM));
|
||||
assertThat(FiltersFunctionScoreQuery.ScoreMode.readFromStream(in), equalTo(FiltersFunctionScoreQuery.ScoreMode.SUM));
|
||||
}
|
||||
}
|
||||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
out.writeVInt(4);
|
||||
try (StreamInput in = StreamInput.wrap(out.bytes())) {
|
||||
assertThat(FiltersFunctionScoreQuery.ScoreMode.readScoreModeFrom(in), equalTo(FiltersFunctionScoreQuery.ScoreMode.MIN));
|
||||
assertThat(FiltersFunctionScoreQuery.ScoreMode.readFromStream(in), equalTo(FiltersFunctionScoreQuery.ScoreMode.MIN));
|
||||
}
|
||||
}
|
||||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
out.writeVInt(5);
|
||||
try (StreamInput in = StreamInput.wrap(out.bytes())) {
|
||||
assertThat(FiltersFunctionScoreQuery.ScoreMode.readScoreModeFrom(in), equalTo(FiltersFunctionScoreQuery.ScoreMode.MULTIPLY));
|
||||
assertThat(FiltersFunctionScoreQuery.ScoreMode.readFromStream(in), equalTo(FiltersFunctionScoreQuery.ScoreMode.MULTIPLY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,12 +44,7 @@ public class ScriptQueryBuilderTests extends AbstractQueryTestCase<ScriptQueryBu
|
|||
}
|
||||
|
||||
public void testIllegalConstructorArg() {
|
||||
try {
|
||||
new ScriptQueryBuilder(null);
|
||||
fail("cannot be null");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
expectThrows(IllegalArgumentException.class, () -> new ScriptQueryBuilder((Script) null));
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
|
|
|
@ -173,12 +173,7 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
|
|||
}
|
||||
|
||||
public void testIllegalConstructorArg() {
|
||||
try {
|
||||
new SimpleQueryStringBuilder(null);
|
||||
fail("cannot be null");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
expectThrows(IllegalArgumentException.class, () -> new SimpleQueryStringBuilder((String) null));
|
||||
}
|
||||
|
||||
public void testFieldCannotBeNull() {
|
||||
|
|
|
@ -59,12 +59,7 @@ public class SpanMultiTermQueryBuilderTests extends AbstractQueryTestCase<SpanMu
|
|||
}
|
||||
|
||||
public void testIllegalArgument() {
|
||||
try {
|
||||
new SpanMultiTermQueryBuilder(null);
|
||||
fail("cannot be null");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
expectThrows(IllegalArgumentException.class, () -> new SpanMultiTermQueryBuilder((MultiTermQueryBuilder<?>) null));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,12 +52,7 @@ public class SpanOrQueryBuilderTests extends AbstractQueryTestCase<SpanOrQueryBu
|
|||
}
|
||||
|
||||
public void testIllegalArguments() {
|
||||
try {
|
||||
new SpanOrQueryBuilder(null);
|
||||
fail("cannot be null");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
expectThrows(IllegalArgumentException.class, () -> new SpanOrQueryBuilder((SpanQueryBuilder<?>) null));
|
||||
|
||||
try {
|
||||
SpanOrQueryBuilder spanOrBuilder = new SpanOrQueryBuilder(SpanTermQueryBuilder.PROTOTYPE);
|
||||
|
|
|
@ -64,12 +64,7 @@ public class TemplateQueryBuilderTests extends AbstractQueryTestCase<TemplateQue
|
|||
}
|
||||
|
||||
public void testIllegalArgument() {
|
||||
try {
|
||||
new TemplateQueryBuilder(null);
|
||||
fail("cannot be null");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
expectThrows(IllegalArgumentException.class, () -> new TemplateQueryBuilder((Template) null));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -49,13 +49,28 @@ public class DummyQueryParserPlugin extends Plugin {
|
|||
}
|
||||
|
||||
public void onModule(SearchModule module) {
|
||||
module.registerQuery(new DummyQueryBuilder()::readFrom, DummyQueryBuilder::fromXContent, DummyQueryBuilder.QUERY_NAME_FIELD);
|
||||
module.registerQuery(DummyQueryBuilder::new, DummyQueryBuilder::fromXContent, DummyQueryBuilder.QUERY_NAME_FIELD);
|
||||
}
|
||||
|
||||
public static class DummyQueryBuilder extends AbstractQueryBuilder<DummyQueryBuilder> {
|
||||
private static final String NAME = "dummy";
|
||||
private static final ParseField QUERY_NAME_FIELD = new ParseField(NAME);
|
||||
|
||||
public DummyQueryBuilder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public DummyQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
// only the superclass has state
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME).endObject();
|
||||
|
@ -72,16 +87,6 @@ public class DummyQueryParserPlugin extends Plugin {
|
|||
return new DummyQuery(context.isFilter());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DummyQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
return new DummyQueryBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
// Do Nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return 0;
|
||||
|
|
|
@ -71,7 +71,7 @@ public class TermsLookupTests extends ESTestCase {
|
|||
try (BytesStreamOutput output = new BytesStreamOutput()) {
|
||||
termsLookup.writeTo(output);
|
||||
try (StreamInput in = StreamInput.wrap(output.bytes())) {
|
||||
TermsLookup deserializedLookup = TermsLookup.readTermsLookupFrom(in);
|
||||
TermsLookup deserializedLookup = new TermsLookup(in);
|
||||
assertEquals(deserializedLookup, termsLookup);
|
||||
assertEquals(deserializedLookup.hashCode(), termsLookup.hashCode());
|
||||
assertNotSame(deserializedLookup, termsLookup);
|
||||
|
|
|
@ -81,7 +81,7 @@ public class SearchModuleTests extends ModuleTestCase {
|
|||
public void testRegisterQueryParserDuplicate() {
|
||||
SearchModule module = new SearchModule(Settings.EMPTY, new NamedWriteableRegistry());
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> module
|
||||
.registerQuery(TermQueryBuilder.PROTOTYPE::readFrom, TermQueryBuilder::fromXContent, TermQueryBuilder.QUERY_NAME_FIELD));
|
||||
.registerQuery(TermQueryBuilder::new, TermQueryBuilder::fromXContent, TermQueryBuilder.QUERY_NAME_FIELD));
|
||||
assertThat(e.getMessage(), containsString("already registered for name [term] while trying to register [org.elasticsearch."));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue