Switches from manual field parsing to ParseField
This switches query parsing from manual field parsing to using ParseField. Also adds unit tests for each query that check original json can be parsed into query builders. Relates to #8964
This commit is contained in:
parent
6a2fa73fb5
commit
38e1ad5596
|
@ -67,9 +67,9 @@ public abstract class AbstractQueryBuilder<QB extends AbstractQueryBuilder> exte
|
|||
protected abstract void doXContent(XContentBuilder builder, Params params) throws IOException;
|
||||
|
||||
protected void printBoostAndQueryName(XContentBuilder builder) throws IOException {
|
||||
builder.field("boost", boost);
|
||||
builder.field(BOOST_FIELD.getPreferredName(), boost);
|
||||
if (queryName != null) {
|
||||
builder.field("_name", queryName);
|
||||
builder.field(NAME_FIELD.getPreferredName(), queryName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ public abstract class AbstractQueryBuilder<QB extends AbstractQueryBuilder> exte
|
|||
protected abstract Query doToQuery(QueryShardContext context) throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the query name for the query.
|
||||
* Sets the query name for the query.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
|
@ -117,7 +117,7 @@ public abstract class AbstractQueryBuilder<QB extends AbstractQueryBuilder> exte
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the query name for the query.
|
||||
* Returns the query name for the query.
|
||||
*/
|
||||
@Override
|
||||
public final String queryName() {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
|
@ -30,6 +31,8 @@ import java.util.Objects;
|
|||
|
||||
public abstract class BaseTermQueryBuilder<QB extends BaseTermQueryBuilder<QB>> extends AbstractQueryBuilder<QB> {
|
||||
|
||||
public static final ParseField VALUE_FIELD = new ParseField("value");
|
||||
|
||||
/** Name of field to match against. */
|
||||
protected final String fieldName;
|
||||
|
||||
|
@ -133,7 +136,7 @@ public abstract class BaseTermQueryBuilder<QB extends BaseTermQueryBuilder<QB>>
|
|||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(getName());
|
||||
builder.startObject(fieldName);
|
||||
builder.field("value", convertToStringIfBytesRef(this.value));
|
||||
builder.field(VALUE_FIELD.getPreferredName(), convertToStringIfBytesRef(this.value));
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
builder.endObject();
|
||||
|
|
|
@ -231,14 +231,14 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> {
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
doXArrayContent("must", mustClauses, builder, params);
|
||||
doXArrayContent("filter", filterClauses, builder, params);
|
||||
doXArrayContent("must_not", mustNotClauses, builder, params);
|
||||
doXArrayContent("should", shouldClauses, builder, params);
|
||||
builder.field("disable_coord", disableCoord);
|
||||
builder.field("adjust_pure_negative", adjustPureNegative);
|
||||
doXArrayContent(BoolQueryParser.MUST, mustClauses, builder, params);
|
||||
doXArrayContent(BoolQueryParser.FILTER, filterClauses, builder, params);
|
||||
doXArrayContent(BoolQueryParser.MUST_NOT, mustNotClauses, builder, params);
|
||||
doXArrayContent(BoolQueryParser.SHOULD, shouldClauses, builder, params);
|
||||
builder.field(BoolQueryParser.DISABLE_COORD_FIELD.getPreferredName(), disableCoord);
|
||||
builder.field(BoolQueryParser.ADJUST_PURE_NEGATIVE.getPreferredName(), adjustPureNegative);
|
||||
if (minimumShouldMatch != null) {
|
||||
builder.field("minimum_should_match", minimumShouldMatch);
|
||||
builder.field(BoolQueryParser.MINIMUM_SHOULD_MATCH.getPreferredName(), minimumShouldMatch);
|
||||
}
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.apache.lucene.search.BooleanQuery;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -34,6 +35,16 @@ import java.util.List;
|
|||
*/
|
||||
public class BoolQueryParser implements QueryParser<BoolQueryBuilder> {
|
||||
|
||||
public static final String MUSTNOT = "mustNot";
|
||||
public static final String MUST_NOT = "must_not";
|
||||
public static final String FILTER = "filter";
|
||||
public static final String SHOULD = "should";
|
||||
public static final String MUST = "must";
|
||||
public static final ParseField DISABLE_COORD_FIELD = new ParseField("disable_coord");
|
||||
public static final ParseField MINIMUM_SHOULD_MATCH = new ParseField("minimum_should_match");
|
||||
public static final ParseField MINIMUM_NUMBER_SHOULD_MATCH = new ParseField("minimum_number_should_match");
|
||||
public static final ParseField ADJUST_PURE_NEGATIVE = new ParseField("adjust_pure_negative");
|
||||
|
||||
@Inject
|
||||
public BoolQueryParser(Settings settings) {
|
||||
BooleanQuery.setMaxClauseCount(settings.getAsInt("index.query.bool.max_clause_count", settings.getAsInt("indices.query.bool.max_clause_count", BooleanQuery.getMaxClauseCount())));
|
||||
|
@ -69,20 +80,20 @@ public class BoolQueryParser implements QueryParser<BoolQueryBuilder> {
|
|||
// skip
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
switch (currentFieldName) {
|
||||
case "must":
|
||||
case MUST:
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
mustClauses.add(query);
|
||||
break;
|
||||
case "should":
|
||||
case SHOULD:
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
shouldClauses.add(query);
|
||||
break;
|
||||
case "filter":
|
||||
case FILTER:
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
filterClauses.add(query);
|
||||
break;
|
||||
case "must_not":
|
||||
case "mustNot":
|
||||
case MUST_NOT:
|
||||
case MUSTNOT:
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
mustNotClauses.add(query);
|
||||
break;
|
||||
|
@ -92,20 +103,20 @@ public class BoolQueryParser implements QueryParser<BoolQueryBuilder> {
|
|||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
switch (currentFieldName) {
|
||||
case "must":
|
||||
case MUST:
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
mustClauses.add(query);
|
||||
break;
|
||||
case "should":
|
||||
case SHOULD:
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
shouldClauses.add(query);
|
||||
break;
|
||||
case "filter":
|
||||
case FILTER:
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
filterClauses.add(query);
|
||||
break;
|
||||
case "must_not":
|
||||
case "mustNot":
|
||||
case MUST_NOT:
|
||||
case MUSTNOT:
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
mustNotClauses.add(query);
|
||||
break;
|
||||
|
@ -114,17 +125,17 @@ public class BoolQueryParser implements QueryParser<BoolQueryBuilder> {
|
|||
}
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, DISABLE_COORD_FIELD)) {
|
||||
disableCoord = parser.booleanValue();
|
||||
} else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, MINIMUM_SHOULD_MATCH)) {
|
||||
minimumShouldMatch = parser.textOrNull();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("minimum_number_should_match".equals(currentFieldName) || "minimumNumberShouldMatch".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, MINIMUM_NUMBER_SHOULD_MATCH)) {
|
||||
minimumShouldMatch = parser.textOrNull();
|
||||
} else if ("adjust_pure_negative".equals(currentFieldName) || "adjustPureNegative".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, ADJUST_PURE_NEGATIVE)) {
|
||||
adjustPureNegative = parser.booleanValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[bool] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -104,11 +104,11 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder<BoostingQueryBuil
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("positive");
|
||||
builder.field(BoostingQueryParser.POSITIVE_FIELD.getPreferredName());
|
||||
positiveQuery.toXContent(builder, params);
|
||||
builder.field("negative");
|
||||
builder.field(BoostingQueryParser.NEGATIVE_FIELD.getPreferredName());
|
||||
negativeQuery.toXContent(builder, params);
|
||||
builder.field("negative_boost", negativeBoost);
|
||||
builder.field(BoostingQueryParser.NEGATIVE_BOOST_FIELD.getPreferredName(), negativeBoost);
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
|
@ -29,6 +30,10 @@ import java.io.IOException;
|
|||
*/
|
||||
public class BoostingQueryParser implements QueryParser<BoostingQueryBuilder> {
|
||||
|
||||
public static final ParseField POSITIVE_FIELD = new ParseField("positive");
|
||||
public static final ParseField NEGATIVE_FIELD = new ParseField("negative");
|
||||
public static final ParseField NEGATIVE_BOOST_FIELD = new ParseField("negative_boost");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{BoostingQueryBuilder.NAME};
|
||||
|
@ -52,21 +57,21 @@ public class BoostingQueryParser implements QueryParser<BoostingQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if ("positive".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, POSITIVE_FIELD)) {
|
||||
positiveQuery = parseContext.parseInnerQueryBuilder();
|
||||
positiveQueryFound = true;
|
||||
} else if ("negative".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, NEGATIVE_FIELD)) {
|
||||
negativeQuery = parseContext.parseInnerQueryBuilder();
|
||||
negativeQueryFound = true;
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[boosting] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("negative_boost".equals(currentFieldName) || "negativeBoost".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, NEGATIVE_BOOST_FIELD)) {
|
||||
negativeBoost = parser.floatValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[boosting] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -202,21 +202,21 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue
|
|||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.startObject(fieldName);
|
||||
builder.field("query", text);
|
||||
builder.field("disable_coord", disableCoord);
|
||||
builder.field("high_freq_operator", highFreqOperator.toString());
|
||||
builder.field("low_freq_operator", lowFreqOperator.toString());
|
||||
builder.field(CommonTermsQueryParser.QUERY_FIELD.getPreferredName(), text);
|
||||
builder.field(CommonTermsQueryParser.DISABLE_COORD_FIELD.getPreferredName(), disableCoord);
|
||||
builder.field(CommonTermsQueryParser.HIGH_FREQ_OPERATOR_FIELD.getPreferredName(), highFreqOperator.toString());
|
||||
builder.field(CommonTermsQueryParser.LOW_FREQ_OPERATOR_FIELD.getPreferredName(), lowFreqOperator.toString());
|
||||
if (analyzer != null) {
|
||||
builder.field("analyzer", analyzer);
|
||||
builder.field(CommonTermsQueryParser.ANALYZER_FIELD.getPreferredName(), analyzer);
|
||||
}
|
||||
builder.field("cutoff_frequency", cutoffFrequency);
|
||||
builder.field(CommonTermsQueryParser.CUTOFF_FREQUENCY_FIELD.getPreferredName(), cutoffFrequency);
|
||||
if (lowFreqMinimumShouldMatch != null || highFreqMinimumShouldMatch != null) {
|
||||
builder.startObject("minimum_should_match");
|
||||
builder.startObject(CommonTermsQueryParser.MINIMUM_SHOULD_MATCH_FIELD.getPreferredName());
|
||||
if (lowFreqMinimumShouldMatch != null) {
|
||||
builder.field("low_freq", lowFreqMinimumShouldMatch);
|
||||
builder.field(CommonTermsQueryParser.LOW_FREQ_FIELD.getPreferredName(), lowFreqMinimumShouldMatch);
|
||||
}
|
||||
if (highFreqMinimumShouldMatch != null) {
|
||||
builder.field("high_freq", highFreqMinimumShouldMatch);
|
||||
builder.field(CommonTermsQueryParser.HIGH_FREQ_FIELD.getPreferredName(), highFreqMinimumShouldMatch);
|
||||
}
|
||||
builder.endObject();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
|
@ -29,6 +30,16 @@ import java.io.IOException;
|
|||
*/
|
||||
public class CommonTermsQueryParser implements QueryParser<CommonTermsQueryBuilder> {
|
||||
|
||||
public static final ParseField CUTOFF_FREQUENCY_FIELD = new ParseField("cutoff_frequency");
|
||||
public static final ParseField MINIMUM_SHOULD_MATCH_FIELD = new ParseField("minimum_should_match");
|
||||
public static final ParseField LOW_FREQ_OPERATOR_FIELD = new ParseField("low_freq_operator");
|
||||
public static final ParseField HIGH_FREQ_OPERATOR_FIELD = new ParseField("high_freq_operator");
|
||||
public static final ParseField DISABLE_COORD_FIELD = new ParseField("disable_coord");
|
||||
public static final ParseField ANALYZER_FIELD = new ParseField("analyzer");
|
||||
public static final ParseField QUERY_FIELD = new ParseField("query");
|
||||
public static final ParseField HIGH_FREQ_FIELD = new ParseField("high_freq");
|
||||
public static final ParseField LOW_FREQ_FIELD = new ParseField("low_freq");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[] { CommonTermsQueryBuilder.NAME };
|
||||
|
@ -59,15 +70,15 @@ public class CommonTermsQueryParser implements QueryParser<CommonTermsQueryBuild
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, MINIMUM_SHOULD_MATCH_FIELD)) {
|
||||
String innerFieldName = null;
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
innerFieldName = parser.currentName();
|
||||
} else if (token.isValue()) {
|
||||
if ("low_freq".equals(innerFieldName) || "lowFreq".equals(innerFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(innerFieldName, LOW_FREQ_FIELD)) {
|
||||
lowFreqMinimumShouldMatch = parser.text();
|
||||
} else if ("high_freq".equals(innerFieldName) || "highFreq".equals(innerFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(innerFieldName, HIGH_FREQ_FIELD)) {
|
||||
highFreqMinimumShouldMatch = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + CommonTermsQueryBuilder.NAME + "] query does not support [" + innerFieldName
|
||||
|
@ -82,23 +93,23 @@ public class CommonTermsQueryParser implements QueryParser<CommonTermsQueryBuild
|
|||
throw new ParsingException(parser.getTokenLocation(), "[" + CommonTermsQueryBuilder.NAME + "] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("query".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) {
|
||||
text = parser.objectText();
|
||||
} else if ("analyzer".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, ANALYZER_FIELD)) {
|
||||
analyzer = parser.text();
|
||||
} else if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, DISABLE_COORD_FIELD)) {
|
||||
disableCoord = parser.booleanValue();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("high_freq_operator".equals(currentFieldName) || "highFreqOperator".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, HIGH_FREQ_OPERATOR_FIELD)) {
|
||||
highFreqOperator = Operator.fromString(parser.text());
|
||||
} else if ("low_freq_operator".equals(currentFieldName) || "lowFreqOperator".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, LOW_FREQ_OPERATOR_FIELD)) {
|
||||
lowFreqOperator = Operator.fromString(parser.text());
|
||||
} else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, MINIMUM_SHOULD_MATCH_FIELD)) {
|
||||
lowFreqMinimumShouldMatch = parser.text();
|
||||
} else if ("cutoff_frequency".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, CUTOFF_FREQUENCY_FIELD)) {
|
||||
cutoffFrequency = parser.floatValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + CommonTermsQueryBuilder.NAME + "] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -63,7 +63,7 @@ public class ConstantScoreQueryBuilder extends AbstractQueryBuilder<ConstantScor
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("filter");
|
||||
builder.field(ConstantScoreQueryParser.INNER_QUERY_FIELD.getPreferredName());
|
||||
filterBuilder.toXContent(builder, params);
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.io.IOException;
|
|||
*/
|
||||
public class ConstantScoreQueryParser implements QueryParser<ConstantScoreQueryBuilder> {
|
||||
|
||||
private static final ParseField INNER_QUERY_FIELD = new ParseField("filter", "query");
|
||||
public static final ParseField INNER_QUERY_FIELD = new ParseField("filter", "query");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
@ -62,9 +62,9 @@ public class ConstantScoreQueryParser implements QueryParser<ConstantScoreQueryB
|
|||
throw new ParsingException(parser.getTokenLocation(), "[constant_score] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("_name".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[constant_score] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -88,8 +88,8 @@ public class DisMaxQueryBuilder extends AbstractQueryBuilder<DisMaxQueryBuilder>
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("tie_breaker", tieBreaker);
|
||||
builder.startArray("queries");
|
||||
builder.field(DisMaxQueryParser.TIE_BREAKER_FIELD.getPreferredName(), tieBreaker);
|
||||
builder.startArray(DisMaxQueryParser.QUERIES_FIELD.getPreferredName());
|
||||
for (QueryBuilder queryBuilder : queries) {
|
||||
queryBuilder.toXContent(builder, params);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -32,6 +33,9 @@ import java.util.List;
|
|||
*/
|
||||
public class DisMaxQueryParser implements QueryParser<DisMaxQueryBuilder> {
|
||||
|
||||
public static final ParseField TIE_BREAKER_FIELD = new ParseField("tie_breaker");
|
||||
public static final ParseField QUERIES_FIELD = new ParseField("queries");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{DisMaxQueryBuilder.NAME, Strings.toCamelCase(DisMaxQueryBuilder.NAME)};
|
||||
|
@ -54,7 +58,7 @@ public class DisMaxQueryParser implements QueryParser<DisMaxQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if ("queries".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, QUERIES_FIELD)) {
|
||||
queriesFound = true;
|
||||
QueryBuilder query = parseContext.parseInnerQueryBuilder();
|
||||
queries.add(query);
|
||||
|
@ -62,7 +66,7 @@ public class DisMaxQueryParser implements QueryParser<DisMaxQueryBuilder> {
|
|||
throw new ParsingException(parser.getTokenLocation(), "[dis_max] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
if ("queries".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, QUERIES_FIELD)) {
|
||||
queriesFound = true;
|
||||
while (token != XContentParser.Token.END_ARRAY) {
|
||||
QueryBuilder query = parseContext.parseInnerQueryBuilder();
|
||||
|
@ -73,11 +77,11 @@ public class DisMaxQueryParser implements QueryParser<DisMaxQueryBuilder> {
|
|||
throw new ParsingException(parser.getTokenLocation(), "[dis_max] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else {
|
||||
if ("boost".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("tie_breaker".equals(currentFieldName) || "tieBreaker".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, TIE_BREAKER_FIELD)) {
|
||||
tieBreaker = parser.floatValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[dis_max] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -61,7 +61,7 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder<ExistsQueryBuilder>
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("field", fieldName);
|
||||
builder.field(ExistsQueryParser.FIELD_FIELD.getPreferredName(), fieldName);
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
|
@ -29,6 +30,8 @@ import java.io.IOException;
|
|||
*/
|
||||
public class ExistsQueryParser implements QueryParser<ExistsQueryBuilder> {
|
||||
|
||||
public static final ParseField FIELD_FIELD = new ParseField("field");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{ExistsQueryBuilder.NAME};
|
||||
|
@ -48,11 +51,11 @@ public class ExistsQueryParser implements QueryParser<ExistsQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token.isValue()) {
|
||||
if ("field".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, FIELD_FIELD)) {
|
||||
fieldPattern = parser.text();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + ExistsQueryBuilder.NAME + "] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -75,9 +75,9 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("query");
|
||||
builder.field(FieldMaskingSpanQueryParser.QUERY_FIELD.getPreferredName());
|
||||
queryBuilder.toXContent(builder, params);
|
||||
builder.field("field", fieldName);
|
||||
builder.field(FieldMaskingSpanQueryParser.FIELD_FIELD.getPreferredName(), fieldName);
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -29,6 +30,9 @@ import java.io.IOException;
|
|||
*/
|
||||
public class FieldMaskingSpanQueryParser implements QueryParser<FieldMaskingSpanQueryBuilder> {
|
||||
|
||||
public static final ParseField FIELD_FIELD = new ParseField("field");
|
||||
public static final ParseField QUERY_FIELD = new ParseField("query");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{FieldMaskingSpanQueryBuilder.NAME, Strings.toCamelCase(FieldMaskingSpanQueryBuilder.NAME)};
|
||||
|
@ -50,7 +54,7 @@ public class FieldMaskingSpanQueryParser implements QueryParser<FieldMaskingSpan
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if ("query".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) {
|
||||
QueryBuilder query = parseContext.parseInnerQueryBuilder();
|
||||
if (!(query instanceof SpanQueryBuilder)) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[field_masking_span] query must be of type span query");
|
||||
|
@ -61,11 +65,11 @@ public class FieldMaskingSpanQueryParser implements QueryParser<FieldMaskingSpan
|
|||
+ currentFieldName + "]");
|
||||
}
|
||||
} else {
|
||||
if ("boost".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("field".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FIELD_FIELD)) {
|
||||
field = parser.text();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[field_masking_span] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -209,16 +209,16 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.startObject(fieldName);
|
||||
builder.field("value", convertToStringIfBytesRef(this.value));
|
||||
builder.field(FuzzyQueryParser.VALUE_FIELD.getPreferredName(), convertToStringIfBytesRef(this.value));
|
||||
fuzziness.toXContent(builder, params);
|
||||
builder.field("prefix_length", prefixLength);
|
||||
builder.field("max_expansions", maxExpansions);
|
||||
builder.field("transpositions", transpositions);
|
||||
builder.field(FuzzyQueryParser.PREFIX_LENGTH_FIELD.getPreferredName(), prefixLength);
|
||||
builder.field(FuzzyQueryParser.MAX_EXPANSIONS_FIELD.getPreferredName(), maxExpansions);
|
||||
builder.field(FuzzyQueryParser.TRANSPOSITIONS_FIELD.getPreferredName(), transpositions);
|
||||
if (rewrite != null) {
|
||||
builder.field("rewrite", rewrite);
|
||||
builder.field(FuzzyQueryParser.REWRITE_FIELD.getPreferredName(), rewrite);
|
||||
}
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
|
@ -231,7 +231,7 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public Query doToQuery(QueryShardContext context) throws IOException {
|
||||
protected Query doToQuery(QueryShardContext context) throws IOException {
|
||||
Query query = null;
|
||||
String rewrite = this.rewrite;
|
||||
if (rewrite == null && context.isFilter()) {
|
||||
|
@ -253,7 +253,7 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public FuzzyQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
protected FuzzyQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
FuzzyQueryBuilder fuzzyQueryBuilder = new FuzzyQueryBuilder(in.readString(), in.readGenericValue());
|
||||
fuzzyQueryBuilder.fuzziness = Fuzziness.readFuzzinessFrom(in);
|
||||
fuzzyQueryBuilder.prefixLength = in.readVInt();
|
||||
|
@ -264,7 +264,7 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doWriteTo(StreamOutput out) throws IOException {
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(this.fieldName);
|
||||
out.writeGenericValue(this.value);
|
||||
this.fuzziness.writeTo(out);
|
||||
|
@ -275,12 +275,12 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public int doHashCode() {
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(fieldName, value, fuzziness, prefixLength, maxExpansions, transpositions, rewrite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doEquals(FuzzyQueryBuilder other) {
|
||||
protected boolean doEquals(FuzzyQueryBuilder other) {
|
||||
return Objects.equals(fieldName, other.fieldName) &&
|
||||
Objects.equals(value, other.value) &&
|
||||
Objects.equals(fuzziness, other.fuzziness) &&
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.unit.Fuzziness;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -27,6 +28,13 @@ import java.io.IOException;
|
|||
|
||||
public class FuzzyQueryParser implements QueryParser<FuzzyQueryBuilder> {
|
||||
|
||||
public static final ParseField TERM_FIELD = new ParseField("term");
|
||||
public static final ParseField VALUE_FIELD = new ParseField("value");
|
||||
public static final ParseField PREFIX_LENGTH_FIELD = new ParseField("prefix_length");
|
||||
public static final ParseField MAX_EXPANSIONS_FIELD = new ParseField("max_expansions");
|
||||
public static final ParseField TRANSPOSITIONS_FIELD = new ParseField("transpositions");
|
||||
public static final ParseField REWRITE_FIELD = new ParseField("rewrite");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{ FuzzyQueryBuilder.NAME };
|
||||
|
@ -60,23 +68,23 @@ public class FuzzyQueryParser implements QueryParser<FuzzyQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else {
|
||||
if ("term".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, TERM_FIELD)) {
|
||||
value = parser.objectBytes();
|
||||
} else if ("value".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, VALUE_FIELD)) {
|
||||
value = parser.objectBytes();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, Fuzziness.FIELD)) {
|
||||
fuzziness = Fuzziness.parse(parser);
|
||||
} else if ("prefix_length".equals(currentFieldName) || "prefixLength".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, PREFIX_LENGTH_FIELD)) {
|
||||
prefixLength = parser.intValue();
|
||||
} else if ("max_expansions".equals(currentFieldName) || "maxExpansions".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, MAX_EXPANSIONS_FIELD)) {
|
||||
maxExpansions = parser.intValue();
|
||||
} else if ("transpositions".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, TRANSPOSITIONS_FIELD)) {
|
||||
transpositions = parser.booleanValue();
|
||||
} else if ("rewrite".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) {
|
||||
rewrite = parser.textOrNull();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[fuzzy] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -292,11 +292,11 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
|
|||
builder.startObject(NAME);
|
||||
|
||||
builder.startObject(fieldName);
|
||||
builder.array(GeoBoundingBoxQueryParser.TOP_LEFT, topLeft.getLon(), topLeft.getLat());
|
||||
builder.array(GeoBoundingBoxQueryParser.BOTTOM_RIGHT, bottomRight.getLon(), bottomRight.getLat());
|
||||
builder.array(GeoBoundingBoxQueryParser.TOP_LEFT_FIELD.getPreferredName(), topLeft.getLon(), topLeft.getLat());
|
||||
builder.array(GeoBoundingBoxQueryParser.BOTTOM_RIGHT_FIELD.getPreferredName(), bottomRight.getLon(), bottomRight.getLat());
|
||||
builder.endObject();
|
||||
builder.field("validation_method", validationMethod);
|
||||
builder.field("type", type);
|
||||
builder.field(GeoBoundingBoxQueryParser.VALIDATION_METHOD_FIELD.getPreferredName(), validationMethod);
|
||||
builder.field(GeoBoundingBoxQueryParser.TYPE_FIELD.getPreferredName(), type);
|
||||
|
||||
printBoostAndQueryName(builder);
|
||||
|
||||
|
@ -304,7 +304,7 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean doEquals(GeoBoundingBoxQueryBuilder other) {
|
||||
protected boolean doEquals(GeoBoundingBoxQueryBuilder other) {
|
||||
return Objects.equals(topLeft, other.topLeft) &&
|
||||
Objects.equals(bottomRight, other.bottomRight) &&
|
||||
Objects.equals(type, other.type) &&
|
||||
|
@ -313,12 +313,12 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
|
|||
}
|
||||
|
||||
@Override
|
||||
public int doHashCode() {
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(topLeft, bottomRight, type, validationMethod, fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeoBoundingBoxQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
protected GeoBoundingBoxQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
String fieldName = in.readString();
|
||||
GeoBoundingBoxQueryBuilder geo = new GeoBoundingBoxQueryBuilder(fieldName);
|
||||
geo.topLeft = in.readGeoPoint();
|
||||
|
@ -329,7 +329,7 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doWriteTo(StreamOutput out) throws IOException {
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeGeoPoint(topLeft);
|
||||
out.writeGeoPoint(bottomRight);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.geo.GeoUtils;
|
||||
|
@ -31,34 +32,19 @@ public class GeoBoundingBoxQueryParser implements QueryParser<GeoBoundingBoxQuer
|
|||
|
||||
public static final String NAME = "geo_bbox";
|
||||
|
||||
/** Key to refer to the top of the bounding box. */
|
||||
public static final String TOP = "top";
|
||||
/** Key to refer to the left of the bounding box. */
|
||||
public static final String LEFT = "left";
|
||||
/** Key to refer to the right of the bounding box. */
|
||||
public static final String RIGHT = "right";
|
||||
/** Key to refer to the bottom of the bounding box. */
|
||||
public static final String BOTTOM = "bottom";
|
||||
|
||||
/** Key to refer to top_left corner of bounding box. */
|
||||
public static final String TOP_LEFT = TOP + "_" + LEFT;
|
||||
/** Key to refer to bottom_right corner of bounding box. */
|
||||
public static final String BOTTOM_RIGHT = BOTTOM + "_" + RIGHT;
|
||||
/** Key to refer to top_right corner of bounding box. */
|
||||
public static final String TOP_RIGHT = TOP + "_" + RIGHT;
|
||||
/** Key to refer to bottom left corner of bounding box. */
|
||||
public static final String BOTTOM_LEFT = BOTTOM + "_" + LEFT;
|
||||
|
||||
/** Key to refer to top_left corner of bounding box. */
|
||||
public static final String TOPLEFT = "topLeft";
|
||||
/** Key to refer to bottom_right corner of bounding box. */
|
||||
public static final String BOTTOMRIGHT = "bottomRight";
|
||||
/** Key to refer to top_right corner of bounding box. */
|
||||
public static final String TOPRIGHT = "topRight";
|
||||
/** Key to refer to bottom left corner of bounding box. */
|
||||
public static final String BOTTOMLEFT = "bottomLeft";
|
||||
|
||||
public static final String FIELD = "field";
|
||||
public static final ParseField IGNORE_MALFORMED_FIELD = new ParseField("ignore_malformed");
|
||||
public static final ParseField TYPE_FIELD = new ParseField("type");
|
||||
public static final ParseField VALIDATION_METHOD_FIELD = new ParseField("validation_method");
|
||||
public static final ParseField COERCE_FIELD = new ParseField("coerce", "normalize");
|
||||
public static final ParseField FIELD_FIELD = new ParseField("field");
|
||||
public static final ParseField TOP_FIELD = new ParseField("top");
|
||||
public static final ParseField BOTTOM_FIELD = new ParseField("bottom");
|
||||
public static final ParseField LEFT_FIELD = new ParseField("left");
|
||||
public static final ParseField RIGHT_FIELD = new ParseField("right");
|
||||
public static final ParseField TOP_LEFT_FIELD = new ParseField("top_left");
|
||||
public static final ParseField BOTTOM_RIGHT_FIELD = new ParseField("bottom_right");
|
||||
public static final ParseField TOP_RIGHT_FIELD = new ParseField("top_right");
|
||||
public static final ParseField BOTTOM_LEFT_FIELD = new ParseField("bottom_left");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
@ -100,30 +86,30 @@ public class GeoBoundingBoxQueryParser implements QueryParser<GeoBoundingBoxQuer
|
|||
token = parser.nextToken();
|
||||
if (parseContext.isDeprecatedSetting(currentFieldName)) {
|
||||
// skip
|
||||
} else if (FIELD.equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FIELD_FIELD)) {
|
||||
fieldName = parser.text();
|
||||
} else if (TOP.equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, TOP_FIELD)) {
|
||||
top = parser.doubleValue();
|
||||
} else if (BOTTOM.equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, BOTTOM_FIELD)) {
|
||||
bottom = parser.doubleValue();
|
||||
} else if (LEFT.equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, LEFT_FIELD)) {
|
||||
left = parser.doubleValue();
|
||||
} else if (RIGHT.equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, RIGHT_FIELD)) {
|
||||
right = parser.doubleValue();
|
||||
} else {
|
||||
if (TOP_LEFT.equals(currentFieldName) || TOPLEFT.equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, TOP_LEFT_FIELD)) {
|
||||
GeoUtils.parseGeoPoint(parser, sparse);
|
||||
top = sparse.getLat();
|
||||
left = sparse.getLon();
|
||||
} else if (BOTTOM_RIGHT.equals(currentFieldName) || BOTTOMRIGHT.equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, BOTTOM_RIGHT_FIELD)) {
|
||||
GeoUtils.parseGeoPoint(parser, sparse);
|
||||
bottom = sparse.getLat();
|
||||
right = sparse.getLon();
|
||||
} else if (TOP_RIGHT.equals(currentFieldName) || TOPRIGHT.equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, TOP_RIGHT_FIELD)) {
|
||||
GeoUtils.parseGeoPoint(parser, sparse);
|
||||
top = sparse.getLat();
|
||||
right = sparse.getLon();
|
||||
} else if (BOTTOM_LEFT.equals(currentFieldName) || BOTTOMLEFT.equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, BOTTOM_LEFT_FIELD)) {
|
||||
GeoUtils.parseGeoPoint(parser, sparse);
|
||||
bottom = sparse.getLat();
|
||||
left = sparse.getLon();
|
||||
|
@ -136,20 +122,20 @@ public class GeoBoundingBoxQueryParser implements QueryParser<GeoBoundingBoxQuer
|
|||
}
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("_name".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("coerce".equals(currentFieldName) || ("normalize".equals(currentFieldName))) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, COERCE_FIELD)) {
|
||||
coerce = parser.booleanValue();
|
||||
if (coerce) {
|
||||
ignoreMalformed = true;
|
||||
}
|
||||
} else if ("validation_method".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, VALIDATION_METHOD_FIELD)) {
|
||||
validationMethod = GeoValidationMethod.fromString(parser.text());
|
||||
} else if ("type".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, TYPE_FIELD)) {
|
||||
type = parser.text();
|
||||
} else if ("ignore_malformed".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, IGNORE_MALFORMED_FIELD)) {
|
||||
ignoreMalformed = parser.booleanValue();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "failed to parse [{}] query. unexpected field [{}]", NAME, currentFieldName);
|
||||
|
|
|
@ -239,21 +239,21 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
|
|||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.startArray(fieldName).value(center.lon()).value(center.lat()).endArray();
|
||||
builder.field("distance", distance);
|
||||
builder.field("distance_type", geoDistance.name().toLowerCase(Locale.ROOT));
|
||||
builder.field("optimize_bbox", optimizeBbox);
|
||||
builder.field("validation_method", validationMethod);
|
||||
builder.field(GeoDistanceQueryParser.DISTANCE_FIELD.getPreferredName(), distance);
|
||||
builder.field(GeoDistanceQueryParser.DISTANCE_TYPE_FIELD.getPreferredName(), geoDistance.name().toLowerCase(Locale.ROOT));
|
||||
builder.field(GeoDistanceQueryParser.OPTIMIZE_BBOX_FIELD.getPreferredName(), optimizeBbox);
|
||||
builder.field(GeoDistanceQueryParser.VALIDATION_METHOD_FIELD.getPreferredName(), validationMethod);
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int doHashCode() {
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(center, geoDistance, optimizeBbox, distance, validationMethod);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doEquals(GeoDistanceQueryBuilder other) {
|
||||
protected boolean doEquals(GeoDistanceQueryBuilder other) {
|
||||
return Objects.equals(fieldName, other.fieldName) &&
|
||||
(distance == other.distance) &&
|
||||
Objects.equals(validationMethod, other.validationMethod) &&
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.geo.GeoDistance;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
|
@ -41,6 +42,14 @@ import java.io.IOException;
|
|||
*/
|
||||
public class GeoDistanceQueryParser implements QueryParser<GeoDistanceQueryBuilder> {
|
||||
|
||||
public static final ParseField VALIDATION_METHOD_FIELD = new ParseField("validation_method");
|
||||
public static final ParseField IGNORE_MALFORMED_FIELD = new ParseField("ignore_malformed");
|
||||
public static final ParseField COERCE_FIELD = new ParseField("coerce", "normalize");
|
||||
public static final ParseField OPTIMIZE_BBOX_FIELD = new ParseField("optimize_bbox");
|
||||
public static final ParseField DISTANCE_TYPE_FIELD = new ParseField("distance_type");
|
||||
public static final ParseField UNIT_FIELD = new ParseField("unit");
|
||||
public static final ParseField DISTANCE_FIELD = new ParseField("distance");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{GeoDistanceQueryBuilder.NAME, "geoDistance"};
|
||||
|
@ -95,15 +104,15 @@ public class GeoDistanceQueryParser implements QueryParser<GeoDistanceQueryBuild
|
|||
}
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("distance".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, DISTANCE_FIELD)) {
|
||||
if (token == XContentParser.Token.VALUE_STRING) {
|
||||
vDistance = parser.text(); // a String
|
||||
} else {
|
||||
vDistance = parser.numberValue(); // a Number
|
||||
}
|
||||
} else if ("unit".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, UNIT_FIELD)) {
|
||||
unit = DistanceUnit.fromString(parser.text());
|
||||
} else if ("distance_type".equals(currentFieldName) || "distanceType".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, DISTANCE_TYPE_FIELD)) {
|
||||
geoDistance = GeoDistance.fromString(parser.text());
|
||||
} else if (currentFieldName.endsWith(GeoPointFieldMapper.Names.LAT_SUFFIX)) {
|
||||
point.resetLat(parser.doubleValue());
|
||||
|
@ -114,20 +123,20 @@ public class GeoDistanceQueryParser implements QueryParser<GeoDistanceQueryBuild
|
|||
} else if (currentFieldName.endsWith(GeoPointFieldMapper.Names.GEOHASH_SUFFIX)) {
|
||||
point.resetFromGeoHash(parser.text());
|
||||
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.GEOHASH_SUFFIX.length());
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("optimize_bbox".equals(currentFieldName) || "optimizeBbox".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, OPTIMIZE_BBOX_FIELD)) {
|
||||
optimizeBbox = parser.textOrNull();
|
||||
} else if ("coerce".equals(currentFieldName) || ("normalize".equals(currentFieldName))) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, COERCE_FIELD)) {
|
||||
coerce = parser.booleanValue();
|
||||
if (coerce == true) {
|
||||
ignoreMalformed = true;
|
||||
}
|
||||
} else if ("ignore_malformed".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, IGNORE_MALFORMED_FIELD)) {
|
||||
ignoreMalformed = parser.booleanValue();
|
||||
} else if ("validation_method".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, VALIDATION_METHOD_FIELD)) {
|
||||
validationMethod = GeoValidationMethod.fromString(parser.text());
|
||||
} else {
|
||||
if (fieldName == null) {
|
||||
|
|
|
@ -185,12 +185,12 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("query");
|
||||
builder.field(HasChildQueryParser.QUERY_FIELD.getPreferredName());
|
||||
query.toXContent(builder, params);
|
||||
builder.field("child_type", type);
|
||||
builder.field("score_mode", scoreMode.name().toLowerCase(Locale.ROOT));
|
||||
builder.field("min_children", minChildren);
|
||||
builder.field("max_children", maxChildren);
|
||||
builder.field(HasChildQueryParser.TYPE_FIELD.getPreferredName(), type);
|
||||
builder.field(HasChildQueryParser.SCORE_MODE_FIELD.getPreferredName(), scoreMode.name().toLowerCase(Locale.ROOT));
|
||||
builder.field(HasChildQueryParser.MIN_CHILDREN_FIELD.getPreferredName(), minChildren);
|
||||
builder.field(HasChildQueryParser.MAX_CHILDREN_FIELD.getPreferredName(), maxChildren);
|
||||
printBoostAndQueryName(builder);
|
||||
if (queryInnerHits != null) {
|
||||
queryInnerHits.toXContent(builder, params);
|
||||
|
|
|
@ -33,7 +33,12 @@ import java.io.IOException;
|
|||
*/
|
||||
public class HasChildQueryParser implements QueryParser<HasChildQueryBuilder> {
|
||||
|
||||
private static final ParseField QUERY_FIELD = new ParseField("query", "filter");
|
||||
public static final ParseField QUERY_FIELD = new ParseField("query", "filter");
|
||||
public static final ParseField TYPE_FIELD = new ParseField("type", "child_type");
|
||||
public static final ParseField MAX_CHILDREN_FIELD = new ParseField("max_children");
|
||||
public static final ParseField MIN_CHILDREN_FIELD = new ParseField("min_children");
|
||||
public static final ParseField SCORE_MODE_FIELD = new ParseField("score_mode");
|
||||
public static final ParseField INNER_HITS_FIELD = new ParseField("inner_hits");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
@ -61,23 +66,23 @@ public class HasChildQueryParser implements QueryParser<HasChildQueryBuilder> {
|
|||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) {
|
||||
iqb = parseContext.parseInnerQueryBuilder();
|
||||
} else if ("inner_hits".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, INNER_HITS_FIELD)) {
|
||||
queryInnerHits = new QueryInnerHits(parser);
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[has_child] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("type".equals(currentFieldName) || "child_type".equals(currentFieldName) || "childType".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, TYPE_FIELD)) {
|
||||
childType = parser.text();
|
||||
} else if ("score_mode".equals(currentFieldName) || "scoreMode".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, SCORE_MODE_FIELD)) {
|
||||
scoreMode = parseScoreMode(parser.text());
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("min_children".equals(currentFieldName) || "minChildren".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, MIN_CHILDREN_FIELD)) {
|
||||
minChildren = parser.intValue(true);
|
||||
} else if ("max_children".equals(currentFieldName) || "maxChildren".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, MAX_CHILDREN_FIELD)) {
|
||||
maxChildren = parser.intValue(true);
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[has_child] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -199,10 +199,10 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("query");
|
||||
builder.field(HasParentQueryParser.QUERY_FIELD.getPreferredName());
|
||||
query.toXContent(builder, params);
|
||||
builder.field("parent_type", type);
|
||||
builder.field("score", score);
|
||||
builder.field(HasParentQueryParser.TYPE_FIELD.getPreferredName(), type);
|
||||
builder.field(HasParentQueryParser.SCORE_FIELD.getPreferredName(), score);
|
||||
printBoostAndQueryName(builder);
|
||||
if (innerHit != null) {
|
||||
innerHit.toXContent(builder, params);
|
||||
|
|
|
@ -30,9 +30,11 @@ import java.io.IOException;
|
|||
public class HasParentQueryParser implements QueryParser<HasParentQueryBuilder> {
|
||||
|
||||
private static final HasParentQueryBuilder PROTOTYPE = new HasParentQueryBuilder("", EmptyQueryBuilder.PROTOTYPE);
|
||||
private static final ParseField QUERY_FIELD = new ParseField("query", "filter");
|
||||
private static final ParseField SCORE_FIELD = new ParseField("score_mode").withAllDeprecated("score");
|
||||
private static final ParseField TYPE_FIELD = new ParseField("parent_type", "type");
|
||||
public static final ParseField QUERY_FIELD = new ParseField("query", "filter");
|
||||
//public static final ParseField SCORE_MODE_FIELD = new ParseField("score_mode").withAllDeprecated("score");
|
||||
public static final ParseField SCORE_MODE_FIELD = new ParseField("score_mode").withAllDeprecated("score");
|
||||
public static final ParseField TYPE_FIELD = new ParseField("parent_type", "type");
|
||||
public static final ParseField SCORE_FIELD = new ParseField("score");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
@ -42,7 +44,6 @@ public class HasParentQueryParser implements QueryParser<HasParentQueryBuilder>
|
|||
@Override
|
||||
public HasParentQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
|
||||
XContentParser parser = parseContext.parser();
|
||||
|
||||
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||
String parentType = null;
|
||||
boolean score = HasParentQueryBuilder.DEFAULT_SCORE;
|
||||
|
@ -66,7 +67,7 @@ public class HasParentQueryParser implements QueryParser<HasParentQueryBuilder>
|
|||
} else if (token.isValue()) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, TYPE_FIELD)) {
|
||||
parentType = parser.text();
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, SCORE_FIELD)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, SCORE_MODE_FIELD)) {
|
||||
String scoreModeValue = parser.text();
|
||||
if ("score".equals(scoreModeValue)) {
|
||||
score = true;
|
||||
|
@ -75,11 +76,11 @@ public class HasParentQueryParser implements QueryParser<HasParentQueryBuilder>
|
|||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[has_parent] query does not support [" + scoreModeValue + "] as an option for score_mode");
|
||||
}
|
||||
} else if ("score".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, SCORE_FIELD)) {
|
||||
score = parser.booleanValue();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[has_parent] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -90,8 +90,8 @@ public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> {
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.array("types", types);
|
||||
builder.startArray("values");
|
||||
builder.array(IdsQueryParser.TYPE_FIELD.getPreferredName(), types);
|
||||
builder.startArray(IdsQueryParser.VALUES_FIELD.getPreferredName());
|
||||
for (String value : ids) {
|
||||
builder.value(value);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
|
@ -32,6 +33,10 @@ import java.util.List;
|
|||
*/
|
||||
public class IdsQueryParser implements QueryParser<IdsQueryBuilder> {
|
||||
|
||||
public static final ParseField TYPE_FIELD = new ParseField("type", "types", "_type");
|
||||
|
||||
public static final ParseField VALUES_FIELD = new ParseField("values");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{IdsQueryBuilder.NAME};
|
||||
|
@ -55,7 +60,7 @@ public class IdsQueryParser implements QueryParser<IdsQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
if ("values".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, VALUES_FIELD)) {
|
||||
idsProvided = true;
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
if ((token == XContentParser.Token.VALUE_STRING) ||
|
||||
|
@ -70,7 +75,7 @@ public class IdsQueryParser implements QueryParser<IdsQueryBuilder> {
|
|||
+ token);
|
||||
}
|
||||
}
|
||||
} else if ("types".equals(currentFieldName) || "type".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, TYPE_FIELD)) {
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
String value = parser.textOrNull();
|
||||
if (value == null) {
|
||||
|
@ -82,11 +87,11 @@ public class IdsQueryParser implements QueryParser<IdsQueryBuilder> {
|
|||
throw new ParsingException(parser.getTokenLocation(), "[" + IdsQueryBuilder.NAME + "] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("type".equals(currentFieldName) || "_type".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, TYPE_FIELD)) {
|
||||
types = Collections.singletonList(parser.text());
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + IdsQueryBuilder.NAME + "] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -93,10 +93,10 @@ public class IndicesQueryBuilder extends AbstractQueryBuilder<IndicesQueryBuilde
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("indices", indices);
|
||||
builder.field("query");
|
||||
builder.field(IndicesQueryParser.INDICES_FIELD.getPreferredName(), indices);
|
||||
builder.field(IndicesQueryParser.QUERY_FIELD.getPreferredName());
|
||||
innerQuery.toXContent(builder, params);
|
||||
builder.field("no_match_query");
|
||||
builder.field(IndicesQueryParser.NO_MATCH_QUERY.getPreferredName());
|
||||
noMatchQuery.toXContent(builder, params);
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
|
|
|
@ -32,8 +32,11 @@ import java.util.Collection;
|
|||
*/
|
||||
public class IndicesQueryParser implements QueryParser {
|
||||
|
||||
private static final ParseField QUERY_FIELD = new ParseField("query");
|
||||
private static final ParseField NO_MATCH_QUERY = new ParseField("no_match_query");
|
||||
public static final ParseField QUERY_FIELD = new ParseField("query");
|
||||
public static final ParseField NO_MATCH_QUERY = new ParseField("no_match_query");
|
||||
public static final ParseField INDEX_FIELD = new ParseField("index");
|
||||
public static final ParseField INDICES_FIELD = new ParseField("indices");
|
||||
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
@ -65,7 +68,7 @@ public class IndicesQueryParser implements QueryParser {
|
|||
throw new ParsingException(parser.getTokenLocation(), "[indices] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
if ("indices".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, INDICES_FIELD)) {
|
||||
if (indices.isEmpty() == false) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[indices] indices or index already specified");
|
||||
}
|
||||
|
@ -80,16 +83,16 @@ public class IndicesQueryParser implements QueryParser {
|
|||
throw new ParsingException(parser.getTokenLocation(), "[indices] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("index".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, INDEX_FIELD)) {
|
||||
if (indices.isEmpty() == false) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[indices] indices or index already specified");
|
||||
}
|
||||
indices.add(parser.text());
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, NO_MATCH_QUERY)) {
|
||||
noMatchQuery = parseNoMatchQuery(parser.text());
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[indices] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -47,9 +47,9 @@ public class MatchAllQueryParser implements QueryParser<MatchAllQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token.isValue()) {
|
||||
if ("_name".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + MatchAllQueryBuilder.NAME + "] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -44,9 +44,9 @@ public class MatchNoneQueryParser implements QueryParser<MatchNoneQueryBuilder>
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token.isValue()) {
|
||||
if ("_name".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "["+MatchNoneQueryBuilder.NAME+"] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -129,6 +129,11 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
return this;
|
||||
}
|
||||
|
||||
/** Returns the operator to use in a boolean query.*/
|
||||
public Operator operator() {
|
||||
return this.operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicitly set the analyzer to use. Defaults to use explicit mapping config for the field, or, if not
|
||||
* set, the default search analyzer.
|
||||
|
@ -312,30 +317,30 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
|||
builder.startObject(NAME);
|
||||
builder.startObject(fieldName);
|
||||
|
||||
builder.field("query", value);
|
||||
builder.field("type", type.toString().toLowerCase(Locale.ENGLISH));
|
||||
builder.field("operator", operator.toString());
|
||||
builder.field(MatchQueryParser.QUERY_FIELD.getPreferredName(), value);
|
||||
builder.field(MatchQueryParser.TYPE_FIELD.getPreferredName(), type.toString().toLowerCase(Locale.ENGLISH));
|
||||
builder.field(MatchQueryParser.OPERATOR_FIELD.getPreferredName(), operator.toString());
|
||||
if (analyzer != null) {
|
||||
builder.field("analyzer", analyzer);
|
||||
builder.field(MatchQueryParser.ANALYZER_FIELD.getPreferredName(), analyzer);
|
||||
}
|
||||
builder.field("slop", slop);
|
||||
builder.field(MatchQueryParser.SLOP_FIELD.getPreferredName(), slop);
|
||||
if (fuzziness != null) {
|
||||
fuzziness.toXContent(builder, params);
|
||||
}
|
||||
builder.field("prefix_length", prefixLength);
|
||||
builder.field("max_expansions", maxExpansions);
|
||||
builder.field(MatchQueryParser.PREFIX_LENGTH_FIELD.getPreferredName(), prefixLength);
|
||||
builder.field(MatchQueryParser.MAX_EXPANSIONS_FIELD.getPreferredName(), maxExpansions);
|
||||
if (minimumShouldMatch != null) {
|
||||
builder.field("minimum_should_match", minimumShouldMatch);
|
||||
builder.field(MatchQueryParser.MINIMUM_SHOULD_MATCH_FIELD.getPreferredName(), minimumShouldMatch);
|
||||
}
|
||||
if (fuzzyRewrite != null) {
|
||||
builder.field("fuzzy_rewrite", fuzzyRewrite);
|
||||
builder.field(MatchQueryParser.FUZZY_REWRITE_FIELD.getPreferredName(), fuzzyRewrite);
|
||||
}
|
||||
// LUCENE 4 UPGRADE we need to document this & test this
|
||||
builder.field("fuzzy_transpositions", fuzzyTranspositions);
|
||||
builder.field("lenient", lenient);
|
||||
builder.field("zero_terms_query", zeroTermsQuery.toString());
|
||||
builder.field(MatchQueryParser.FUZZY_TRANSPOSITIONS_FIELD.getPreferredName(), fuzzyTranspositions);
|
||||
builder.field(MatchQueryParser.LENIENT_FIELD.getPreferredName(), lenient);
|
||||
builder.field(MatchQueryParser.ZERO_TERMS_QUERY_FIELD.getPreferredName(), zeroTermsQuery.toString());
|
||||
if (cutoffFrequency != null) {
|
||||
builder.field("cutoff_frequency", cutoffFrequency);
|
||||
builder.field(MatchQueryParser.CUTOFF_FREQUENCY_FIELD.getPreferredName(), cutoffFrequency);
|
||||
}
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.apache.lucene.search.FuzzyQuery;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.unit.Fuzziness;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -33,6 +34,22 @@ import java.io.IOException;
|
|||
*/
|
||||
public class MatchQueryParser implements QueryParser<MatchQueryBuilder> {
|
||||
|
||||
public static final ParseField MATCH_PHRASE_FIELD = new ParseField("match_phrase", "text_phrase");
|
||||
public static final ParseField MATCH_PHRASE_PREFIX_FIELD = new ParseField("match_phrase_prefix", "text_phrase_prefix");
|
||||
public static final ParseField SLOP_FIELD = new ParseField("slop", "phrase_slop");
|
||||
public static final ParseField ZERO_TERMS_QUERY_FIELD = new ParseField("zero_terms_query");
|
||||
public static final ParseField CUTOFF_FREQUENCY_FIELD = new ParseField("cutoff_frequency");
|
||||
public static final ParseField LENIENT_FIELD = new ParseField("lenient");
|
||||
public static final ParseField FUZZY_TRANSPOSITIONS_FIELD = new ParseField("fuzzy_transpositions");
|
||||
public static final ParseField FUZZY_REWRITE_FIELD = new ParseField("fuzzy_rewrite");
|
||||
public static final ParseField MINIMUM_SHOULD_MATCH_FIELD = new ParseField("minimum_should_match");
|
||||
public static final ParseField OPERATOR_FIELD = new ParseField("operator");
|
||||
public static final ParseField MAX_EXPANSIONS_FIELD = new ParseField("max_expansions");
|
||||
public static final ParseField PREFIX_LENGTH_FIELD = new ParseField("prefix_length");
|
||||
public static final ParseField ANALYZER_FIELD = new ParseField("analyzer");
|
||||
public static final ParseField TYPE_FIELD = new ParseField("type");
|
||||
public static final ParseField QUERY_FIELD = new ParseField("query");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{
|
||||
|
@ -45,11 +62,9 @@ public class MatchQueryParser implements QueryParser<MatchQueryBuilder> {
|
|||
XContentParser parser = parseContext.parser();
|
||||
|
||||
MatchQuery.Type type = MatchQuery.Type.BOOLEAN;
|
||||
if ("match_phrase".equals(parser.currentName()) || "matchPhrase".equals(parser.currentName()) ||
|
||||
"text_phrase".equals(parser.currentName()) || "textPhrase".equals(parser.currentName())) {
|
||||
if (parseContext.parseFieldMatcher().match(parser.currentName(), MATCH_PHRASE_FIELD)) {
|
||||
type = MatchQuery.Type.PHRASE;
|
||||
} else if ("match_phrase_prefix".equals(parser.currentName()) || "matchPhrasePrefix".equals(parser.currentName()) ||
|
||||
"text_phrase_prefix".equals(parser.currentName()) || "textPhrasePrefix".equals(parser.currentName())) {
|
||||
} else if (parseContext.parseFieldMatcher().match(parser.currentName(), MATCH_PHRASE_PREFIX_FIELD)) {
|
||||
type = MatchQuery.Type.PHRASE_PREFIX;
|
||||
}
|
||||
|
||||
|
@ -82,44 +97,44 @@ public class MatchQueryParser implements QueryParser<MatchQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token.isValue()) {
|
||||
if ("query".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) {
|
||||
value = parser.objectText();
|
||||
} else if ("type".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, TYPE_FIELD)) {
|
||||
String tStr = parser.text();
|
||||
if ("boolean".equals(tStr)) {
|
||||
type = MatchQuery.Type.BOOLEAN;
|
||||
} else if ("phrase".equals(tStr)) {
|
||||
type = MatchQuery.Type.PHRASE;
|
||||
} else if ("phrase_prefix".equals(tStr) || "phrasePrefix".equals(currentFieldName)) {
|
||||
} else if ("phrase_prefix".equals(tStr) || ("phrasePrefix".equals(tStr))) {
|
||||
type = MatchQuery.Type.PHRASE_PREFIX;
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + MatchQueryBuilder.NAME + "] query does not support type " + tStr);
|
||||
}
|
||||
} else if ("analyzer".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, ANALYZER_FIELD)) {
|
||||
analyzer = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("slop".equals(currentFieldName) || "phrase_slop".equals(currentFieldName) || "phraseSlop".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, SLOP_FIELD)) {
|
||||
slop = parser.intValue();
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, Fuzziness.FIELD)) {
|
||||
fuzziness = Fuzziness.parse(parser);
|
||||
} else if ("prefix_length".equals(currentFieldName) || "prefixLength".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, PREFIX_LENGTH_FIELD)) {
|
||||
prefixLength = parser.intValue();
|
||||
} else if ("max_expansions".equals(currentFieldName) || "maxExpansions".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, MAX_EXPANSIONS_FIELD)) {
|
||||
maxExpansion = parser.intValue();
|
||||
} else if ("operator".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, OPERATOR_FIELD)) {
|
||||
operator = Operator.fromString(parser.text());
|
||||
} else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, MINIMUM_SHOULD_MATCH_FIELD)) {
|
||||
minimumShouldMatch = parser.textOrNull();
|
||||
} else if ("fuzzy_rewrite".equals(currentFieldName) || "fuzzyRewrite".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FUZZY_REWRITE_FIELD)) {
|
||||
fuzzyRewrite = parser.textOrNull();
|
||||
} else if ("fuzzy_transpositions".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FUZZY_TRANSPOSITIONS_FIELD)) {
|
||||
fuzzyTranspositions = parser.booleanValue();
|
||||
} else if ("lenient".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, LENIENT_FIELD)) {
|
||||
lenient = parser.booleanValue();
|
||||
} else if ("cutoff_frequency".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, CUTOFF_FREQUENCY_FIELD)) {
|
||||
cutOffFrequency = parser.floatValue();
|
||||
} else if ("zero_terms_query".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, ZERO_TERMS_QUERY_FIELD)) {
|
||||
String zeroTermsDocs = parser.text();
|
||||
if ("none".equalsIgnoreCase(zeroTermsDocs)) {
|
||||
zeroTermsQuery = MatchQuery.ZeroTermsQuery.NONE;
|
||||
|
@ -128,7 +143,7 @@ public class MatchQueryParser implements QueryParser<MatchQueryBuilder> {
|
|||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "Unsupported zero_terms_docs value [" + zeroTermsDocs + "]");
|
||||
}
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + MatchQueryBuilder.NAME + "] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -104,9 +104,9 @@ public class MissingQueryBuilder extends AbstractQueryBuilder<MissingQueryBuilde
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("field", fieldPattern);
|
||||
builder.field("null_value", nullValue);
|
||||
builder.field("existence", existence);
|
||||
builder.field(MissingQueryParser.FIELD_FIELD.getPreferredName(), fieldPattern);
|
||||
builder.field(MissingQueryParser.NULL_VALUE_FIELD.getPreferredName(), nullValue);
|
||||
builder.field(MissingQueryParser.EXISTENCE_FIELD.getPreferredName(), existence);
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
|
@ -29,6 +30,10 @@ import java.io.IOException;
|
|||
*/
|
||||
public class MissingQueryParser implements QueryParser<MissingQueryBuilder> {
|
||||
|
||||
public static final ParseField FIELD_FIELD = new ParseField("field");
|
||||
public static final ParseField NULL_VALUE_FIELD = new ParseField("null_value");
|
||||
public static final ParseField EXISTENCE_FIELD = new ParseField("existence");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{MissingQueryBuilder.NAME};
|
||||
|
@ -50,15 +55,15 @@ public class MissingQueryParser implements QueryParser<MissingQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token.isValue()) {
|
||||
if ("field".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, FIELD_FIELD)) {
|
||||
fieldPattern = parser.text();
|
||||
} else if ("null_value".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, NULL_VALUE_FIELD)) {
|
||||
nullValue = parser.booleanValue();
|
||||
} else if ("existence".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, EXISTENCE_FIELD)) {
|
||||
existence = parser.booleanValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + MissingQueryBuilder.NAME + "] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -457,40 +457,40 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
|
|||
@Override
|
||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("query", value);
|
||||
builder.startArray("fields");
|
||||
builder.field(MultiMatchQueryParser.QUERY_FIELD.getPreferredName(), value);
|
||||
builder.startArray(MultiMatchQueryParser.FIELDS_FIELD.getPreferredName());
|
||||
for (Map.Entry<String, Float> fieldEntry : this.fieldsBoosts.entrySet()) {
|
||||
builder.value(fieldEntry.getKey() + "^" + fieldEntry.getValue());
|
||||
}
|
||||
builder.endArray();
|
||||
builder.field("type", type.toString().toLowerCase(Locale.ENGLISH));
|
||||
builder.field("operator", operator.toString());
|
||||
builder.field(MultiMatchQueryParser.TYPE_FIELD.getPreferredName(), type.toString().toLowerCase(Locale.ENGLISH));
|
||||
builder.field(MultiMatchQueryParser.OPERATOR_FIELD.getPreferredName(), operator.toString());
|
||||
if (analyzer != null) {
|
||||
builder.field("analyzer", analyzer);
|
||||
builder.field(MultiMatchQueryParser.ANALYZER_FIELD.getPreferredName(), analyzer);
|
||||
}
|
||||
builder.field("slop", slop);
|
||||
builder.field(MultiMatchQueryParser.SLOP_FIELD.getPreferredName(), slop);
|
||||
if (fuzziness != null) {
|
||||
fuzziness.toXContent(builder, params);
|
||||
}
|
||||
builder.field("prefix_length", prefixLength);
|
||||
builder.field("max_expansions", maxExpansions);
|
||||
builder.field(MultiMatchQueryParser.PREFIX_LENGTH_FIELD.getPreferredName(), prefixLength);
|
||||
builder.field(MultiMatchQueryParser.MAX_EXPANSIONS_FIELD.getPreferredName(), maxExpansions);
|
||||
if (minimumShouldMatch != null) {
|
||||
builder.field("minimum_should_match", minimumShouldMatch);
|
||||
builder.field(MultiMatchQueryParser.MINIMUM_SHOULD_MATCH_FIELD.getPreferredName(), minimumShouldMatch);
|
||||
}
|
||||
if (fuzzyRewrite != null) {
|
||||
builder.field("fuzzy_rewrite", fuzzyRewrite);
|
||||
builder.field(MultiMatchQueryParser.FUZZY_REWRITE_FIELD.getPreferredName(), fuzzyRewrite);
|
||||
}
|
||||
if (useDisMax != null) {
|
||||
builder.field("use_dis_max", useDisMax);
|
||||
builder.field(MultiMatchQueryParser.USE_DIS_MAX_FIELD.getPreferredName(), useDisMax);
|
||||
}
|
||||
if (tieBreaker != null) {
|
||||
builder.field("tie_breaker", tieBreaker);
|
||||
builder.field(MultiMatchQueryParser.TIE_BREAKER_FIELD.getPreferredName(), tieBreaker);
|
||||
}
|
||||
builder.field("lenient", lenient);
|
||||
builder.field(MultiMatchQueryParser.LENIENT_FIELD.getPreferredName(), lenient);
|
||||
if (cutoffFrequency != null) {
|
||||
builder.field("cutoff_frequency", cutoffFrequency);
|
||||
builder.field(MultiMatchQueryParser.CUTOFF_FREQUENCY_FIELD.getPreferredName(), cutoffFrequency);
|
||||
}
|
||||
builder.field("zero_terms_query", zeroTermsQuery.toString());
|
||||
builder.field(MultiMatchQueryParser.ZERO_TERMS_QUERY_FIELD.getPreferredName(), zeroTermsQuery.toString());
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
}
|
||||
|
|
|
@ -19,9 +19,11 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.unit.Fuzziness;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.query.MoreLikeThisQueryParser.Field;
|
||||
import org.elasticsearch.index.search.MatchQuery;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -33,6 +35,22 @@ import java.util.Map;
|
|||
*/
|
||||
public class MultiMatchQueryParser implements QueryParser<MultiMatchQueryBuilder> {
|
||||
|
||||
public static final ParseField SLOP_FIELD = new ParseField("slop", "phrase_slop");
|
||||
public static final ParseField ZERO_TERMS_QUERY_FIELD = new ParseField("zero_terms_query");
|
||||
public static final ParseField LENIENT_FIELD = new ParseField("lenient");
|
||||
public static final ParseField CUTOFF_FREQUENCY_FIELD = new ParseField("cutoff_frequency");
|
||||
public static final ParseField TIE_BREAKER_FIELD = new ParseField("tie_breaker");
|
||||
public static final ParseField USE_DIS_MAX_FIELD = new ParseField("use_dis_max");
|
||||
public static final ParseField FUZZY_REWRITE_FIELD = new ParseField("fuzzy_rewrite");
|
||||
public static final ParseField MINIMUM_SHOULD_MATCH_FIELD = new ParseField("minimum_should_match");
|
||||
public static final ParseField OPERATOR_FIELD = new ParseField("operator");
|
||||
public static final ParseField MAX_EXPANSIONS_FIELD = new ParseField("max_expansions");
|
||||
public static final ParseField PREFIX_LENGTH_FIELD = new ParseField("prefix_length");
|
||||
public static final ParseField ANALYZER_FIELD = new ParseField("analyzer");
|
||||
public static final ParseField TYPE_FIELD = new ParseField("type");
|
||||
public static final ParseField QUERY_FIELD = new ParseField("query");
|
||||
public static final ParseField FIELDS_FIELD = new ParseField("fields");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{
|
||||
|
@ -69,7 +87,7 @@ public class MultiMatchQueryParser implements QueryParser<MultiMatchQueryBuilder
|
|||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if ("fields".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) {
|
||||
if (token == XContentParser.Token.START_ARRAY) {
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
parseFieldAndBoost(parser, fieldsBoosts);
|
||||
|
@ -80,37 +98,37 @@ public class MultiMatchQueryParser implements QueryParser<MultiMatchQueryBuilder
|
|||
throw new ParsingException(parser.getTokenLocation(), "[" + MultiMatchQueryBuilder.NAME + "] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("query".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) {
|
||||
value = parser.objectText();
|
||||
} else if ("type".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, TYPE_FIELD)) {
|
||||
type = MultiMatchQueryBuilder.Type.parse(parser.text(), parseContext.parseFieldMatcher());
|
||||
} else if ("analyzer".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, ANALYZER_FIELD)) {
|
||||
analyzer = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("slop".equals(currentFieldName) || "phrase_slop".equals(currentFieldName) || "phraseSlop".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, SLOP_FIELD)) {
|
||||
slop = parser.intValue();
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, Fuzziness.FIELD)) {
|
||||
fuzziness = Fuzziness.parse(parser);
|
||||
} else if ("prefix_length".equals(currentFieldName) || "prefixLength".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, PREFIX_LENGTH_FIELD)) {
|
||||
prefixLength = parser.intValue();
|
||||
} else if ("max_expansions".equals(currentFieldName) || "maxExpansions".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, MAX_EXPANSIONS_FIELD)) {
|
||||
maxExpansions = parser.intValue();
|
||||
} else if ("operator".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, OPERATOR_FIELD)) {
|
||||
operator = Operator.fromString(parser.text());
|
||||
} else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, MINIMUM_SHOULD_MATCH_FIELD)) {
|
||||
minimumShouldMatch = parser.textOrNull();
|
||||
} else if ("fuzzy_rewrite".equals(currentFieldName) || "fuzzyRewrite".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FUZZY_REWRITE_FIELD)) {
|
||||
fuzzyRewrite = parser.textOrNull();
|
||||
} else if ("use_dis_max".equals(currentFieldName) || "useDisMax".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, USE_DIS_MAX_FIELD)) {
|
||||
useDisMax = parser.booleanValue();
|
||||
} else if ("tie_breaker".equals(currentFieldName) || "tieBreaker".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, TIE_BREAKER_FIELD)) {
|
||||
tieBreaker = parser.floatValue();
|
||||
} else if ("cutoff_frequency".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, CUTOFF_FREQUENCY_FIELD)) {
|
||||
cutoffFrequency = parser.floatValue();
|
||||
} else if ("lenient".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, LENIENT_FIELD)) {
|
||||
lenient = parser.booleanValue();
|
||||
} else if ("zero_terms_query".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, ZERO_TERMS_QUERY_FIELD)) {
|
||||
String zeroTermsDocs = parser.text();
|
||||
if ("none".equalsIgnoreCase(zeroTermsDocs)) {
|
||||
zeroTermsQuery = MatchQuery.ZeroTermsQuery.NONE;
|
||||
|
@ -119,7 +137,7 @@ public class MultiMatchQueryParser implements QueryParser<MultiMatchQueryBuilder
|
|||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "Unsupported zero_terms_docs value [" + zeroTermsDocs + "]");
|
||||
}
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + MultiMatchQueryBuilder.NAME + "] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -117,11 +117,11 @@ public class NestedQueryBuilder extends AbstractQueryBuilder<NestedQueryBuilder>
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("query");
|
||||
builder.field(NestedQueryParser.QUERY_FIELD.getPreferredName());
|
||||
query.toXContent(builder, params);
|
||||
builder.field("path", path);
|
||||
builder.field(NestedQueryParser.PATH_FIELD.getPreferredName(), path);
|
||||
if (scoreMode != null) {
|
||||
builder.field("score_mode", scoreMode.name().toLowerCase(Locale.ROOT));
|
||||
builder.field(NestedQueryParser.SCORE_MODE_FIELD.getPreferredName(), scoreMode.name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
printBoostAndQueryName(builder);
|
||||
if (queryInnerHits != null) {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -30,6 +31,10 @@ import java.io.IOException;
|
|||
public class NestedQueryParser implements QueryParser<NestedQueryBuilder> {
|
||||
|
||||
private static final NestedQueryBuilder PROTOTYPE = new NestedQueryBuilder("", EmptyQueryBuilder.PROTOTYPE);
|
||||
public static final ParseField SCORE_MODE_FIELD = new ParseField("score_mode");
|
||||
public static final ParseField PATH_FIELD = new ParseField("path");
|
||||
public static final ParseField QUERY_FIELD = new ParseField("query");
|
||||
public static final ParseField INNER_HITS_FIELD = new ParseField("inner_hits");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
@ -51,19 +56,19 @@ public class NestedQueryParser implements QueryParser<NestedQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if ("query".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) {
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
} else if ("inner_hits".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, INNER_HITS_FIELD)) {
|
||||
queryInnerHits = new QueryInnerHits(parser);
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[nested] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("path".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, PATH_FIELD)) {
|
||||
path = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("score_mode".equals(currentFieldName) || "scoreMode".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, SCORE_MODE_FIELD)) {
|
||||
String sScoreMode = parser.text();
|
||||
if ("avg".equals(sScoreMode)) {
|
||||
scoreMode = ScoreMode.Avg;
|
||||
|
@ -78,7 +83,7 @@ public class NestedQueryParser implements QueryParser<NestedQueryBuilder> {
|
|||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "illegal score_mode for nested query [" + sScoreMode + "]");
|
||||
}
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[nested] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -87,9 +87,9 @@ public class PrefixQueryBuilder extends AbstractQueryBuilder<PrefixQueryBuilder>
|
|||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.startObject(fieldName);
|
||||
builder.field("prefix", this.value);
|
||||
builder.field(PrefixQueryParser.PREFIX_FIELD.getPreferredName(), this.value);
|
||||
if (rewrite != null) {
|
||||
builder.field("rewrite", rewrite);
|
||||
builder.field(PrefixQueryParser.REWRITE_FIELD.getPreferredName(), rewrite);
|
||||
}
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
|
|
|
@ -30,7 +30,8 @@ import java.io.IOException;
|
|||
*/
|
||||
public class PrefixQueryParser implements QueryParser<PrefixQueryBuilder> {
|
||||
|
||||
private static final ParseField NAME_FIELD = new ParseField("_name").withAllDeprecated("query name is not supported in short version of prefix query");
|
||||
public static final ParseField PREFIX_FIELD = new ParseField("value", "prefix");
|
||||
public static final ParseField REWRITE_FIELD = new ParseField("rewrite");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
@ -60,13 +61,13 @@ public class PrefixQueryParser implements QueryParser<PrefixQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else {
|
||||
if ("_name".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if ("value".equals(currentFieldName) || "prefix".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, PREFIX_FIELD)) {
|
||||
value = parser.textOrNull();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("rewrite".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) {
|
||||
rewrite = parser.textOrNull();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[regexp] query does not support [" + currentFieldName + "]");
|
||||
|
@ -74,12 +75,8 @@ public class PrefixQueryParser implements QueryParser<PrefixQueryBuilder> {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
fieldName = currentFieldName;
|
||||
value = parser.textOrNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -468,58 +468,58 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQue
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("query", this.queryString);
|
||||
builder.field(QueryStringQueryParser.QUERY_FIELD.getPreferredName(), this.queryString);
|
||||
if (this.defaultField != null) {
|
||||
builder.field("default_field", this.defaultField);
|
||||
builder.field(QueryStringQueryParser.DEFAULT_FIELD_FIELD.getPreferredName(), this.defaultField);
|
||||
}
|
||||
builder.startArray("fields");
|
||||
builder.startArray(QueryStringQueryParser.FIELDS_FIELD.getPreferredName());
|
||||
for (Map.Entry<String, Float> fieldEntry : this.fieldsAndWeights.entrySet()) {
|
||||
builder.value(fieldEntry.getKey() + "^" + fieldEntry.getValue());
|
||||
}
|
||||
builder.endArray();
|
||||
builder.field("use_dis_max", this.useDisMax);
|
||||
builder.field("tie_breaker", this.tieBreaker);
|
||||
builder.field("default_operator", this.defaultOperator.name().toLowerCase(Locale.ROOT));
|
||||
builder.field(QueryStringQueryParser.USE_DIS_MAX_FIELD.getPreferredName(), this.useDisMax);
|
||||
builder.field(QueryStringQueryParser.TIE_BREAKER_FIELD.getPreferredName(), this.tieBreaker);
|
||||
builder.field(QueryStringQueryParser.DEFAULT_OPERATOR_FIELD.getPreferredName(), this.defaultOperator.name().toLowerCase(Locale.ROOT));
|
||||
if (this.analyzer != null) {
|
||||
builder.field("analyzer", this.analyzer);
|
||||
builder.field(QueryStringQueryParser.ANALYZER_FIELD.getPreferredName(), this.analyzer);
|
||||
}
|
||||
if (this.quoteAnalyzer != null) {
|
||||
builder.field("quote_analyzer", this.quoteAnalyzer);
|
||||
builder.field(QueryStringQueryParser.QUOTE_ANALYZER_FIELD.getPreferredName(), this.quoteAnalyzer);
|
||||
}
|
||||
builder.field("auto_generate_phrase_queries", this.autoGeneratePhraseQueries);
|
||||
builder.field("max_determinized_states", this.maxDeterminizedStates);
|
||||
builder.field(QueryStringQueryParser.AUTO_GENERATED_PHRASE_QUERIES_FIELD.getPreferredName(), this.autoGeneratePhraseQueries);
|
||||
builder.field(QueryStringQueryParser.MAX_DETERMINED_STATES_FIELD.getPreferredName(), this.maxDeterminizedStates);
|
||||
if (this.allowLeadingWildcard != null) {
|
||||
builder.field("allow_leading_wildcard", this.allowLeadingWildcard);
|
||||
builder.field(QueryStringQueryParser.ALLOW_LEADING_WILDCARD_FIELD.getPreferredName(), this.allowLeadingWildcard);
|
||||
}
|
||||
builder.field("lowercase_expanded_terms", this.lowercaseExpandedTerms);
|
||||
builder.field("enable_position_increments", this.enablePositionIncrements);
|
||||
builder.field(QueryStringQueryParser.LOWERCASE_EXPANDED_TERMS_FIELD.getPreferredName(), this.lowercaseExpandedTerms);
|
||||
builder.field(QueryStringQueryParser.ENABLE_POSITION_INCREMENTS_FIELD.getPreferredName(), this.enablePositionIncrements);
|
||||
this.fuzziness.toXContent(builder, params);
|
||||
builder.field("fuzzy_prefix_length", this.fuzzyPrefixLength);
|
||||
builder.field("fuzzy_max_expansions", this.fuzzyMaxExpansions);
|
||||
builder.field(QueryStringQueryParser.FUZZY_PREFIX_LENGTH_FIELD.getPreferredName(), this.fuzzyPrefixLength);
|
||||
builder.field(QueryStringQueryParser.FUZZY_MAX_EXPANSIONS_FIELD.getPreferredName(), this.fuzzyMaxExpansions);
|
||||
if (this.fuzzyRewrite != null) {
|
||||
builder.field("fuzzy_rewrite", this.fuzzyRewrite);
|
||||
builder.field(QueryStringQueryParser.FUZZY_REWRITE_FIELD.getPreferredName(), this.fuzzyRewrite);
|
||||
}
|
||||
builder.field("phrase_slop", this.phraseSlop);
|
||||
builder.field(QueryStringQueryParser.PHRASE_SLOP_FIELD.getPreferredName(), this.phraseSlop);
|
||||
if (this.analyzeWildcard != null) {
|
||||
builder.field("analyze_wildcard", this.analyzeWildcard);
|
||||
builder.field(QueryStringQueryParser.ANALYZE_WILDCARD_FIELD.getPreferredName(), this.analyzeWildcard);
|
||||
}
|
||||
if (this.rewrite != null) {
|
||||
builder.field("rewrite", this.rewrite);
|
||||
builder.field(QueryStringQueryParser.REWRITE_FIELD.getPreferredName(), this.rewrite);
|
||||
}
|
||||
if (this.minimumShouldMatch != null) {
|
||||
builder.field("minimum_should_match", this.minimumShouldMatch);
|
||||
builder.field(QueryStringQueryParser.MINIMUM_SHOULD_MATCH_FIELD.getPreferredName(), this.minimumShouldMatch);
|
||||
}
|
||||
if (this.quoteFieldSuffix != null) {
|
||||
builder.field("quote_field_suffix", this.quoteFieldSuffix);
|
||||
builder.field(QueryStringQueryParser.QUOTE_FIELD_SUFFIX_FIELD.getPreferredName(), this.quoteFieldSuffix);
|
||||
}
|
||||
if (this.lenient != null) {
|
||||
builder.field("lenient", this.lenient);
|
||||
builder.field(QueryStringQueryParser.LENIENT_FIELD.getPreferredName(), this.lenient);
|
||||
}
|
||||
builder.field("locale", this.locale.toLanguageTag());
|
||||
builder.field(QueryStringQueryParser.LOCALE_FIELD.getPreferredName(), this.locale.toLanguageTag());
|
||||
if (this.timeZone != null) {
|
||||
builder.field("time_zone", this.timeZone.getID());
|
||||
builder.field(QueryStringQueryParser.TIME_ZONE_FIELD.getPreferredName(), this.timeZone.getID());
|
||||
}
|
||||
builder.field("escape", this.escape);
|
||||
builder.field(QueryStringQueryParser.ESCAPE_FIELD.getPreferredName(), this.escape);
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.unit.Fuzziness;
|
||||
|
@ -34,6 +35,32 @@ import java.util.Map;
|
|||
*/
|
||||
public class QueryStringQueryParser implements QueryParser {
|
||||
|
||||
public static final ParseField QUERY_FIELD = new ParseField("query");
|
||||
public static final ParseField FIELDS_FIELD = new ParseField("fields");
|
||||
public static final ParseField DEFAULT_FIELD_FIELD = new ParseField("default_field");
|
||||
public static final ParseField DEFAULT_OPERATOR_FIELD = new ParseField("default_operator");
|
||||
public static final ParseField ANALYZER_FIELD = new ParseField("analyzer");
|
||||
public static final ParseField QUOTE_ANALYZER_FIELD = new ParseField("quote_analyzer");
|
||||
public static final ParseField ALLOW_LEADING_WILDCARD_FIELD = new ParseField("allow_leading_wildcard");
|
||||
public static final ParseField AUTO_GENERATED_PHRASE_QUERIES_FIELD = new ParseField("auto_generated_phrase_queries");
|
||||
public static final ParseField MAX_DETERMINED_STATES_FIELD = new ParseField("max_determined_states");
|
||||
public static final ParseField LOWERCASE_EXPANDED_TERMS_FIELD = new ParseField("lowercase_expanded_terms");
|
||||
public static final ParseField ENABLE_POSITION_INCREMENTS_FIELD = new ParseField("enable_position_increment");
|
||||
public static final ParseField ESCAPE_FIELD = new ParseField("escape");
|
||||
public static final ParseField USE_DIS_MAX_FIELD = new ParseField("use_dis_max");
|
||||
public static final ParseField FUZZY_PREFIX_LENGTH_FIELD = new ParseField("fuzzy_prefix_length");
|
||||
public static final ParseField FUZZY_MAX_EXPANSIONS_FIELD = new ParseField("fuzzy_max_expansions");
|
||||
public static final ParseField FUZZY_REWRITE_FIELD = new ParseField("fuzzy_rewrite");
|
||||
public static final ParseField PHRASE_SLOP_FIELD = new ParseField("phrase_slop");
|
||||
public static final ParseField TIE_BREAKER_FIELD = new ParseField("tie_breaker");
|
||||
public static final ParseField ANALYZE_WILDCARD_FIELD = new ParseField("analyze_wildcard");
|
||||
public static final ParseField REWRITE_FIELD = new ParseField("rewrite");
|
||||
public static final ParseField MINIMUM_SHOULD_MATCH_FIELD = new ParseField("minimum_should_match");
|
||||
public static final ParseField QUOTE_FIELD_SUFFIX_FIELD = new ParseField("quote_field_suffix");
|
||||
public static final ParseField LENIENT_FIELD = new ParseField("lenient");
|
||||
public static final ParseField LOCALE_FIELD = new ParseField("locale");
|
||||
public static final ParseField TIME_ZONE_FIELD = new ParseField("time_zone");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{QueryStringQueryBuilder.NAME, Strings.toCamelCase(QueryStringQueryBuilder.NAME)};
|
||||
|
@ -76,7 +103,7 @@ public class QueryStringQueryParser implements QueryParser {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
if ("fields".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) {
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
String fField = null;
|
||||
float fBoost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||
|
@ -99,64 +126,64 @@ public class QueryStringQueryParser implements QueryParser {
|
|||
throw new ParsingException(parser.getTokenLocation(), "[" + QueryStringQueryBuilder.NAME + "] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("query".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) {
|
||||
queryString = parser.text();
|
||||
} else if ("default_field".equals(currentFieldName) || "defaultField".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, DEFAULT_FIELD_FIELD)) {
|
||||
defaultField = parser.text();
|
||||
} else if ("default_operator".equals(currentFieldName) || "defaultOperator".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, DEFAULT_OPERATOR_FIELD)) {
|
||||
defaultOperator = Operator.fromString(parser.text());
|
||||
} else if ("analyzer".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, ANALYZER_FIELD)) {
|
||||
analyzer = parser.text();
|
||||
} else if ("quote_analyzer".equals(currentFieldName) || "quoteAnalyzer".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, QUOTE_ANALYZER_FIELD)) {
|
||||
quoteAnalyzer = parser.text();
|
||||
} else if ("allow_leading_wildcard".equals(currentFieldName) || "allowLeadingWildcard".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, ALLOW_LEADING_WILDCARD_FIELD)) {
|
||||
allowLeadingWildcard = parser.booleanValue();
|
||||
} else if ("auto_generate_phrase_queries".equals(currentFieldName) || "autoGeneratePhraseQueries".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AUTO_GENERATED_PHRASE_QUERIES_FIELD)) {
|
||||
autoGeneratePhraseQueries = parser.booleanValue();
|
||||
} else if ("max_determinized_states".equals(currentFieldName) || "maxDeterminizedStates".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, MAX_DETERMINED_STATES_FIELD)) {
|
||||
maxDeterminizedStates = parser.intValue();
|
||||
} else if ("lowercase_expanded_terms".equals(currentFieldName) || "lowercaseExpandedTerms".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, LOWERCASE_EXPANDED_TERMS_FIELD)) {
|
||||
lowercaseExpandedTerms = parser.booleanValue();
|
||||
} else if ("enable_position_increments".equals(currentFieldName) || "enablePositionIncrements".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, ENABLE_POSITION_INCREMENTS_FIELD)) {
|
||||
enablePositionIncrements = parser.booleanValue();
|
||||
} else if ("escape".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, ESCAPE_FIELD)) {
|
||||
escape = parser.booleanValue();
|
||||
} else if ("use_dis_max".equals(currentFieldName) || "useDisMax".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, USE_DIS_MAX_FIELD)) {
|
||||
useDisMax = parser.booleanValue();
|
||||
} else if ("fuzzy_prefix_length".equals(currentFieldName) || "fuzzyPrefixLength".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FUZZY_PREFIX_LENGTH_FIELD)) {
|
||||
fuzzyPrefixLength = parser.intValue();
|
||||
} else if ("fuzzy_max_expansions".equals(currentFieldName) || "fuzzyMaxExpansions".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FUZZY_MAX_EXPANSIONS_FIELD)) {
|
||||
fuzzyMaxExpansions = parser.intValue();
|
||||
} else if ("fuzzy_rewrite".equals(currentFieldName) || "fuzzyRewrite".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FUZZY_REWRITE_FIELD)) {
|
||||
fuzzyRewrite = parser.textOrNull();
|
||||
} else if ("phrase_slop".equals(currentFieldName) || "phraseSlop".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, PHRASE_SLOP_FIELD)) {
|
||||
phraseSlop = parser.intValue();
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, Fuzziness.FIELD)) {
|
||||
fuzziness = Fuzziness.parse(parser);
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("tie_breaker".equals(currentFieldName) || "tieBreaker".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, TIE_BREAKER_FIELD)) {
|
||||
tieBreaker = parser.floatValue();
|
||||
} else if ("analyze_wildcard".equals(currentFieldName) || "analyzeWildcard".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, ANALYZE_WILDCARD_FIELD)) {
|
||||
analyzeWildcard = parser.booleanValue();
|
||||
} else if ("rewrite".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) {
|
||||
rewrite = parser.textOrNull();
|
||||
} else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, MINIMUM_SHOULD_MATCH_FIELD)) {
|
||||
minimumShouldMatch = parser.textOrNull();
|
||||
} else if ("quote_field_suffix".equals(currentFieldName) || "quoteFieldSuffix".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, QUOTE_FIELD_SUFFIX_FIELD)) {
|
||||
quoteFieldSuffix = parser.textOrNull();
|
||||
} else if ("lenient".equalsIgnoreCase(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, LENIENT_FIELD)) {
|
||||
lenient = parser.booleanValue();
|
||||
} else if ("locale".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, LOCALE_FIELD)) {
|
||||
String localeStr = parser.text();
|
||||
locale = Locale.forLanguageTag(localeStr);
|
||||
} else if ("time_zone".equals(currentFieldName) || "timeZone".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, TIME_ZONE_FIELD)) {
|
||||
try {
|
||||
timeZone = parser.text();
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + QueryStringQueryBuilder.NAME + "] time_zone [" + parser.text() + "] is unknown");
|
||||
}
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + QueryStringQueryBuilder.NAME + "] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -233,15 +233,15 @@ public class RangeQueryBuilder extends AbstractQueryBuilder<RangeQueryBuilder> i
|
|||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.startObject(fieldName);
|
||||
builder.field("from", convertToStringIfBytesRef(this.from));
|
||||
builder.field("to", convertToStringIfBytesRef(this.to));
|
||||
builder.field("include_lower", includeLower);
|
||||
builder.field("include_upper", includeUpper);
|
||||
builder.field(RangeQueryParser.FROM_FIELD.getPreferredName(), convertToStringIfBytesRef(this.from));
|
||||
builder.field(RangeQueryParser.TO_FIELD.getPreferredName(), convertToStringIfBytesRef(this.to));
|
||||
builder.field(RangeQueryParser.INCLUDE_LOWER_FIELD.getPreferredName(), includeLower);
|
||||
builder.field(RangeQueryParser.INCLUDE_UPPER_FIELD.getPreferredName(), includeUpper);
|
||||
if (timeZone != null) {
|
||||
builder.field("time_zone", timeZone.getID());
|
||||
builder.field(RangeQueryParser.TIME_ZONE_FIELD.getPreferredName(), timeZone.getID());
|
||||
}
|
||||
if (format != null) {
|
||||
builder.field("format", format.format());
|
||||
builder.field(RangeQueryParser.FORMAT_FIELD.getPreferredName(), format.format());
|
||||
}
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
|
|
|
@ -30,8 +30,18 @@ import java.io.IOException;
|
|||
*/
|
||||
public class RangeQueryParser implements QueryParser<RangeQueryBuilder> {
|
||||
|
||||
private static final ParseField FIELDDATA_FIELD = new ParseField("fielddata").withAllDeprecated("[no replacement]");
|
||||
private static final ParseField NAME_FIELD = new ParseField("_name").withAllDeprecated("query name is not supported in short version of range query");
|
||||
public static final ParseField FIELDDATA_FIELD = new ParseField("fielddata").withAllDeprecated("[no replacement]");
|
||||
public static final ParseField NAME_FIELD = new ParseField("_name").withAllDeprecated("query name is not supported in short version of range query");
|
||||
public static final ParseField LTE_FIELD = new ParseField("lte", "le");
|
||||
public static final ParseField GTE_FIELD = new ParseField("gte", "ge");
|
||||
public static final ParseField FROM_FIELD = new ParseField("from");
|
||||
public static final ParseField TO_FIELD = new ParseField("to");
|
||||
public static final ParseField INCLUDE_LOWER_FIELD = new ParseField("include_lower");
|
||||
public static final ParseField INCLUDE_UPPER_FIELD = new ParseField("include_upper");
|
||||
public static final ParseField GT_FIELD = new ParseField("gt");
|
||||
public static final ParseField LT_FIELD = new ParseField("lt");
|
||||
public static final ParseField TIME_ZONE_FIELD = new ParseField("time_zone");
|
||||
public static final ParseField FORMAT_FIELD = new ParseField("format");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
@ -65,33 +75,33 @@ public class RangeQueryParser implements QueryParser<RangeQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else {
|
||||
if ("from".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, FROM_FIELD)) {
|
||||
from = parser.objectBytes();
|
||||
} else if ("to".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, TO_FIELD)) {
|
||||
to = parser.objectBytes();
|
||||
} else if ("include_lower".equals(currentFieldName) || "includeLower".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, INCLUDE_LOWER_FIELD)) {
|
||||
includeLower = parser.booleanValue();
|
||||
} else if ("include_upper".equals(currentFieldName) || "includeUpper".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, INCLUDE_UPPER_FIELD)) {
|
||||
includeUpper = parser.booleanValue();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("gt".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, GT_FIELD)) {
|
||||
from = parser.objectBytes();
|
||||
includeLower = false;
|
||||
} else if ("gte".equals(currentFieldName) || "ge".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, GTE_FIELD)) {
|
||||
from = parser.objectBytes();
|
||||
includeLower = true;
|
||||
} else if ("lt".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, LT_FIELD)) {
|
||||
to = parser.objectBytes();
|
||||
includeUpper = false;
|
||||
} else if ("lte".equals(currentFieldName) || "le".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, LTE_FIELD)) {
|
||||
to = parser.objectBytes();
|
||||
includeUpper = true;
|
||||
} else if ("time_zone".equals(currentFieldName) || "timeZone".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, TIME_ZONE_FIELD)) {
|
||||
timeZone = parser.text();
|
||||
} else if ("format".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FORMAT_FIELD)) {
|
||||
format = parser.text();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[range] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -135,14 +135,14 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder<RegexpQueryBuilder>
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.startObject(fieldName);
|
||||
builder.field("value", this.value);
|
||||
builder.field("flags_value", flagsValue);
|
||||
builder.field("max_determinized_states", maxDeterminizedStates);
|
||||
builder.field(RegexpQueryParser.VALUE_FIELD.getPreferredName(), this.value);
|
||||
builder.field(RegexpQueryParser.FLAGS_VALUE_FIELD.getPreferredName(), flagsValue);
|
||||
builder.field(RegexpQueryParser.MAX_DETERMINIZED_STATES_FIELD.getPreferredName(), maxDeterminizedStates);
|
||||
if (rewrite != null) {
|
||||
builder.field("rewrite", rewrite);
|
||||
builder.field(RegexpQueryParser.REWRITE_FIELD.getPreferredName(), rewrite);
|
||||
}
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
|
@ -155,7 +155,7 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder<RegexpQueryBuilder>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Query doToQuery(QueryShardContext context) throws QueryShardException, IOException {
|
||||
protected Query doToQuery(QueryShardContext context) throws QueryShardException, IOException {
|
||||
MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(context.parseFieldMatcher(), rewrite, null);
|
||||
|
||||
Query query = null;
|
||||
|
@ -174,7 +174,7 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder<RegexpQueryBuilder>
|
|||
}
|
||||
|
||||
@Override
|
||||
public RegexpQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
protected RegexpQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
RegexpQueryBuilder regexpQueryBuilder = new RegexpQueryBuilder(in.readString(), in.readString());
|
||||
regexpQueryBuilder.flagsValue = in.readVInt();
|
||||
regexpQueryBuilder.maxDeterminizedStates = in.readVInt();
|
||||
|
@ -183,7 +183,7 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder<RegexpQueryBuilder>
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doWriteTo(StreamOutput out) throws IOException {
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldName);
|
||||
out.writeString(value);
|
||||
out.writeVInt(flagsValue);
|
||||
|
@ -192,12 +192,12 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder<RegexpQueryBuilder>
|
|||
}
|
||||
|
||||
@Override
|
||||
public int doHashCode() {
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(fieldName, value, flagsValue, maxDeterminizedStates, rewrite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doEquals(RegexpQueryBuilder other) {
|
||||
protected boolean doEquals(RegexpQueryBuilder other) {
|
||||
return Objects.equals(fieldName, other.fieldName) &&
|
||||
Objects.equals(value, other.value) &&
|
||||
Objects.equals(flagsValue, other.flagsValue) &&
|
||||
|
|
|
@ -30,7 +30,12 @@ import java.io.IOException;
|
|||
*/
|
||||
public class RegexpQueryParser implements QueryParser<RegexpQueryBuilder> {
|
||||
|
||||
private static final ParseField NAME_FIELD = new ParseField("_name").withAllDeprecated("query name is not supported in short version of regexp query");
|
||||
public static final ParseField NAME_FIELD = new ParseField("_name").withAllDeprecated("query name is not supported in short version of regexp query");
|
||||
public static final ParseField FLAGS_VALUE_FIELD = new ParseField("flags_value");
|
||||
public static final ParseField MAX_DETERMINIZED_STATES_FIELD = new ParseField("max_determinized_states");
|
||||
public static final ParseField FLAGS_FIELD = new ParseField("flags");
|
||||
public static final ParseField REWRITE_FIELD = new ParseField("rewrite");
|
||||
public static final ParseField VALUE_FIELD = new ParseField("value");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
@ -62,20 +67,20 @@ public class RegexpQueryParser implements QueryParser<RegexpQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else {
|
||||
if ("value".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, VALUE_FIELD)) {
|
||||
value = parser.textOrNull();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("rewrite".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) {
|
||||
rewrite = parser.textOrNull();
|
||||
} else if ("flags".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FLAGS_FIELD)) {
|
||||
String flags = parser.textOrNull();
|
||||
flagsValue = RegexpFlag.resolveValue(flags);
|
||||
} else if ("max_determinized_states".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, MAX_DETERMINIZED_STATES_FIELD)) {
|
||||
maxDeterminizedStates = parser.intValue();
|
||||
} else if ("flags_value".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FLAGS_VALUE_FIELD)) {
|
||||
flagsValue = parser.intValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[regexp] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.script.Script;
|
||||
|
@ -35,6 +36,8 @@ import java.util.Map;
|
|||
*/
|
||||
public class ScriptQueryParser implements QueryParser<ScriptQueryBuilder> {
|
||||
|
||||
public static final ParseField PARAMS_FIELD = new ParseField("params");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{ScriptQueryBuilder.NAME};
|
||||
|
@ -62,15 +65,15 @@ public class ScriptQueryParser implements QueryParser<ScriptQueryBuilder> {
|
|||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
|
||||
script = Script.parse(parser, parseContext.parseFieldMatcher());
|
||||
} else if ("params".equals(currentFieldName)) { // TODO remove in 3.0 (here to support old script APIs)
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, PARAMS_FIELD)) { // TODO remove in 3.0 (here to support old script APIs)
|
||||
params = parser.map();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("_name".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if (!scriptParameterParser.token(currentFieldName, token, parser, parseContext.parseFieldMatcher())) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -303,10 +303,10 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
|||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
|
||||
builder.field("query", queryText);
|
||||
builder.field(SimpleQueryStringParser.QUERY_FIELD.getPreferredName(), queryText);
|
||||
|
||||
if (fieldsAndWeights.size() > 0) {
|
||||
builder.startArray("fields");
|
||||
builder.startArray(SimpleQueryStringParser.FIELDS_FIELD.getPreferredName());
|
||||
for (Map.Entry<String, Float> entry : fieldsAndWeights.entrySet()) {
|
||||
builder.value(entry.getKey() + "^" + entry.getValue());
|
||||
}
|
||||
|
@ -314,18 +314,18 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
|||
}
|
||||
|
||||
if (analyzer != null) {
|
||||
builder.field("analyzer", analyzer);
|
||||
builder.field(SimpleQueryStringParser.ANALYZER_FIELD.getPreferredName(), analyzer);
|
||||
}
|
||||
|
||||
builder.field("flags", flags);
|
||||
builder.field("default_operator", defaultOperator.name().toLowerCase(Locale.ROOT));
|
||||
builder.field("lowercase_expanded_terms", settings.lowercaseExpandedTerms());
|
||||
builder.field("lenient", settings.lenient());
|
||||
builder.field("analyze_wildcard", settings.analyzeWildcard());
|
||||
builder.field("locale", (settings.locale().toLanguageTag()));
|
||||
builder.field(SimpleQueryStringParser.FLAGS_FIELD.getPreferredName(), flags);
|
||||
builder.field(SimpleQueryStringParser.DEFAULT_OPERATOR_FIELD.getPreferredName(), defaultOperator.name().toLowerCase(Locale.ROOT));
|
||||
builder.field(SimpleQueryStringParser.LOWERCASE_EXPANDED_TERMS_FIELD.getPreferredName(), settings.lowercaseExpandedTerms());
|
||||
builder.field(SimpleQueryStringParser.LENIENT_FIELD.getPreferredName(), settings.lenient());
|
||||
builder.field(SimpleQueryStringParser.ANALYZE_WILDCARD_FIELD.getPreferredName(), settings.analyzeWildcard());
|
||||
builder.field(SimpleQueryStringParser.LOCALE_FIELD.getPreferredName(), (settings.locale().toLanguageTag()));
|
||||
|
||||
if (minimumShouldMatch != null) {
|
||||
builder.field("minimum_should_match", minimumShouldMatch);
|
||||
builder.field(SimpleQueryStringParser.MINIMUM_SHOULD_MATCH_FIELD.getPreferredName(), minimumShouldMatch);
|
||||
}
|
||||
|
||||
printBoostAndQueryName(builder);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -60,6 +61,17 @@ import java.util.Map;
|
|||
*/
|
||||
public class SimpleQueryStringParser implements QueryParser<SimpleQueryStringBuilder> {
|
||||
|
||||
public static final ParseField MINIMUM_SHOULD_MATCH_FIELD = new ParseField("minimum_should_match");
|
||||
public static final ParseField ANALYZE_WILDCARD_FIELD = new ParseField("analyze_wildcard");
|
||||
public static final ParseField LENIENT_FIELD = new ParseField("lenient");
|
||||
public static final ParseField LOWERCASE_EXPANDED_TERMS_FIELD = new ParseField("lowercase_expanded_terms");
|
||||
public static final ParseField LOCALE_FIELD = new ParseField("locale");
|
||||
public static final ParseField FLAGS_FIELD = new ParseField("flags");
|
||||
public static final ParseField DEFAULT_OPERATOR_FIELD = new ParseField("default_operator");
|
||||
public static final ParseField ANALYZER_FIELD = new ParseField("analyzer");
|
||||
public static final ParseField QUERY_FIELD = new ParseField("query");
|
||||
public static final ParseField FIELDS_FIELD = new ParseField("fields");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{SimpleQueryStringBuilder.NAME, Strings.toCamelCase(SimpleQueryStringBuilder.NAME)};
|
||||
|
@ -88,7 +100,7 @@ public class SimpleQueryStringParser implements QueryParser<SimpleQueryStringBui
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
if ("fields".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) {
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
String fField = null;
|
||||
float fBoost = 1;
|
||||
|
@ -111,15 +123,15 @@ public class SimpleQueryStringParser implements QueryParser<SimpleQueryStringBui
|
|||
throw new ParsingException(parser.getTokenLocation(), "[" + SimpleQueryStringBuilder.NAME + "] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("query".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) {
|
||||
queryBody = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("analyzer".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, ANALYZER_FIELD)) {
|
||||
analyzerName = parser.text();
|
||||
} else if ("default_operator".equals(currentFieldName) || "defaultOperator".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, DEFAULT_OPERATOR_FIELD)) {
|
||||
defaultOperator = Operator.fromString(parser.text());
|
||||
} else if ("flags".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FLAGS_FIELD)) {
|
||||
if (parser.currentToken() != XContentParser.Token.VALUE_NUMBER) {
|
||||
// Possible options are:
|
||||
// ALL, NONE, AND, OR, PREFIX, PHRASE, PRECEDENCE, ESCAPE, WHITESPACE, FUZZY, NEAR, SLOP
|
||||
|
@ -130,18 +142,18 @@ public class SimpleQueryStringParser implements QueryParser<SimpleQueryStringBui
|
|||
flags = SimpleQueryStringFlag.ALL.value();
|
||||
}
|
||||
}
|
||||
} else if ("locale".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, LOCALE_FIELD)) {
|
||||
String localeStr = parser.text();
|
||||
locale = Locale.forLanguageTag(localeStr);
|
||||
} else if ("lowercase_expanded_terms".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, LOWERCASE_EXPANDED_TERMS_FIELD)) {
|
||||
lowercaseExpandedTerms = parser.booleanValue();
|
||||
} else if ("lenient".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, LENIENT_FIELD)) {
|
||||
lenient = parser.booleanValue();
|
||||
} else if ("analyze_wildcard".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, ANALYZE_WILDCARD_FIELD)) {
|
||||
analyzeWildcard = parser.booleanValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if ("minimum_should_match".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, MINIMUM_SHOULD_MATCH_FIELD)) {
|
||||
minimumShouldMatch = parser.textOrNull();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + SimpleQueryStringBuilder.NAME + "] unsupported field [" + parser.currentName() + "]");
|
||||
|
|
|
@ -71,9 +71,9 @@ public class SpanContainingQueryBuilder extends AbstractQueryBuilder<SpanContain
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("big");
|
||||
builder.field(SpanContainingQueryParser.BIG_FIELD.getPreferredName());
|
||||
big.toXContent(builder, params);
|
||||
builder.field("little");
|
||||
builder.field(SpanContainingQueryParser.LITTLE_FIELD.getPreferredName());
|
||||
little.toXContent(builder, params);
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -30,6 +31,9 @@ import java.io.IOException;
|
|||
*/
|
||||
public class SpanContainingQueryParser implements QueryParser<SpanContainingQueryBuilder> {
|
||||
|
||||
public static final ParseField BIG_FIELD = new ParseField("big");
|
||||
public static final ParseField LITTLE_FIELD = new ParseField("little");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{SpanContainingQueryBuilder.NAME, Strings.toCamelCase(SpanContainingQueryBuilder.NAME)};
|
||||
|
@ -49,13 +53,13 @@ public class SpanContainingQueryParser implements QueryParser<SpanContainingQuer
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if ("big".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, BIG_FIELD)) {
|
||||
QueryBuilder query = parseContext.parseInnerQueryBuilder();
|
||||
if (!(query instanceof SpanQueryBuilder<?>)) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "span_containing [big] must be of type span query");
|
||||
}
|
||||
big = (SpanQueryBuilder<?>) query;
|
||||
} else if ("little".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, LITTLE_FIELD)) {
|
||||
QueryBuilder query = parseContext.parseInnerQueryBuilder();
|
||||
if (!(query instanceof SpanQueryBuilder<?>)) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "span_containing [little] must be of type span query");
|
||||
|
@ -64,9 +68,9 @@ public class SpanContainingQueryParser implements QueryParser<SpanContainingQuer
|
|||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[span_containing] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[span_containing] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -74,9 +74,9 @@ public class SpanFirstQueryBuilder extends AbstractQueryBuilder<SpanFirstQueryBu
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("match");
|
||||
builder.field(SpanFirstQueryParser.MATCH_FIELD.getPreferredName());
|
||||
matchBuilder.toXContent(builder, params);
|
||||
builder.field("end", end);
|
||||
builder.field(SpanFirstQueryParser.END_FIELD.getPreferredName(), end);
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -30,6 +31,9 @@ import java.io.IOException;
|
|||
*/
|
||||
public class SpanFirstQueryParser implements QueryParser<SpanFirstQueryBuilder> {
|
||||
|
||||
public static final ParseField MATCH_FIELD = new ParseField("match");
|
||||
public static final ParseField END_FIELD = new ParseField("end");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{SpanFirstQueryBuilder.NAME, Strings.toCamelCase(SpanFirstQueryBuilder.NAME)};
|
||||
|
@ -51,7 +55,7 @@ public class SpanFirstQueryParser implements QueryParser<SpanFirstQueryBuilder>
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if ("match".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, MATCH_FIELD)) {
|
||||
QueryBuilder query = parseContext.parseInnerQueryBuilder();
|
||||
if (!(query instanceof SpanQueryBuilder)) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "spanFirst [match] must be of type span query");
|
||||
|
@ -61,11 +65,11 @@ public class SpanFirstQueryParser implements QueryParser<SpanFirstQueryBuilder>
|
|||
throw new ParsingException(parser.getTokenLocation(), "[span_first] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else {
|
||||
if ("boost".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("end".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, END_FIELD)) {
|
||||
end = parser.intValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[span_first] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -56,7 +56,7 @@ public class SpanMultiTermQueryBuilder extends AbstractQueryBuilder<SpanMultiTer
|
|||
protected void doXContent(XContentBuilder builder, Params params)
|
||||
throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field(SpanMultiTermQueryParser.MATCH_NAME);
|
||||
builder.field(SpanMultiTermQueryParser.MATCH_FIELD.getPreferredName());
|
||||
multiTermQueryBuilder.toXContent(builder, params);
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -29,7 +30,7 @@ import java.io.IOException;
|
|||
*/
|
||||
public class SpanMultiTermQueryParser implements QueryParser<SpanMultiTermQueryBuilder> {
|
||||
|
||||
public static final String MATCH_NAME = "match";
|
||||
public static final ParseField MATCH_FIELD = new ParseField("match");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
@ -48,19 +49,19 @@ public class SpanMultiTermQueryParser implements QueryParser<SpanMultiTermQueryB
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if (MATCH_NAME.equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, MATCH_FIELD)) {
|
||||
QueryBuilder innerQuery = parseContext.parseInnerQueryBuilder();
|
||||
if (innerQuery instanceof MultiTermQueryBuilder == false) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[span_multi] [" + MATCH_NAME + "] must be of type multi term query");
|
||||
throw new ParsingException(parser.getTokenLocation(), "[span_multi] [" + MATCH_FIELD.getPreferredName() + "] must be of type multi term query");
|
||||
}
|
||||
subQuery = (MultiTermQueryBuilder) innerQuery;
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[span_multi] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("_name".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[span_multi] query does not support [" + currentFieldName + "]");
|
||||
|
@ -69,7 +70,7 @@ public class SpanMultiTermQueryParser implements QueryParser<SpanMultiTermQueryB
|
|||
}
|
||||
|
||||
if (subQuery == null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[span_multi] must have [" + MATCH_NAME + "] multi term query clause");
|
||||
throw new ParsingException(parser.getTokenLocation(), "[span_multi] must have [" + MATCH_FIELD.getPreferredName() + "] multi term query clause");
|
||||
}
|
||||
|
||||
return new SpanMultiTermQueryBuilder(subQuery).queryName(queryName).boost(boost);
|
||||
|
|
|
@ -125,14 +125,14 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.startArray("clauses");
|
||||
builder.startArray(SpanNearQueryParser.CLAUSES_FIELD.getPreferredName());
|
||||
for (SpanQueryBuilder clause : clauses) {
|
||||
clause.toXContent(builder, params);
|
||||
}
|
||||
builder.endArray();
|
||||
builder.field("slop", slop);
|
||||
builder.field("in_order", inOrder);
|
||||
builder.field("collect_payloads", collectPayloads);
|
||||
builder.field(SpanNearQueryParser.SLOP_FIELD.getPreferredName(), slop);
|
||||
builder.field(SpanNearQueryParser.IN_ORDER_FIELD.getPreferredName(), inOrder);
|
||||
builder.field(SpanNearQueryParser.COLLECT_PAYLOADS_FIELD.getPreferredName(), collectPayloads);
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -32,6 +33,11 @@ import java.util.List;
|
|||
*/
|
||||
public class SpanNearQueryParser implements QueryParser<SpanNearQueryBuilder> {
|
||||
|
||||
public static final ParseField SLOP_FIELD = new ParseField("slop");
|
||||
public static final ParseField COLLECT_PAYLOADS_FIELD = new ParseField("collect_payloads");
|
||||
public static final ParseField CLAUSES_FIELD = new ParseField("clauses");
|
||||
public static final ParseField IN_ORDER_FIELD = new ParseField("in_order");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{SpanNearQueryBuilder.NAME, Strings.toCamelCase(SpanNearQueryBuilder.NAME)};
|
||||
|
@ -55,7 +61,7 @@ public class SpanNearQueryParser implements QueryParser<SpanNearQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
if ("clauses".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, CLAUSES_FIELD)) {
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
QueryBuilder query = parseContext.parseInnerQueryBuilder();
|
||||
if (!(query instanceof SpanQueryBuilder)) {
|
||||
|
@ -67,15 +73,15 @@ public class SpanNearQueryParser implements QueryParser<SpanNearQueryBuilder> {
|
|||
throw new ParsingException(parser.getTokenLocation(), "[span_near] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("in_order".equals(currentFieldName) || "inOrder".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, IN_ORDER_FIELD)) {
|
||||
inOrder = parser.booleanValue();
|
||||
} else if ("collect_payloads".equals(currentFieldName) || "collectPayloads".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, COLLECT_PAYLOADS_FIELD)) {
|
||||
collectPayloads = parser.booleanValue();
|
||||
} else if ("slop".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, SLOP_FIELD)) {
|
||||
slop = parser.intValue();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[span_near] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -125,12 +125,12 @@ public class SpanNotQueryBuilder extends AbstractQueryBuilder<SpanNotQueryBuilde
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("include");
|
||||
builder.field(SpanNotQueryParser.INCLUDE_FIELD.getPreferredName());
|
||||
include.toXContent(builder, params);
|
||||
builder.field("exclude");
|
||||
builder.field(SpanNotQueryParser.EXCLUDE_FIELD.getPreferredName());
|
||||
exclude.toXContent(builder, params);
|
||||
builder.field("pre", pre);
|
||||
builder.field("post", post);
|
||||
builder.field(SpanNotQueryParser.PRE_FIELD.getPreferredName(), pre);
|
||||
builder.field(SpanNotQueryParser.POST_FIELD.getPreferredName(), post);
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -30,6 +31,12 @@ import java.io.IOException;
|
|||
*/
|
||||
public class SpanNotQueryParser implements QueryParser<SpanNotQueryBuilder> {
|
||||
|
||||
public static final ParseField POST_FIELD = new ParseField("post");
|
||||
public static final ParseField PRE_FIELD = new ParseField("pre");
|
||||
public static final ParseField DIST_FIELD = new ParseField("dist");
|
||||
public static final ParseField EXCLUDE_FIELD = new ParseField("exclude");
|
||||
public static final ParseField INCLUDE_FIELD = new ParseField("include");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{SpanNotQueryBuilder.NAME, Strings.toCamelCase(SpanNotQueryBuilder.NAME)};
|
||||
|
@ -56,13 +63,13 @@ public class SpanNotQueryParser implements QueryParser<SpanNotQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if ("include".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, INCLUDE_FIELD)) {
|
||||
QueryBuilder query = parseContext.parseInnerQueryBuilder();
|
||||
if (!(query instanceof SpanQueryBuilder)) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "spanNot [include] must be of type span query");
|
||||
}
|
||||
include = (SpanQueryBuilder) query;
|
||||
} else if ("exclude".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, EXCLUDE_FIELD)) {
|
||||
QueryBuilder query = parseContext.parseInnerQueryBuilder();
|
||||
if (!(query instanceof SpanQueryBuilder)) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "spanNot [exclude] must be of type span query");
|
||||
|
@ -72,15 +79,15 @@ public class SpanNotQueryParser implements QueryParser<SpanNotQueryBuilder> {
|
|||
throw new ParsingException(parser.getTokenLocation(), "[span_not] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else {
|
||||
if ("dist".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, DIST_FIELD)) {
|
||||
dist = parser.intValue();
|
||||
} else if ("pre".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, PRE_FIELD)) {
|
||||
pre = parser.intValue();
|
||||
} else if ("post".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, POST_FIELD)) {
|
||||
post = parser.intValue();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[span_not] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -67,7 +67,7 @@ public class SpanOrQueryBuilder extends AbstractQueryBuilder<SpanOrQueryBuilder>
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.startArray("clauses");
|
||||
builder.startArray(SpanOrQueryParser.CLAUSES_FIELD.getPreferredName());
|
||||
for (SpanQueryBuilder clause : clauses) {
|
||||
clause.toXContent(builder, params);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -32,6 +33,8 @@ import java.util.List;
|
|||
*/
|
||||
public class SpanOrQueryParser implements QueryParser<SpanOrQueryBuilder> {
|
||||
|
||||
public static final ParseField CLAUSES_FIELD = new ParseField("clauses");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{SpanOrQueryBuilder.NAME, Strings.toCamelCase(SpanOrQueryBuilder.NAME)};
|
||||
|
@ -52,7 +55,7 @@ public class SpanOrQueryParser implements QueryParser<SpanOrQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
if ("clauses".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, CLAUSES_FIELD)) {
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
QueryBuilder query = parseContext.parseInnerQueryBuilder();
|
||||
if (!(query instanceof SpanQueryBuilder)) {
|
||||
|
@ -64,9 +67,9 @@ public class SpanOrQueryParser implements QueryParser<SpanOrQueryBuilder> {
|
|||
throw new ParsingException(parser.getTokenLocation(), "[span_or] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else {
|
||||
if ("boost".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[span_or] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -68,7 +68,7 @@ public class SpanTermQueryBuilder extends BaseTermQueryBuilder<SpanTermQueryBuil
|
|||
}
|
||||
|
||||
@Override
|
||||
public SpanQuery doToQuery(QueryShardContext context) throws IOException {
|
||||
protected SpanQuery doToQuery(QueryShardContext context) throws IOException {
|
||||
BytesRef valueBytes = null;
|
||||
String fieldName = this.fieldName;
|
||||
MappedFieldType mapper = context.fieldMapper(fieldName);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -30,6 +31,8 @@ import java.io.IOException;
|
|||
*/
|
||||
public class SpanTermQueryParser implements QueryParser<SpanTermQueryBuilder> {
|
||||
|
||||
public static final ParseField TERM_FIELD = new ParseField("term");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{SpanTermQueryBuilder.NAME, Strings.toCamelCase(SpanTermQueryBuilder.NAME)};
|
||||
|
@ -58,13 +61,13 @@ public class SpanTermQueryParser implements QueryParser<SpanTermQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else {
|
||||
if ("term".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, TERM_FIELD)) {
|
||||
value = parser.objectBytes();
|
||||
} else if ("value".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, BaseTermQueryBuilder.VALUE_FIELD)) {
|
||||
value = parser.objectBytes();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[span_term] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -73,10 +73,10 @@ public class SpanWithinQueryBuilder extends AbstractQueryBuilder<SpanWithinQuery
|
|||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
|
||||
builder.field("big");
|
||||
builder.field(SpanWithinQueryParser.BIG_FIELD.getPreferredName());
|
||||
big.toXContent(builder, params);
|
||||
|
||||
builder.field("little");
|
||||
builder.field(SpanWithinQueryParser.LITTLE_FIELD.getPreferredName());
|
||||
little.toXContent(builder, params);
|
||||
|
||||
printBoostAndQueryName(builder);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -30,6 +31,9 @@ import java.io.IOException;
|
|||
*/
|
||||
public class SpanWithinQueryParser implements QueryParser<SpanWithinQueryBuilder> {
|
||||
|
||||
public static final ParseField BIG_FIELD = new ParseField("big");
|
||||
public static final ParseField LITTLE_FIELD = new ParseField("little");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{SpanWithinQueryBuilder.NAME, Strings.toCamelCase(SpanWithinQueryBuilder.NAME)};
|
||||
|
@ -50,13 +54,13 @@ public class SpanWithinQueryParser implements QueryParser<SpanWithinQueryBuilder
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if ("big".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, BIG_FIELD)) {
|
||||
QueryBuilder query = parseContext.parseInnerQueryBuilder();
|
||||
if (query instanceof SpanQueryBuilder == false) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "span_within [big] must be of type span query");
|
||||
}
|
||||
big = (SpanQueryBuilder) query;
|
||||
} else if ("little".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, LITTLE_FIELD)) {
|
||||
QueryBuilder query = parseContext.parseInnerQueryBuilder();
|
||||
if (query instanceof SpanQueryBuilder == false) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "span_within [little] must be of type span query");
|
||||
|
@ -65,9 +69,9 @@ public class SpanWithinQueryParser implements QueryParser<SpanWithinQueryBuilder
|
|||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[span_within] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[span_within] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -71,7 +71,7 @@ public class TermQueryBuilder extends BaseTermQueryBuilder<TermQueryBuilder> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Query doToQuery(QueryShardContext context) throws IOException {
|
||||
protected Query doToQuery(QueryShardContext context) throws IOException {
|
||||
Query query = null;
|
||||
MappedFieldType mapper = context.fieldMapper(this.fieldName);
|
||||
if (mapper != null) {
|
||||
|
|
|
@ -30,8 +30,8 @@ import java.io.IOException;
|
|||
*/
|
||||
public class TermQueryParser implements QueryParser<TermQueryBuilder> {
|
||||
|
||||
private static final ParseField NAME_FIELD = new ParseField("_name").withAllDeprecated("query name is not supported in short version of term query");
|
||||
private static final ParseField BOOST_FIELD = new ParseField("boost").withAllDeprecated("boost is not supported in short version of term query");
|
||||
public static final ParseField TERM_FIELD = new ParseField("term");
|
||||
public static final ParseField VALUE_FIELD = new ParseField("value");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
@ -63,13 +63,13 @@ public class TermQueryParser implements QueryParser<TermQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else {
|
||||
if ("term".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, TERM_FIELD)) {
|
||||
value = parser.objectBytes();
|
||||
} else if ("value".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, VALUE_FIELD)) {
|
||||
value = parser.objectBytes();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[term] query does not support [" + currentFieldName + "]");
|
||||
|
@ -77,17 +77,11 @@ public class TermQueryParser implements QueryParser<TermQueryBuilder> {
|
|||
}
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else {
|
||||
if (fieldName != null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[term] query does not support different field names, use [bool] query instead");
|
||||
}
|
||||
fieldName = currentFieldName;
|
||||
value = parser.objectBytes();
|
||||
if (fieldName != null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[term] query does not support different field names, use [bool] query instead");
|
||||
}
|
||||
fieldName = currentFieldName;
|
||||
value = parser.objectBytes();
|
||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[term] query does not support array of values");
|
||||
}
|
||||
|
|
|
@ -207,7 +207,7 @@ public class TermsQueryBuilder extends AbstractQueryBuilder<TermsQueryBuilder> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
if (this.termsLookup != null) {
|
||||
builder.startObject(fieldName);
|
||||
|
|
|
@ -74,9 +74,9 @@ public class TermsQueryParser implements QueryParser {
|
|||
fieldName = currentFieldName;
|
||||
termsLookup = TermsLookup.parseTermsLookup(parser);
|
||||
} else if (token.isValue()) {
|
||||
if ("boost".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + TermsQueryBuilder.NAME + "] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -62,7 +62,7 @@ public class TypeQueryBuilder extends AbstractQueryBuilder<TypeQueryBuilder> {
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("value", type.utf8ToString());
|
||||
builder.field(TypeQueryParser.VALUE_FIELD.getPreferredName(), type.utf8ToString());
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
|
@ -30,6 +31,8 @@ import java.io.IOException;
|
|||
*/
|
||||
public class TypeQueryParser implements QueryParser<TypeQueryBuilder> {
|
||||
|
||||
public static final ParseField VALUE_FIELD = new ParseField("value");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{TypeQueryBuilder.NAME};
|
||||
|
@ -49,11 +52,11 @@ public class TypeQueryParser implements QueryParser<TypeQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token.isValue()) {
|
||||
if ("_name".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("value".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, VALUE_FIELD)) {
|
||||
type = parser.utf8Bytes();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[" + TypeQueryBuilder.NAME + "] filter doesn't support [" + currentFieldName + "]");
|
||||
|
|
|
@ -99,12 +99,12 @@ public class WildcardQueryBuilder extends AbstractQueryBuilder<WildcardQueryBuil
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.startObject(fieldName);
|
||||
builder.field("wildcard", value);
|
||||
builder.field(WildcardQueryParser.WILDCARD_FIELD.getPreferredName(), value);
|
||||
if (rewrite != null) {
|
||||
builder.field("rewrite", rewrite);
|
||||
builder.field(WildcardQueryParser.REWRITE_FIELD.getPreferredName(), rewrite);
|
||||
}
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
|
@ -29,6 +30,10 @@ import java.io.IOException;
|
|||
*/
|
||||
public class WildcardQueryParser implements QueryParser<WildcardQueryBuilder> {
|
||||
|
||||
public static final ParseField WILDCARD_FIELD = new ParseField("wildcard");
|
||||
public static final ParseField VALUE_FIELD = new ParseField("value");
|
||||
public static final ParseField REWRITE_FIELD = new ParseField("rewrite");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{WildcardQueryBuilder.NAME};
|
||||
|
@ -55,15 +60,15 @@ public class WildcardQueryParser implements QueryParser<WildcardQueryBuilder> {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else {
|
||||
if ("wildcard".equals(currentFieldName)) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, WILDCARD_FIELD)) {
|
||||
value = parser.text();
|
||||
} else if ("value".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, VALUE_FIELD)) {
|
||||
value = parser.text();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("rewrite".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) {
|
||||
rewrite = parser.textOrNull();
|
||||
} else if ("_name".equals(currentFieldName)) {
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[wildcard] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -94,7 +94,7 @@ public class WrapperQueryBuilder extends AbstractQueryBuilder<WrapperQueryBuilde
|
|||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.field("query", source);
|
||||
builder.field(WrapperQueryParser.QUERY_FIELD.getPreferredName(), source);
|
||||
builder.endObject();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
|
@ -29,6 +30,8 @@ import java.io.IOException;
|
|||
*/
|
||||
public class WrapperQueryParser implements QueryParser {
|
||||
|
||||
public static final ParseField QUERY_FIELD = new ParseField("query");
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{WrapperQueryBuilder.NAME};
|
||||
|
@ -43,7 +46,7 @@ public class WrapperQueryParser implements QueryParser {
|
|||
throw new ParsingException(parser.getTokenLocation(), "[wrapper] query malformed");
|
||||
}
|
||||
String fieldName = parser.currentName();
|
||||
if (!fieldName.equals("query")) {
|
||||
if (! parseContext.parseFieldMatcher().match(fieldName, QUERY_FIELD)) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[wrapper] query malformed, expected `query` but was" + fieldName);
|
||||
}
|
||||
parser.nextToken();
|
||||
|
|
|
@ -349,7 +349,7 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|||
assertParsedQuery(builder.bytes(), testQuery);
|
||||
for (Map.Entry<String, QB> alternateVersion : getAlternateVersions().entrySet()) {
|
||||
String queryAsString = alternateVersion.getKey();
|
||||
assertParsedQuery(new BytesArray(queryAsString), alternateVersion.getValue());
|
||||
assertParsedQuery(new BytesArray(queryAsString), alternateVersion.getValue(), ParseFieldMatcher.EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -869,4 +869,54 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|||
throw new UnsupportedOperationException("this test can't handle MultiTermVector requests");
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method to check a valid json string representing the query under test against
|
||||
* it's generated json.
|
||||
*
|
||||
* Note: By the time of this writing (Nov 2015) all queries are taken from the query dsl
|
||||
* reference docs mirroring examples there. Here's how the queries were generated:
|
||||
*
|
||||
* <ul>
|
||||
* <li> Take a reference documentation example.
|
||||
* <li> Stick it into the createParseableQueryJson method of the respective query test.
|
||||
* <li> Manually check that what the QueryBuilder generates equals the input json ignoring default options.
|
||||
* <li> Put the manual checks into the asserQueryParsedFromJson method.
|
||||
* <li> Now copy the generated json including default options into createParseableQueryJso
|
||||
* <li> By now the roundtrip check for the json should be happy.
|
||||
* </ul>
|
||||
**/
|
||||
public static void checkGeneratedJson(String expected, QueryBuilder<?> source) throws IOException {
|
||||
// now assert that we actually generate the same JSON
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
|
||||
source.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
assertEquals(
|
||||
msg(expected, builder.string()),
|
||||
expected.replaceAll("\\s+",""),
|
||||
builder.string().replaceAll("\\s+",""));
|
||||
}
|
||||
|
||||
private static String msg(String left, String right) {
|
||||
int size = Math.min(left.length(), right.length());
|
||||
StringBuilder builder = new StringBuilder("size: " + left.length() + " vs. " + right.length());
|
||||
builder.append(" content: <<");
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (left.charAt(i) == right.charAt(i)) {
|
||||
builder.append(left.charAt(i));
|
||||
} else {
|
||||
builder.append(">> ").append("until offset: ").append(i)
|
||||
.append(" [").append(left.charAt(i)).append(" vs.").append(right.charAt(i))
|
||||
.append("] [").append((int)left.charAt(i) ).append(" vs.").append((int)right.charAt(i)).append(']');
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
if (left.length() != right.length()) {
|
||||
int leftEnd = Math.max(size, left.length()) - 1;
|
||||
int rightEnd = Math.max(size, right.length()) - 1;
|
||||
builder.append(">> ").append("until offset: ").append(size)
|
||||
.append(" [").append(left.charAt(leftEnd)).append(" vs.").append(right.charAt(rightEnd))
|
||||
.append("] [").append((int)left.charAt(leftEnd)).append(" vs.").append((int)right.charAt(rightEnd)).append(']');
|
||||
return builder.toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.common.bytes.BytesReference;
|
|||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -243,4 +244,65 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase<BoolQueryBuilde
|
|||
assertThat(innerBooleanClause2.getOccur(), equalTo(BooleanClause.Occur.SHOULD));
|
||||
assertThat(innerBooleanClause2.getQuery(), instanceOf(MatchAllDocsQuery.class));
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String query =
|
||||
"{" +
|
||||
"\"bool\" : {" +
|
||||
" \"must\" : [ {" +
|
||||
" \"term\" : {" +
|
||||
" \"user\" : {" +
|
||||
" \"value\" : \"kimchy\"," +
|
||||
" \"boost\" : 1.0" +
|
||||
" }" +
|
||||
" }" +
|
||||
" } ]," +
|
||||
" \"filter\" : [ {" +
|
||||
" \"term\" : {" +
|
||||
" \"tag\" : {" +
|
||||
" \"value\" : \"tech\"," +
|
||||
" \"boost\" : 1.0" +
|
||||
" }" +
|
||||
" }" +
|
||||
" } ]," +
|
||||
" \"must_not\" : [ {" +
|
||||
" \"range\" : {" +
|
||||
" \"age\" : {" +
|
||||
" \"from\" : 10," +
|
||||
" \"to\" : 20," +
|
||||
" \"include_lower\" : true," +
|
||||
" \"include_upper\" : true," +
|
||||
" \"boost\" : 1.0" +
|
||||
" }" +
|
||||
" }" +
|
||||
" } ]," +
|
||||
" \"should\" : [ {" +
|
||||
" \"term\" : {" +
|
||||
" \"tag\" : {" +
|
||||
" \"value\" : \"wow\"," +
|
||||
" \"boost\" : 1.0" +
|
||||
" }" +
|
||||
" }" +
|
||||
" }, {" +
|
||||
" \"term\" : {" +
|
||||
" \"tag\" : {" +
|
||||
" \"value\" : \"elasticsearch\"," +
|
||||
" \"boost\" : 1.0" +
|
||||
" }" +
|
||||
" }" +
|
||||
" } ]," +
|
||||
" \"disable_coord\" : false," +
|
||||
" \"adjust_pure_negative\" : true," +
|
||||
" \"minimum_should_match\" : \"23\"," +
|
||||
" \"boost\" : 42.0" +
|
||||
"}" +
|
||||
"}";
|
||||
|
||||
BoolQueryBuilder queryBuilder = (BoolQueryBuilder) parseQuery(query);
|
||||
checkGeneratedJson(query, queryBuilder);
|
||||
|
||||
assertEquals(query, 42, queryBuilder.boost, 0.00001);
|
||||
assertEquals(query, "23", queryBuilder.minimumShouldMatch());
|
||||
assertEquals(query, "kimchy", ((TermQueryBuilder)queryBuilder.must().get(0)).value());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,4 +69,38 @@ public class BoostingQueryBuilderTests extends AbstractQueryTestCase<BoostingQue
|
|||
//
|
||||
}
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String query =
|
||||
"{\n" +
|
||||
" \"boosting\" : {\n" +
|
||||
" \"positive\" : {\n" +
|
||||
" \"term\" : {\n" +
|
||||
" \"field1\" : {\n" +
|
||||
" \"value\" : \"value1\",\n" +
|
||||
" \"boost\" : 5.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"negative\" : {\n" +
|
||||
" \"term\" : {\n" +
|
||||
" \"field2\" : {\n" +
|
||||
" \"value\" : \"value2\",\n" +
|
||||
" \"boost\" : 8.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"negative_boost\" : 23.0,\n" +
|
||||
" \"boost\" : 42.0\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
BoostingQueryBuilder queryBuilder = (BoostingQueryBuilder) parseQuery(query);
|
||||
checkGeneratedJson(query, queryBuilder);
|
||||
|
||||
assertEquals(query, 42, queryBuilder.boost(), 0.00001);
|
||||
assertEquals(query, 23, queryBuilder.negativeBoost(), 0.00001);
|
||||
assertEquals(query, 8, queryBuilder.negativeQuery().boost(), 0.00001);
|
||||
assertEquals(query, 5, queryBuilder.positiveQuery().boost(), 0.00001);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,6 +104,35 @@ public class CommonTermsQueryBuilderTests extends AbstractQueryTestCase<CommonTe
|
|||
}
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String query =
|
||||
"{\n" +
|
||||
" \"common\" : {\n" +
|
||||
" \"body\" : {\n" +
|
||||
" \"query\" : \"nelly the elephant not as a cartoon\",\n" +
|
||||
" \"disable_coord\" : true,\n" +
|
||||
" \"high_freq_operator\" : \"AND\",\n" +
|
||||
" \"low_freq_operator\" : \"OR\",\n" +
|
||||
" \"cutoff_frequency\" : 0.001,\n" +
|
||||
" \"minimum_should_match\" : {\n" +
|
||||
" \"low_freq\" : \"2\",\n" +
|
||||
" \"high_freq\" : \"3\"\n" +
|
||||
" },\n" +
|
||||
" \"boost\" : 42.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
CommonTermsQueryBuilder queryBuilder = (CommonTermsQueryBuilder) parseQuery(query);
|
||||
checkGeneratedJson(query, queryBuilder);
|
||||
|
||||
assertEquals(query, 42, queryBuilder.boost, 0.00001);
|
||||
assertEquals(query, 0.001, queryBuilder.cutoffFrequency(), 0.0001);
|
||||
assertEquals(query, Operator.OR, queryBuilder.lowFreqOperator());
|
||||
assertEquals(query, Operator.AND, queryBuilder.highFreqOperator());
|
||||
assertEquals(query, "nelly the elephant not as a cartoon", queryBuilder.value());
|
||||
}
|
||||
|
||||
public void testNoTermsFromQueryString() throws IOException {
|
||||
CommonTermsQueryBuilder builder = new CommonTermsQueryBuilder(STRING_FIELD_NAME, "");
|
||||
QueryShardContext context = createShardContext();
|
||||
|
|
|
@ -76,4 +76,26 @@ public class ConstantScoreQueryBuilderTests extends AbstractQueryTestCase<Consta
|
|||
public void testUnknownField() throws IOException {
|
||||
assumeTrue("test doesn't apply for query filter queries", false);
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"constant_score\" : {\n" +
|
||||
" \"filter\" : {\n" +
|
||||
" \"terms\" : {\n" +
|
||||
" \"user\" : [ \"kimchy\", \"elasticsearch\" ],\n" +
|
||||
" \"boost\" : 42.0\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"boost\" : 23.0\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
ConstantScoreQueryBuilder parsed = (ConstantScoreQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
|
||||
assertEquals(json, 23.0, parsed.boost(), 0.0001);
|
||||
assertEquals(json, 42.0, parsed.innerQuery().boost(), 0.0001);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -142,4 +142,36 @@ public class DisMaxQueryBuilderTests extends AbstractQueryTestCase<DisMaxQueryBu
|
|||
assertThat(firstQ.getPrefix(), equalTo(new Term(STRING_FIELD_NAME, "sh")));
|
||||
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"dis_max\" : {\n" +
|
||||
" \"tie_breaker\" : 0.7,\n" +
|
||||
" \"queries\" : [ {\n" +
|
||||
" \"term\" : {\n" +
|
||||
" \"age\" : {\n" +
|
||||
" \"value\" : 34,\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }, {\n" +
|
||||
" \"term\" : {\n" +
|
||||
" \"age\" : {\n" +
|
||||
" \"value\" : 35,\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" } ],\n" +
|
||||
" \"boost\" : 1.2\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
DisMaxQueryBuilder parsed = (DisMaxQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
|
||||
assertEquals(json, 1.2, parsed.boost(), 0.0001);
|
||||
assertEquals(json, 0.7, parsed.tieBreaker(), 0.0001);
|
||||
assertEquals(json, 2, parsed.innerQueries().size());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,4 +90,20 @@ public class ExistsQueryBuilderTests extends AbstractQueryTestCase<ExistsQueryBu
|
|||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"exists\" : {\n" +
|
||||
" \"field\" : \"user\",\n" +
|
||||
" \"boost\" : 42.0\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
ExistsQueryBuilder parsed = (ExistsQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
|
||||
assertEquals(json, 42.0, parsed.boost(), 0.0001);
|
||||
assertEquals(json, "user", parsed.fieldName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,4 +74,29 @@ public class FieldMaskingSpanQueryBuilderTests extends AbstractQueryTestCase<Fie
|
|||
// okay
|
||||
}
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"field_masking_span\" : {\n" +
|
||||
" \"query\" : {\n" +
|
||||
" \"span_term\" : {\n" +
|
||||
" \"value\" : {\n" +
|
||||
" \"value\" : 0.5,\n" +
|
||||
" \"boost\" : 0.23\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"field\" : \"mapped_geo_shape\",\n" +
|
||||
" \"boost\" : 42.0,\n" +
|
||||
" \"_name\" : \"KPI\"\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
FieldMaskingSpanQueryBuilder parsed = (FieldMaskingSpanQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
|
||||
assertEquals(json, 42.0, parsed.boost(), 0.00001);
|
||||
assertEquals(json, 0.23, parsed.innerQuery().boost(), 0.00001);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,4 +144,24 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
|
|||
assertThat(fuzzyQuery.getMin().longValue(), equalTo(7l));
|
||||
assertThat(fuzzyQuery.getMax().longValue(), equalTo(17l));
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"fuzzy\" : {\n" +
|
||||
" \"user\" : {\n" +
|
||||
" \"value\" : \"ki\",\n" +
|
||||
" \"fuzziness\" : \"2\",\n" +
|
||||
" \"prefix_length\" : 0,\n" +
|
||||
" \"max_expansions\" : 100,\n" +
|
||||
" \"transpositions\" : false,\n" +
|
||||
" \"boost\" : 42.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
FuzzyQueryBuilder parsed = (FuzzyQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
assertEquals(json, 42.0, parsed.boost(), 0.00001);
|
||||
assertEquals(json, 2, parsed.fuzziness().asInt());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,12 +24,9 @@ import com.spatial4j.core.shape.Rectangle;
|
|||
|
||||
import org.apache.lucene.search.*;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.geo.GeoUtils;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.search.geo.InMemoryGeoBoundingBoxQuery;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.elasticsearch.test.geo.RandomShapeGenerator;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -443,4 +440,28 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|||
assertThat(q.getMaxLon(), closeTo(-80, 1E-5));
|
||||
}
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"geo_bbox\" : {\n" +
|
||||
" \"pin.location\" : {\n" +
|
||||
" \"top_left\" : [ -74.1, 40.73 ],\n" +
|
||||
" \"bottom_right\" : [ -71.12, 40.01 ]\n" +
|
||||
" },\n" +
|
||||
" \"validation_method\" : \"STRICT\",\n" +
|
||||
" \"type\" : \"MEMORY\",\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
GeoBoundingBoxQueryBuilder parsed = (GeoBoundingBoxQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
assertEquals(json, "pin.location", parsed.fieldName());
|
||||
assertEquals(json, -74.1, parsed.topLeft().getLon(), 0.0001);
|
||||
assertEquals(json, 40.73, parsed.topLeft().getLat(), 0.0001);
|
||||
assertEquals(json, -71.12, parsed.bottomRight().getLon(), 0.0001);
|
||||
assertEquals(json, 40.01, parsed.bottomRight().getLat(), 0.0001);
|
||||
assertEquals(json, 1.0, parsed.boost(), 0.0001);
|
||||
assertEquals(json, GeoExecType.MEMORY, parsed.type());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -384,4 +384,23 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
assertThat(q.getRadiusMeters(), closeTo(distanceUnit.convert(distance, DistanceUnit.MILES), 1E-5D));
|
||||
}
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"geo_distance\" : {\n" +
|
||||
" \"pin.location\" : [ -70.0, 40.0 ],\n" +
|
||||
" \"distance\" : 12000.0,\n" +
|
||||
" \"distance_type\" : \"sloppy_arc\",\n" +
|
||||
" \"optimize_bbox\" : \"memory\",\n" +
|
||||
" \"validation_method\" : \"STRICT\",\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
GeoDistanceQueryBuilder parsed = (GeoDistanceQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
assertEquals(json, -70.0, parsed.point().getLon(), 0.0001);
|
||||
assertEquals(json, 40.0, parsed.point().getLat(), 0.0001);
|
||||
assertEquals(json, 12000.0, parsed.distance(), 0.0001);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -295,4 +295,25 @@ public class GeoDistanceRangeQueryTests extends AbstractQueryTestCase<GeoDistanc
|
|||
assertThat(e.getMessage(), is("distance unit must not be null"));
|
||||
}
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"geo_distance_range\" : {\n" +
|
||||
" \"pin.location\" : [ -70.0, 40.0 ],\n" +
|
||||
" \"from\" : \"200km\",\n" +
|
||||
" \"to\" : \"400km\",\n" +
|
||||
" \"include_lower\" : true,\n" +
|
||||
" \"include_upper\" : true,\n" +
|
||||
" \"unit\" : \"m\",\n" +
|
||||
" \"distance_type\" : \"sloppy_arc\",\n" +
|
||||
" \"optimize_bbox\" : \"memory\",\n" +
|
||||
" \"validation_method\" : \"STRICT\",\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
GeoDistanceRangeQueryBuilder parsed = (GeoDistanceRangeQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
assertEquals(json, -70.0, parsed.point().lon(), 0.0001);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -326,4 +326,21 @@ public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase<GeoPolygo
|
|||
assertThat(lons[3], equalTo(lons[0]));
|
||||
}
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"geo_polygon\" : {\n" +
|
||||
" \"person.location\" : {\n" +
|
||||
" \"points\" : [ [ -70.0, 40.0 ], [ -80.0, 30.0 ], [ -90.0, 20.0 ], [ -70.0, 40.0 ] ]\n" +
|
||||
" },\n" +
|
||||
" \"coerce\" : false,\n" +
|
||||
" \"ignore_malformed\" : false,\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
GeoPolygonQueryBuilder parsed = (GeoPolygonQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
assertEquals(json, 4, parsed.points().size());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -222,4 +222,23 @@ public class GeoShapeQueryBuilderTests extends AbstractQueryTestCase<GeoShapeQue
|
|||
GeoShapeQueryBuilder geoQuery = QueryBuilders.geoShapeQuery("searchGeometry", envelopeBuilder);
|
||||
JsonXContent.contentBuilder().startArray().value(geoQuery).endArray();
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"geo_shape\" : {\n" +
|
||||
" \"location\" : {\n" +
|
||||
" \"shape\" : {\n" +
|
||||
" \"type\" : \"envelope\",\n" +
|
||||
" \"coordinates\" : [ [ 13.0, 53.0 ], [ 14.0, 52.0 ] ]\n" +
|
||||
" },\n" +
|
||||
" \"relation\" : \"intersects\"\n" +
|
||||
" },\n" +
|
||||
" \"boost\" : 42.0\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
GeoShapeQueryBuilder parsed = (GeoShapeQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
assertEquals(json, 42.0, parsed.boost(), 0.0001);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,4 +131,19 @@ public class GeohashCellQueryBuilderTests extends AbstractQueryTestCase<Builder>
|
|||
String pointTest3 = "{\"geohash_cell\": {\"pin\": [" + point.getX() + "," + point.getY() + "]}}";
|
||||
assertParsedQuery(pointTest3, pointTestBuilder);
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"geohash_cell\" : {\n" +
|
||||
" \"neighbors\" : true,\n" +
|
||||
" \"precision\" : 3,\n" +
|
||||
" \"pin\" : \"t4mk70fgk067\",\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
GeohashCellQuery.Builder parsed = (GeohashCellQuery.Builder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
assertEquals(json, 3, parsed.precision().intValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.apache.lucene.search.join.ScoreMode;
|
|||
import org.apache.lucene.util.BytesRef;
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
|
@ -197,8 +198,9 @@ public class HasChildQueryBuilderTests extends AbstractQueryTestCase<HasChildQue
|
|||
assertEquals(positiveValue, foo.maxChildren());
|
||||
}
|
||||
|
||||
public void testParseFromJSON() throws IOException {
|
||||
String query = "{\n" +
|
||||
public void testFromJson() throws IOException {
|
||||
String query =
|
||||
"{\n" +
|
||||
" \"has_child\" : {\n" +
|
||||
" \"query\" : {\n" +
|
||||
" \"range\" : {\n" +
|
||||
|
@ -211,7 +213,7 @@ public class HasChildQueryBuilderTests extends AbstractQueryTestCase<HasChildQue
|
|||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"child_type\" : \"child\",\n" +
|
||||
" \"type\" : \"child\",\n" +
|
||||
" \"score_mode\" : \"avg\",\n" +
|
||||
" \"min_children\" : 883170873,\n" +
|
||||
" \"max_children\" : 1217235442,\n" +
|
||||
|
@ -229,6 +231,7 @@ public class HasChildQueryBuilderTests extends AbstractQueryTestCase<HasChildQue
|
|||
" }\n" +
|
||||
"}";
|
||||
HasChildQueryBuilder queryBuilder = (HasChildQueryBuilder) parseQuery(query);
|
||||
checkGeneratedJson(query, queryBuilder);
|
||||
assertEquals(query, queryBuilder.maxChildren(), 1217235442);
|
||||
assertEquals(query, queryBuilder.minChildren(), 883170873);
|
||||
assertEquals(query, queryBuilder.boost(), 2.0f, 0.0f);
|
||||
|
@ -237,38 +240,8 @@ public class HasChildQueryBuilderTests extends AbstractQueryTestCase<HasChildQue
|
|||
assertEquals(query, queryBuilder.scoreMode(), ScoreMode.Avg);
|
||||
assertNotNull(query, queryBuilder.innerHit());
|
||||
assertEquals(query, queryBuilder.innerHit(), new QueryInnerHits("inner_hits_name", new InnerHitsBuilder.InnerHit().setSize(100).addSort("mapped_string", SortOrder.ASC)));
|
||||
// now assert that we actually generate the same JSON
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
|
||||
queryBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
logger.info(msg(query, builder.string()));
|
||||
assertEquals(query, builder.string());
|
||||
}
|
||||
|
||||
private String msg(String left, String right) {
|
||||
int size = Math.min(left.length(), right.length());
|
||||
StringBuilder builder = new StringBuilder("size: " + left.length() + " vs. " + right.length());
|
||||
builder.append(" content: <<");
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (left.charAt(i) == right.charAt(i)) {
|
||||
builder.append(left.charAt(i));
|
||||
} else {
|
||||
builder.append(">> ").append("until offset: ").append(i)
|
||||
.append(" [").append(left.charAt(i)).append(" vs.").append(right.charAt(i))
|
||||
.append("] [").append((int)left.charAt(i) ).append(" vs.").append((int)right.charAt(i)).append(']');
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
if (left.length() != right.length()) {
|
||||
int leftEnd = Math.max(size, left.length()) - 1;
|
||||
int rightEnd = Math.max(size, right.length()) - 1;
|
||||
builder.append(">> ").append("until offset: ").append(size)
|
||||
.append(" [").append(left.charAt(leftEnd)).append(" vs.").append(right.charAt(rightEnd))
|
||||
.append("] [").append((int)left.charAt(leftEnd)).append(" vs.").append((int)right.charAt(rightEnd)).append(']');
|
||||
return builder.toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public void testToQueryInnerQueryType() throws IOException {
|
||||
String[] searchTypes = new String[]{PARENT_TYPE};
|
||||
QueryShardContext.setTypes(searchTypes);
|
||||
|
|
|
@ -242,4 +242,27 @@ public class HasParentQueryBuilderTests extends AbstractQueryTestCase<HasParentQ
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"has_parent\" : {\n" +
|
||||
" \"query\" : {\n" +
|
||||
" \"term\" : {\n" +
|
||||
" \"tag\" : {\n" +
|
||||
" \"value\" : \"something\",\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"parent_type\" : \"blog\",\n" +
|
||||
" \"score\" : true,\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
HasParentQueryBuilder parsed = (HasParentQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
assertEquals(json, "blog", parsed.type());
|
||||
assertEquals(json, "something", ((TermQueryBuilder) parsed.query()).value());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,4 +152,19 @@ public class IdsQueryBuilderTests extends AbstractQueryTestCase<IdsQueryBuilder>
|
|||
assertThat(e.getMessage(), is("Illegal value for id, expecting a string or number, got: START_ARRAY"));
|
||||
}
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"ids\" : {\n" +
|
||||
" \"type\" : [ \"my_type\" ],\n" +
|
||||
" \"values\" : [ \"1\", \"100\", \"4\" ],\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
IdsQueryBuilder parsed = (IdsQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
assertEquals(json, 3, parsed.ids().size());
|
||||
assertEquals(json, "my_type", parsed.types()[0]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,4 +96,35 @@ public class IndicesQueryBuilderTests extends AbstractQueryTestCase<IndicesQuery
|
|||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"indices\" : {\n" +
|
||||
" \"indices\" : [ \"index1\", \"index2\" ],\n" +
|
||||
" \"query\" : {\n" +
|
||||
" \"term\" : {\n" +
|
||||
" \"tag\" : {\n" +
|
||||
" \"value\" : \"wow\",\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"no_match_query\" : {\n" +
|
||||
" \"term\" : {\n" +
|
||||
" \"tag\" : {\n" +
|
||||
" \"value\" : \"kow\",\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
IndicesQueryBuilder parsed = (IndicesQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
assertEquals(json, 2, parsed.indices().length);
|
||||
assertEquals(json, "kow", ((TermQueryBuilder) parsed.noMatchQuery()).value());
|
||||
assertEquals(json, "wow", ((TermQueryBuilder) parsed.innerQuery()).value());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,4 +49,16 @@ public class MatchAllQueryBuilderTests extends AbstractQueryTestCase<MatchAllQue
|
|||
protected void doAssertLuceneQuery(MatchAllQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException {
|
||||
assertThat(query, instanceOf(MatchAllDocsQuery.class));
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"match_all\" : {\n" +
|
||||
" \"boost\" : 1.2\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
MatchAllQueryBuilder parsed = (MatchAllQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
assertEquals(json, 1.2, parsed.boost(), 0.0001);
|
||||
}
|
||||
}
|
|
@ -40,4 +40,16 @@ public class MatchNoneQueryBuilderTests extends AbstractQueryTestCase<MatchNoneQ
|
|||
BooleanQuery booleanQuery = (BooleanQuery) query;
|
||||
assertThat(booleanQuery.clauses().size(), equalTo(0));
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"match_none\" : {\n" +
|
||||
" \"boost\" : 1.2\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
MatchNoneQueryBuilder parsed = (MatchNoneQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
assertEquals(json, 1.2, parsed.boost(), 0.0001);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -235,4 +235,93 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
|
|||
assertThat(e.getMessage(), containsString("analyzer [bogusAnalyzer] not found"));
|
||||
}
|
||||
}
|
||||
|
||||
public void testPhrasePrefixMatchQuery() throws IOException {
|
||||
String json1 = "{\n" +
|
||||
" \"match_phrase_prefix\" : {\n" +
|
||||
" \"message\" : \"this is a test\"\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
String expected = "{\n" +
|
||||
" \"match\" : {\n" +
|
||||
" \"message\" : {\n" +
|
||||
" \"query\" : \"this is a test\",\n" +
|
||||
" \"type\" : \"phrase_prefix\",\n" +
|
||||
" \"operator\" : \"OR\",\n" +
|
||||
" \"slop\" : 0,\n" +
|
||||
" \"prefix_length\" : 0,\n" +
|
||||
" \"max_expansions\" : 50,\n" +
|
||||
" \"fuzzy_transpositions\" : true,\n" +
|
||||
" \"lenient\" : false,\n" +
|
||||
" \"zero_terms_query\" : \"NONE\",\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
MatchQueryBuilder qb = (MatchQueryBuilder) parseQuery(json1);
|
||||
checkGeneratedJson(expected, qb);
|
||||
|
||||
String json2 = "{\n" +
|
||||
" \"match\" : {\n" +
|
||||
" \"message\" : {\n" +
|
||||
" \"query\" : \"this is a test\",\n" +
|
||||
" \"type\" : \"phrase_prefix\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
qb = (MatchQueryBuilder) parseQuery(json2);
|
||||
checkGeneratedJson(expected, qb);
|
||||
|
||||
String json3 = "{\n" +
|
||||
" \"match_phrase_prefix\" : {\n" +
|
||||
" \"message\" : {\n" +
|
||||
" \"query\" : \"this is a test\",\n" +
|
||||
" \"max_expansions\" : 10\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
expected = "{\n" +
|
||||
" \"match\" : {\n" +
|
||||
" \"message\" : {\n" +
|
||||
" \"query\" : \"this is a test\",\n" +
|
||||
" \"type\" : \"phrase_prefix\",\n" +
|
||||
" \"operator\" : \"OR\",\n" +
|
||||
" \"slop\" : 0,\n" +
|
||||
" \"prefix_length\" : 0,\n" +
|
||||
" \"max_expansions\" : 10,\n" +
|
||||
" \"fuzzy_transpositions\" : true,\n" +
|
||||
" \"lenient\" : false,\n" +
|
||||
" \"zero_terms_query\" : \"NONE\",\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
qb = (MatchQueryBuilder) parseQuery(json3);
|
||||
checkGeneratedJson(expected, qb);
|
||||
}
|
||||
|
||||
public void testSimpleMatchQuery() throws IOException {
|
||||
String json = "{\n" +
|
||||
" \"match\" : {\n" +
|
||||
" \"message\" : {\n" +
|
||||
" \"query\" : \"to be or not to be\",\n" +
|
||||
" \"type\" : \"boolean\",\n" +
|
||||
" \"operator\" : \"AND\",\n" +
|
||||
" \"slop\" : 0,\n" +
|
||||
" \"prefix_length\" : 0,\n" +
|
||||
" \"max_expansions\" : 50,\n" +
|
||||
" \"fuzzy_transpositions\" : true,\n" +
|
||||
" \"lenient\" : false,\n" +
|
||||
" \"zero_terms_query\" : \"ALL\",\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
MatchQueryBuilder qb = (MatchQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, qb);
|
||||
|
||||
assertEquals(json, "to be or not to be", qb.value());
|
||||
assertEquals(json, Operator.AND, qb.operator());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,4 +85,23 @@ public class MissingQueryBuilderTests extends AbstractQueryTestCase<MissingQuery
|
|||
assertThat(e.getMessage(), containsString("missing must have either existence, or null_value"));
|
||||
}
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"missing\" : {\n" +
|
||||
" \"field\" : \"user\",\n" +
|
||||
" \"null_value\" : false,\n" +
|
||||
" \"existence\" : true,\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
MissingQueryBuilder parsed = (MissingQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
|
||||
assertEquals(json, false, parsed.nullValue());
|
||||
assertEquals(json, true, parsed.existence());
|
||||
assertEquals(json, "user", parsed.fieldPattern());
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue