Query DSL: Allow for CamelCase field names, closes #134.

This commit is contained in:
kimchy 2010-04-14 11:48:33 +03:00
parent 2d6de97069
commit fcb99b4d9b
19 changed files with 144 additions and 133 deletions

View File

@ -63,7 +63,7 @@ public class BoolJsonFilterParser extends AbstractIndexComponent implements Json
} else if (token == JsonToken.START_OBJECT) {
if ("must".equals(currentFieldName)) {
clauses.add(new FilterClause(parseContext.parseInnerFilter(), BooleanClause.Occur.MUST));
} else if ("must_not".equals(currentFieldName)) {
} else if ("must_not".equals(currentFieldName) || "mustNot".equals(currentFieldName)) {
clauses.add(new FilterClause(parseContext.parseInnerFilter(), BooleanClause.Occur.MUST_NOT));
} else if ("should".equals(currentFieldName)) {
clauses.add(new FilterClause(parseContext.parseInnerFilter(), BooleanClause.Occur.SHOULD));
@ -73,7 +73,7 @@ public class BoolJsonFilterParser extends AbstractIndexComponent implements Json
while ((token = jp.nextToken()) != JsonToken.END_ARRAY) {
clauses.add(new FilterClause(parseContext.parseInnerFilter(), BooleanClause.Occur.MUST));
}
} else if ("must_not".equals(currentFieldName)) {
} else if ("must_not".equals(currentFieldName) || "mustNot".equals(currentFieldName)) {
while ((token = jp.nextToken()) != JsonToken.END_ARRAY) {
clauses.add(new FilterClause(parseContext.parseInnerFilter(), BooleanClause.Occur.MUST_NOT));
}

View File

@ -68,7 +68,7 @@ public class BoolJsonQueryParser extends AbstractIndexComponent implements JsonQ
} else if (token == JsonToken.START_OBJECT) {
if ("must".equals(currentFieldName)) {
clauses.add(new BooleanClause(parseContext.parseInnerQuery(), BooleanClause.Occur.MUST));
} else if ("must_not".equals(currentFieldName)) {
} else if ("must_not".equals(currentFieldName) || "mustNot".equals(currentFieldName)) {
clauses.add(new BooleanClause(parseContext.parseInnerQuery(), BooleanClause.Occur.MUST_NOT));
} else if ("should".equals(currentFieldName)) {
clauses.add(new BooleanClause(parseContext.parseInnerQuery(), BooleanClause.Occur.SHOULD));
@ -78,7 +78,7 @@ public class BoolJsonQueryParser extends AbstractIndexComponent implements JsonQ
while ((token = jp.nextToken()) != JsonToken.END_ARRAY) {
clauses.add(new BooleanClause(parseContext.parseInnerQuery(), BooleanClause.Occur.MUST));
}
} else if ("must_not".equals(currentFieldName)) {
} else if ("must_not".equals(currentFieldName) || "mustNot".equals(currentFieldName)) {
while ((token = jp.nextToken()) != JsonToken.END_ARRAY) {
clauses.add(new BooleanClause(parseContext.parseInnerQuery(), BooleanClause.Occur.MUST_NOT));
}
@ -88,13 +88,13 @@ public class BoolJsonQueryParser extends AbstractIndexComponent implements JsonQ
}
}
} else if (token == JsonToken.VALUE_TRUE || token == JsonToken.VALUE_FALSE) {
if ("disable_coord".equals(currentFieldName)) {
if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) {
disableCoord = token == JsonToken.VALUE_TRUE;
}
} else if (token == JsonToken.VALUE_NUMBER_INT) {
if ("disable_coord".equals(currentFieldName)) {
if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) {
disableCoord = jp.getIntValue() != 0;
} else if ("minimum_number_should_match".equals(currentFieldName)) {
} else if ("minimum_number_should_match".equals(currentFieldName) || "minimumNumberShouldMatch".equals(currentFieldName)) {
minimumNumberShouldMatch = jp.getIntValue();
} else if ("boost".equals(currentFieldName)) {
boost = jp.getIntValue();
@ -104,9 +104,9 @@ public class BoolJsonQueryParser extends AbstractIndexComponent implements JsonQ
boost = jp.getFloatValue();
}
} else if (token == JsonToken.VALUE_STRING) {
if ("disable_coord".equals(currentFieldName)) {
if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) {
disableCoord = Booleans.parseBoolean(jp.getText(), false);
} else if ("minimum_number_should_match".equals(currentFieldName)) {
} else if ("minimum_number_should_match".equals(currentFieldName) || "minimumNumberShouldMatch".equals(currentFieldName)) {
minimumNumberShouldMatch = Integer.parseInt(jp.getText());
} else if ("boost".equals(currentFieldName)) {
boost = Float.parseFloat(jp.getText());

View File

@ -28,6 +28,7 @@ import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.settings.Settings;
import java.io.IOException;
@ -47,7 +48,7 @@ public class DisMaxJsonQueryParser extends AbstractIndexComponent implements Jso
}
@Override public String[] names() {
return new String[]{NAME};
return new String[]{NAME, Strings.toCamelCase(NAME)};
}
@Override public Query parse(JsonQueryParseContext parseContext) throws IOException, QueryParsingException {
@ -81,7 +82,7 @@ public class DisMaxJsonQueryParser extends AbstractIndexComponent implements Jso
} else {
boost = jp.getFloatValue();
}
} else if ("tie_breaker".equals(currentFieldName)) {
} else if ("tie_breaker".equals(currentFieldName) || "tieBreaker".equals(currentFieldName)) {
if (token == JsonToken.VALUE_STRING) {
tieBreaker = Float.parseFloat(jp.getText());
} else {

View File

@ -86,15 +86,15 @@ public class FieldJsonQueryParser extends AbstractIndexComponent implements Json
queryString = jp.getText();
} else if ("boost".equals(currentFieldName)) {
boost = Float.parseFloat(jp.getText());
} else if ("enable_position_increments".equals(currentFieldName)) {
} else if ("enable_position_increments".equals(currentFieldName) || "enablePositionIncrements".equals(currentFieldName)) {
enablePositionIncrements = Booleans.parseBoolean(jp.getText(), true);
} else if ("lowercase_expanded_terms".equals(currentFieldName)) {
} else if ("lowercase_expanded_terms".equals(currentFieldName) || "lowercaseExpandedTerms".equals(currentFieldName)) {
lowercaseExpandedTerms = Booleans.parseBoolean(jp.getText(), true);
} else if ("phrase_slop".equals(currentFieldName)) {
} else if ("phrase_slop".equals(currentFieldName) || "phraseSlop".equals(currentFieldName)) {
phraseSlop = Integer.parseInt(jp.getText());
} else if ("analyzer".equals(currentFieldName)) {
analyzer = analysisService.analyzer(jp.getText());
} else if ("default_operator".equals(currentFieldName)) {
} else if ("default_operator".equals(currentFieldName) || "defaultOperator".equals(currentFieldName)) {
String op = jp.getText();
if ("or".equalsIgnoreCase(op)) {
defaultOperator = QueryParser.Operator.OR;
@ -103,9 +103,9 @@ public class FieldJsonQueryParser extends AbstractIndexComponent implements Json
} else {
throw new QueryParsingException(index, "Query default operator [" + op + "] is not allowed");
}
} else if ("fuzzy_min_sim".equals(currentFieldName)) {
} else if ("fuzzy_min_sim".equals(currentFieldName) || "fuzzyMinSim".equals(currentFieldName)) {
fuzzyMinSim = Float.parseFloat(jp.getText());
} else if ("fuzzy_prefix_length".equals(currentFieldName)) {
} else if ("fuzzy_prefix_length".equals(currentFieldName) || "fuzzyPrefixLength".equals(currentFieldName)) {
fuzzyPrefixLength = Integer.parseInt(jp.getText());
} else if ("escape".equals(currentFieldName)) {
escape = Booleans.parseBoolean(jp.getText(), false);
@ -115,15 +115,15 @@ public class FieldJsonQueryParser extends AbstractIndexComponent implements Json
queryString = jp.getText();
} else if ("boost".equals(currentFieldName)) {
boost = jp.getIntValue();
} else if ("enable_position_increments".equals(currentFieldName)) {
} else if ("enable_position_increments".equals(currentFieldName) || "enablePositionIncrements".equals(currentFieldName)) {
enablePositionIncrements = jp.getIntValue() != 0;
} else if ("lowercase_expanded_terms".equals(currentFieldName)) {
} else if ("lowercase_expanded_terms".equals(currentFieldName) || "lowercaseExpandedTerms".equals(currentFieldName)) {
lowercaseExpandedTerms = jp.getIntValue() != 0;
} else if ("phrase_slop".equals(currentFieldName)) {
} else if ("phrase_slop".equals(currentFieldName) || "phraseSlop".equals(currentFieldName)) {
phraseSlop = jp.getIntValue();
} else if ("fuzzy_min_sim".equals(currentFieldName)) {
} else if ("fuzzy_min_sim".equals(currentFieldName) || "fuzzyMinSim".equals(currentFieldName)) {
fuzzyMinSim = jp.getIntValue();
} else if ("fuzzy_prefix_length".equals(currentFieldName)) {
} else if ("fuzzy_prefix_length".equals(currentFieldName) || "fuzzyPrefixLength".equals(currentFieldName)) {
fuzzyPrefixLength = jp.getIntValue();
} else if ("escape".equals(currentFieldName)) {
escape = jp.getIntValue() != 0;
@ -133,15 +133,15 @@ public class FieldJsonQueryParser extends AbstractIndexComponent implements Json
queryString = jp.getText();
} else if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
} else if ("fuzzy_prefix_length".equals(currentFieldName)) {
} else if ("fuzzy_prefix_length".equals(currentFieldName) || "fuzzyPrefixLength".equals(currentFieldName)) {
fuzzyPrefixLength = jp.getIntValue();
}
} else if (token == JsonToken.VALUE_TRUE) {
if ("query".equals(currentFieldName)) {
queryString = jp.getText();
} else if ("enable_position_increments".equals(currentFieldName)) {
} else if ("enable_position_increments".equals(currentFieldName) || "enablePositionIncrements".equals(currentFieldName)) {
enablePositionIncrements = true;
} else if ("lowercase_expanded_terms".equals(currentFieldName)) {
} else if ("lowercase_expanded_terms".equals(currentFieldName) || "lowercaseExpandedTerms".equals(currentFieldName)) {
lowercaseExpandedTerms = true;
} else if ("escape".equals(currentFieldName)) {
escape = true;
@ -149,9 +149,9 @@ public class FieldJsonQueryParser extends AbstractIndexComponent implements Json
} else if (token == JsonToken.VALUE_FALSE) {
if ("query".equals(currentFieldName)) {
queryString = jp.getText();
} else if ("enable_position_increments".equals(currentFieldName)) {
} else if ("enable_position_increments".equals(currentFieldName) || "enablePositionIncrements".equals(currentFieldName)) {
enablePositionIncrements = false;
} else if ("lowercase_expanded_terms".equals(currentFieldName)) {
} else if ("lowercase_expanded_terms".equals(currentFieldName) || "lowercaseExpandedTerms".equals(currentFieldName)) {
lowercaseExpandedTerms = false;
} else if ("escape".equals(currentFieldName)) {
escape = false;

View File

@ -30,6 +30,7 @@ import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Booleans;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.settings.Settings;
import java.io.IOException;
@ -59,7 +60,7 @@ public class FuzzyLikeThisFieldJsonQueryParser extends AbstractIndexComponent im
}
@Override public String[] names() {
return new String[]{NAME, "fuzzy_like_this_field"};
return new String[]{NAME, "fuzzy_like_this_field", Strings.toCamelCase(NAME), "fuzzyLikeThisField"};
}
@Override public Query parse(JsonQueryParseContext parseContext) throws IOException, QueryParsingException {
@ -86,25 +87,25 @@ public class FuzzyLikeThisFieldJsonQueryParser extends AbstractIndexComponent im
if (token == JsonToken.FIELD_NAME) {
currentFieldName = jp.getCurrentName();
} else if (token == JsonToken.VALUE_STRING) {
if ("like_text".equals(currentFieldName)) {
if ("like_text".equals(currentFieldName) || "likeText".equals(currentFieldName)) {
likeText = jp.getText();
} else if ("max_query_terms".equals(currentFieldName)) {
} else if ("max_query_terms".equals(currentFieldName) || "maxQueryTerms".equals(currentFieldName)) {
maxNumTerms = Integer.parseInt(jp.getText());
} else if ("boost".equals(currentFieldName)) {
boost = Float.parseFloat(jp.getText());
} else if ("ignore_tf".equals(currentFieldName)) {
} else if ("ignore_tf".equals(currentFieldName) || "ignoreTF".equals(currentFieldName)) {
ignoreTF = Booleans.parseBoolean(jp.getText(), false);
}
} else if (token == JsonToken.VALUE_NUMBER_INT) {
if ("max_query_terms".equals(currentFieldName)) {
if ("max_query_terms".equals(currentFieldName) || "maxQueryTerms".equals(currentFieldName)) {
maxNumTerms = jp.getIntValue();
} else if ("boost".equals(currentFieldName)) {
boost = jp.getIntValue();
} else if ("ignore_tf".equals(currentFieldName)) {
} else if ("ignore_tf".equals(currentFieldName) || "ignoreTF".equals(currentFieldName)) {
ignoreTF = jp.getIntValue() != 0;
}
} else if (token == JsonToken.VALUE_TRUE) {
if ("ignore_tf".equals(currentFieldName)) {
if ("ignore_tf".equals(currentFieldName) || "ignoreTF".equals(currentFieldName)) {
ignoreTF = true;
}
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
@ -115,7 +116,7 @@ public class FuzzyLikeThisFieldJsonQueryParser extends AbstractIndexComponent im
}
if (likeText == null) {
throw new QueryParsingException(index, "fuzzy_like_This_field requires 'likeText' to be specified");
throw new QueryParsingException(index, "fuzzy_like_This_field requires 'like_text' to be specified");
}
Analyzer analyzer = null;

View File

@ -58,7 +58,7 @@ public class FuzzyLikeThisJsonQueryParser extends AbstractIndexComponent impleme
}
@Override public String[] names() {
return new String[]{NAME, "fuzzy_like_this"};
return new String[]{NAME, "fuzzy_like_this", "fuzzyLikeThis"};
}
@Override public Query parse(JsonQueryParseContext parseContext) throws IOException, QueryParsingException {
@ -78,25 +78,25 @@ public class FuzzyLikeThisJsonQueryParser extends AbstractIndexComponent impleme
if (token == JsonToken.FIELD_NAME) {
currentFieldName = jp.getCurrentName();
} else if (token == JsonToken.VALUE_STRING) {
if ("like_text".equals(currentFieldName)) {
if ("like_text".equals(currentFieldName) || "likeText".equals(currentFieldName)) {
likeText = jp.getText();
} else if ("max_query_terms".equals(currentFieldName)) {
} else if ("max_query_terms".equals(currentFieldName) || "maxQueryTerms".equals(currentFieldName)) {
maxNumTerms = Integer.parseInt(jp.getText());
} else if ("boost".equals(currentFieldName)) {
boost = Float.parseFloat(jp.getText());
} else if ("ignore_tf".equals(currentFieldName)) {
} else if ("ignore_tf".equals(currentFieldName) || "ignoreTF".equals(currentFieldName)) {
ignoreTF = Booleans.parseBoolean(jp.getText(), false);
}
} else if (token == JsonToken.VALUE_NUMBER_INT) {
if ("max_query_terms".equals(currentFieldName)) {
if ("max_query_terms".equals(currentFieldName) || "maxQueryTerms".equals(currentFieldName)) {
maxNumTerms = jp.getIntValue();
} else if ("boost".equals(currentFieldName)) {
boost = jp.getIntValue();
} else if ("ignore_tf".equals(currentFieldName)) {
} else if ("ignore_tf".equals(currentFieldName) || "ignoreTF".equals(currentFieldName)) {
ignoreTF = jp.getIntValue() != 0;
}
} else if (token == JsonToken.VALUE_TRUE) {
if ("ignore_tf".equals(currentFieldName)) {
if ("ignore_tf".equals(currentFieldName) || "ignoreTF".equals(currentFieldName)) {
ignoreTF = true;
}
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
@ -114,7 +114,7 @@ public class FuzzyLikeThisJsonQueryParser extends AbstractIndexComponent impleme
}
if (likeText == null) {
throw new QueryParsingException(index, "fuzzy_like_this requires 'likeText' to be specified");
throw new QueryParsingException(index, "fuzzy_like_this requires 'like_text' to be specified");
}
FuzzyLikeThisQuery query = new FuzzyLikeThisQuery(maxNumTerms, parseContext.mapperService().searchAnalyzer());

View File

@ -36,7 +36,7 @@ import org.elasticsearch.util.Nullable;
import java.io.IOException;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class JsonQueryParseContext {

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.query.json;
import com.google.common.collect.ImmutableMap;
import org.apache.lucene.util.StringHelper;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.settings.IndexSettings;
@ -103,13 +104,13 @@ public class JsonQueryParserRegistry {
private void add(Map<String, JsonFilterParser> map, JsonFilterParser filterParser) {
for (String name : filterParser.names()) {
map.put(name, filterParser);
map.put(StringHelper.intern(name), filterParser);
}
}
private void add(Map<String, JsonQueryParser> map, JsonQueryParser jsonQueryParser) {
for (String name : jsonQueryParser.names()) {
map.put(name, jsonQueryParser);
map.put(StringHelper.intern(name), jsonQueryParser);
}
}
}

View File

@ -28,6 +28,7 @@ import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.settings.Settings;
import java.io.IOException;
@ -44,7 +45,7 @@ public class MatchAllJsonQueryParser extends AbstractIndexComponent implements J
}
@Override public String[] names() {
return new String[]{NAME};
return new String[]{NAME, Strings.toCamelCase(NAME)};
}
@Override public Query parse(JsonQueryParseContext parseContext) throws IOException, QueryParsingException {
@ -61,7 +62,7 @@ public class MatchAllJsonQueryParser extends AbstractIndexComponent implements J
} else if (token == JsonToken.VALUE_STRING) {
if ("boost".equals(currentFieldName)) {
boost = Float.parseFloat(jp.getText());
} else if ("norms_field".equals(currentFieldName)) {
} else if ("norms_field".equals(currentFieldName) || "normsField".equals(currentFieldName)) {
normsField = parseContext.indexName(jp.getText());
}
} else {

View File

@ -28,6 +28,7 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.lucene.search.MoreLikeThisQuery;
import org.elasticsearch.util.settings.Settings;
@ -48,7 +49,7 @@ public class MoreLikeThisFieldJsonQueryParser extends AbstractIndexComponent imp
}
@Override public String[] names() {
return new String[]{NAME, "more_like_this_field"};
return new String[]{NAME, "more_like_this_field", Strings.toCamelCase(NAME), "moreLikeThisField"};
}
@Override public Query parse(JsonQueryParseContext parseContext) throws IOException, QueryParsingException {
@ -73,56 +74,56 @@ public class MoreLikeThisFieldJsonQueryParser extends AbstractIndexComponent imp
} else if (token == JsonToken.VALUE_STRING) {
if ("like_text".equals(currentFieldName)) {
mltQuery.setLikeText(jp.getText());
} else if ("min_term_freq".equals(currentFieldName)) {
} else if ("min_term_freq".equals(currentFieldName) || "minTermFreq".equals(currentFieldName)) {
mltQuery.setMinTermFrequency(Integer.parseInt(jp.getText()));
} else if ("max_query_terms".equals(currentFieldName)) {
} else if ("max_query_terms".equals(currentFieldName) || "maxQueryTerms".equals(currentFieldName)) {
mltQuery.setMaxQueryTerms(Integer.parseInt(jp.getText()));
} else if ("min_doc_freq".equals(currentFieldName)) {
} else if ("min_doc_freq".equals(currentFieldName) || "minDocFreq".equals(currentFieldName)) {
mltQuery.setMinDocFreq(Integer.parseInt(jp.getText()));
} else if ("max_doc_freq".equals(currentFieldName)) {
} else if ("max_doc_freq".equals(currentFieldName) || "maxDocFreq".equals(currentFieldName)) {
mltQuery.setMaxDocFreq(Integer.parseInt(jp.getText()));
} else if ("min_word_len".equals(currentFieldName)) {
} else if ("min_word_len".equals(currentFieldName) || "minWordLen".equals(currentFieldName)) {
mltQuery.setMinWordLen(Integer.parseInt(jp.getText()));
} else if ("max_word_len".equals(currentFieldName)) {
} else if ("max_word_len".equals(currentFieldName) || "maxWordLen".equals(currentFieldName)) {
mltQuery.setMaxWordLen(Integer.parseInt(jp.getText()));
} else if ("boost_terms".equals(currentFieldName)) {
} else if ("boost_terms".equals(currentFieldName) || "boostTerms".equals(currentFieldName)) {
mltQuery.setBoostTerms(true);
mltQuery.setBoostTermsFactor(Float.parseFloat(jp.getText()));
} else if ("percent_terms_to_match".equals(currentFieldName)) {
} else if ("percent_terms_to_match".equals(currentFieldName) || "percentTermsToMatch".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(Float.parseFloat(jp.getText()));
}
} else if (token == JsonToken.VALUE_NUMBER_INT) {
if ("min_term_freq".equals(currentFieldName)) {
if ("min_term_freq".equals(currentFieldName) || "minTermFreq".equals(currentFieldName)) {
mltQuery.setMinTermFrequency(jp.getIntValue());
} else if ("max_query_terms".equals(currentFieldName)) {
} else if ("max_query_terms".equals(currentFieldName) || "maxQueryTerms".equals(currentFieldName)) {
mltQuery.setMaxQueryTerms(jp.getIntValue());
} else if ("min_doc_freq".equals(currentFieldName)) {
} else if ("min_doc_freq".equals(currentFieldName) || "minDocFreq".equals(currentFieldName)) {
mltQuery.setMinDocFreq(jp.getIntValue());
} else if ("max_doc_freq".equals(currentFieldName)) {
} else if ("max_doc_freq".equals(currentFieldName) || "maxDocFreq".equals(currentFieldName)) {
mltQuery.setMaxDocFreq(jp.getIntValue());
} else if ("min_word_len".equals(currentFieldName)) {
} else if ("min_word_len".equals(currentFieldName) || "minWordLen".equals(currentFieldName)) {
mltQuery.setMinWordLen(jp.getIntValue());
} else if ("max_word_len".equals(currentFieldName)) {
} else if ("max_word_len".equals(currentFieldName) || "maxWordLen".equals(currentFieldName)) {
mltQuery.setMaxWordLen(jp.getIntValue());
} else if ("boost_term".equals(currentFieldName)) {
} else if ("boost_terms".equals(currentFieldName) || "boostTerms".equals(currentFieldName)) {
mltQuery.setBoostTerms(true);
mltQuery.setBoostTermsFactor(jp.getIntValue());
} else if ("percent_terms_to_match".equals(currentFieldName)) {
} else if ("percent_terms_to_match".equals(currentFieldName) || "percentTermsToMatch".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(jp.getIntValue());
} else if ("boost".equals(currentFieldName)) {
mltQuery.setBoost(jp.getIntValue());
}
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
if ("boost_terms".equals(currentFieldName)) {
if ("boost_terms".equals(currentFieldName) || "boostTerms".equals(currentFieldName)) {
mltQuery.setBoostTerms(true);
mltQuery.setBoostTermsFactor(jp.getFloatValue());
} else if ("percent_terms_to_match".equals(currentFieldName)) {
} else if ("percent_terms_to_match".equals(currentFieldName) || "percentTermsToMatch".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(jp.getFloatValue());
} else if ("boost".equals(currentFieldName)) {
mltQuery.setBoost(jp.getFloatValue());
}
} else if (token == JsonToken.START_ARRAY) {
if ("stop_words".equals(currentFieldName)) {
if ("stop_words".equals(currentFieldName) || "stopWords".equals(currentFieldName)) {
Set<String> stopWords = Sets.newHashSet();
while ((token = jp.nextToken()) != JsonToken.END_ARRAY) {
stopWords.add(jp.getText());

View File

@ -49,7 +49,7 @@ public class MoreLikeThisJsonQueryParser extends AbstractIndexComponent implemen
}
@Override public String[] names() {
return new String[]{NAME, "more_like_this"};
return new String[]{NAME, "more_like_this", "moreLikeThis"};
}
@Override public Query parse(JsonQueryParseContext parseContext) throws IOException, QueryParsingException {
@ -65,58 +65,58 @@ public class MoreLikeThisJsonQueryParser extends AbstractIndexComponent implemen
if (token == JsonToken.FIELD_NAME) {
currentFieldName = jp.getCurrentName();
} else if (token == JsonToken.VALUE_STRING) {
if ("like_text".equals(currentFieldName)) {
if ("like_text".equals(currentFieldName) || "likeText".equals(currentFieldName)) {
mltQuery.setLikeText(jp.getText());
} else if ("min_term_freq".equals(currentFieldName)) {
} else if ("min_term_freq".equals(currentFieldName) || "minTermFreq".equals(currentFieldName)) {
mltQuery.setMinTermFrequency(Integer.parseInt(jp.getText()));
} else if ("max_query_terms".equals(currentFieldName)) {
} else if ("max_query_terms".equals(currentFieldName) || "maxQueryTerms".equals(currentFieldName)) {
mltQuery.setMaxQueryTerms(Integer.parseInt(jp.getText()));
} else if ("min_doc_freq".equals(currentFieldName)) {
} else if ("min_doc_freq".equals(currentFieldName) || "minDocFreq".equals(currentFieldName)) {
mltQuery.setMinDocFreq(Integer.parseInt(jp.getText()));
} else if ("max_doc_freq".equals(currentFieldName)) {
} else if ("max_doc_freq".equals(currentFieldName) || "maxDocFreq".equals(currentFieldName)) {
mltQuery.setMaxDocFreq(Integer.parseInt(jp.getText()));
} else if ("min_word_len".equals(currentFieldName)) {
} else if ("min_word_len".equals(currentFieldName) || "minWordLen".equals(currentFieldName)) {
mltQuery.setMinWordLen(Integer.parseInt(jp.getText()));
} else if ("max_word_len".equals(currentFieldName)) {
} else if ("max_word_len".equals(currentFieldName) || "maxWordLen".equals(currentFieldName)) {
mltQuery.setMaxWordLen(Integer.parseInt(jp.getText()));
} else if ("boost_terms".equals(currentFieldName)) {
} else if ("boost_terms".equals(currentFieldName) || "boostTerms".equals(currentFieldName)) {
mltQuery.setBoostTerms(true);
mltQuery.setBoostTermsFactor(Float.parseFloat(jp.getText()));
} else if ("percent_terms_to_match".equals(currentFieldName)) {
} else if ("percent_terms_to_match".equals(currentFieldName) || "percentTermsToMatch".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(Float.parseFloat(jp.getText()));
}
} else if (token == JsonToken.VALUE_NUMBER_INT) {
if ("min_term_freq".equals(currentFieldName)) {
if ("min_term_freq".equals(currentFieldName) || "minTermFreq".equals(currentFieldName)) {
mltQuery.setMinTermFrequency(jp.getIntValue());
} else if ("max_query_terms".equals(currentFieldName)) {
} else if ("max_query_terms".equals(currentFieldName) || "maxQueryTerms".equals(currentFieldName)) {
mltQuery.setMaxQueryTerms(jp.getIntValue());
} else if ("min_doc_freq".equals(currentFieldName)) {
} else if ("min_doc_freq".equals(currentFieldName) || "minDocFreq".equals(currentFieldName)) {
mltQuery.setMinDocFreq(jp.getIntValue());
} else if ("max_doc_freq".equals(currentFieldName)) {
} else if ("max_doc_freq".equals(currentFieldName) || "maxDocFreq".equals(currentFieldName)) {
mltQuery.setMaxDocFreq(jp.getIntValue());
} else if ("min_word_len".equals(currentFieldName)) {
} else if ("min_word_len".equals(currentFieldName) || "minWordLen".equals(currentFieldName)) {
mltQuery.setMinWordLen(jp.getIntValue());
} else if ("max_word_len".equals(currentFieldName)) {
} else if ("max_word_len".equals(currentFieldName) || "maxWordLen".equals(currentFieldName)) {
mltQuery.setMaxWordLen(jp.getIntValue());
} else if ("boost_terms".equals(currentFieldName)) {
} else if ("boost_terms".equals(currentFieldName) || "boostTerms".equals(currentFieldName)) {
mltQuery.setBoostTerms(true);
mltQuery.setBoostTermsFactor(jp.getIntValue());
} else if ("percent_terms_to_match".equals(currentFieldName)) {
} else if ("percent_terms_to_match".equals(currentFieldName) || "percentTermsToMatch".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(jp.getIntValue());
} else if ("boost".equals(currentFieldName)) {
mltQuery.setBoost(jp.getIntValue());
}
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
if ("boost_terms".equals(currentFieldName)) {
if ("boost_terms".equals(currentFieldName) || "boostTerms".equals(currentFieldName)) {
mltQuery.setBoostTerms(true);
mltQuery.setBoostTermsFactor(jp.getFloatValue());
} else if ("percent_terms_to_match".equals(currentFieldName)) {
} else if ("percent_terms_to_match".equals(currentFieldName) || "percentTermsToMatch".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(jp.getFloatValue());
} else if ("boost".equals(currentFieldName)) {
mltQuery.setBoost(jp.getFloatValue());
}
} else if (token == JsonToken.START_ARRAY) {
if ("stop_words".equals(currentFieldName)) {
if ("stop_words".equals(currentFieldName) || "stopWords".equals(currentFieldName)) {
Set<String> stopWords = Sets.newHashSet();
while ((token = jp.nextToken()) != JsonToken.END_ARRAY) {
stopWords.add(jp.getText());

View File

@ -37,6 +37,7 @@ import org.elasticsearch.index.query.support.MapperQueryParser;
import org.elasticsearch.index.query.support.MultiFieldMapperQueryParser;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Booleans;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.trove.ExtTObjectFloatHashMap;
@ -60,7 +61,7 @@ public class QueryStringJsonQueryParser extends AbstractIndexComponent implement
}
@Override public String[] names() {
return new String[]{NAME};
return new String[]{NAME, Strings.toCamelCase(NAME)};
}
@Override public Query parse(JsonQueryParseContext parseContext) throws IOException, QueryParsingException {
@ -123,9 +124,9 @@ public class QueryStringJsonQueryParser extends AbstractIndexComponent implement
} else if (token == JsonToken.VALUE_STRING) {
if ("query".equals(currentFieldName)) {
queryString = jp.getText();
} else if ("default_field".equals(currentFieldName)) {
} else if ("default_field".equals(currentFieldName) || "defaultField".equals(currentFieldName)) {
defaultField = parseContext.indexName(jp.getText());
} else if ("default_operator".equals(currentFieldName)) {
} else if ("default_operator".equals(currentFieldName) || "defaultOperator".equals(currentFieldName)) {
String op = jp.getText();
if ("or".equalsIgnoreCase(op)) {
defaultOperator = QueryParser.Operator.OR;
@ -136,67 +137,67 @@ public class QueryStringJsonQueryParser extends AbstractIndexComponent implement
}
} else if ("analyzer".equals(currentFieldName)) {
analyzer = analysisService.analyzer(jp.getText());
} else if ("allow_leading_wildcard".equals(currentFieldName)) {
} else if ("allow_leading_wildcard".equals(currentFieldName) || "allowLeadingWildcard".equals(currentFieldName)) {
allowLeadingWildcard = Booleans.parseBoolean(jp.getText(), false);
} else if ("lowercase_expanded_terms".equals(currentFieldName)) {
} else if ("lowercase_expanded_terms".equals(currentFieldName) || "lowercaseExpandedTerms".equals(currentFieldName)) {
lowercaseExpandedTerms = Booleans.parseBoolean(jp.getText(), false);
} else if ("enable_position_increments".equals(currentFieldName)) {
} else if ("enable_position_increments".equals(currentFieldName) || "enablePositionIncrements".equals(currentFieldName)) {
enablePositionIncrements = Booleans.parseBoolean(jp.getText(), false);
} else if ("escape".equals(currentFieldName)) {
escape = Booleans.parseBoolean(jp.getText(), false);
} else if ("use_dis_max".equals(currentFieldName)) {
} else if ("use_dis_max".equals(currentFieldName) || "useDisMax".equals(currentFieldName)) {
useDisMax = Booleans.parseBoolean(jp.getText(), false);
} else if ("fuzzy_prefix_length".equals(currentFieldName)) {
} else if ("fuzzy_prefix_length".equals(currentFieldName) || "fuzzyPrefixLength".equals(currentFieldName)) {
fuzzyPrefixLength = Integer.parseInt(jp.getText());
} else if ("phrase_slop".equals(currentFieldName)) {
} else if ("phrase_slop".equals(currentFieldName) || "phraseSlop".equals(currentFieldName)) {
phraseSlop = Integer.parseInt(jp.getText());
} else if ("fuzzy_min_sim".equals(currentFieldName)) {
} else if ("fuzzy_min_sim".equals(currentFieldName) || "fuzzyMinSim".equals(currentFieldName)) {
fuzzyMinSim = Float.parseFloat(jp.getText());
} else if ("boost".equals(currentFieldName)) {
boost = Float.parseFloat(jp.getText());
} else if ("tie_breaker".equals(currentFieldName)) {
} else if ("tie_breaker".equals(currentFieldName) || "tieBreaker".equals(currentFieldName)) {
tieBreaker = Float.parseFloat(jp.getText());
}
} else if (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE) {
if ("allow_leading_wildcard".equals(currentFieldName)) {
if ("allow_leading_wildcard".equals(currentFieldName) || "allowLeadingWildcards".equals(currentFieldName)) {
allowLeadingWildcard = token == JsonToken.VALUE_TRUE;
} else if ("lowercase_expanded_terms".equals(currentFieldName)) {
} else if ("lowercase_expanded_terms".equals(currentFieldName) || "lowercaseExpandedTerms".equals(currentFieldName)) {
lowercaseExpandedTerms = token == JsonToken.VALUE_TRUE;
} else if ("enable_position_increments".equals(currentFieldName)) {
} else if ("enable_position_increments".equals(currentFieldName) || "enablePositionIncrements".equals(currentFieldName)) {
enablePositionIncrements = token == JsonToken.VALUE_TRUE;
} else if ("escape".equals(currentFieldName)) {
escape = token == JsonToken.VALUE_TRUE;
} else if ("use_dis_max".equals(currentFieldName)) {
} else if ("use_dis_max".equals(currentFieldName) || "useDisMax".equals(currentFieldName)) {
useDisMax = token == JsonToken.VALUE_TRUE;
}
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
if ("fuzzy_min_sim".equals(currentFieldName)) {
if ("fuzzy_min_sim".equals(currentFieldName) || "fuzzyMinSim".equals(currentFieldName)) {
fuzzyMinSim = jp.getFloatValue();
} else if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
} else if ("tie_breaker".equals(currentFieldName)) {
} else if ("tie_breaker".equals(currentFieldName) || "tieBreaker".equals(currentFieldName)) {
tieBreaker = jp.getFloatValue();
}
} else if (token == JsonToken.VALUE_NUMBER_INT) {
if ("fuzzy_prefix_length".equals(currentFieldName)) {
if ("fuzzy_prefix_length".equals(currentFieldName) || "fuzzyPrefixLength".equals(currentFieldName)) {
fuzzyPrefixLength = jp.getIntValue();
} else if ("phrase_slop".equals(currentFieldName)) {
} else if ("phrase_slop".equals(currentFieldName) || "phraseSlop".equals(currentFieldName)) {
phraseSlop = jp.getIntValue();
} else if ("fuzzy_min_sim".equals(currentFieldName)) {
} else if ("fuzzy_min_sim".equals(currentFieldName) || "fuzzyMinSim".equals(currentFieldName)) {
fuzzyMinSim = jp.getFloatValue();
} else if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
} else if ("allow_leading_wildcard".equals(currentFieldName)) {
} else if ("allow_leading_wildcard".equals(currentFieldName) || "allowLeadingWildcard".equals(currentFieldName)) {
allowLeadingWildcard = jp.getIntValue() != 0;
} else if ("lowercase_expanded_terms".equals(currentFieldName)) {
} else if ("lowercase_expanded_terms".equals(currentFieldName) || "lowercaseExpandedTerms".equals(currentFieldName)) {
lowercaseExpandedTerms = jp.getIntValue() != 0;
} else if ("enable_position_increments".equals(currentFieldName)) {
} else if ("enable_position_increments".equals(currentFieldName) || "enablePositionIncrements".equals(currentFieldName)) {
enablePositionIncrements = jp.getIntValue() != 0;
} else if ("escape".equals(currentFieldName)) {
escape = jp.getIntValue() != 0;
} else if ("use_dis_max".equals(currentFieldName)) {
} else if ("use_dis_max".equals(currentFieldName) || "useDisMax".equals(currentFieldName)) {
useDisMax = jp.getIntValue() != 0;
} else if ("tie_breaker".equals(currentFieldName)) {
} else if ("tie_breaker".equals(currentFieldName) || "tieBreaker".equals(currentFieldName)) {
tieBreaker = jp.getFloatValue();
}
}

View File

@ -84,7 +84,7 @@ public class RangeJsonFilterParser extends AbstractIndexComponent implements Jso
} else {
to = jp.getText();
}
} else if ("include_lower".equals(currentFieldName)) {
} else if ("include_lower".equals(currentFieldName) || "includeLower".equals(currentFieldName)) {
if (token == JsonToken.VALUE_NUMBER_INT) {
includeLower = jp.getIntValue() != 0;
} else if (token == JsonToken.VALUE_STRING) {
@ -92,7 +92,7 @@ public class RangeJsonFilterParser extends AbstractIndexComponent implements Jso
} else {
includeLower = token == JsonToken.VALUE_TRUE;
}
} else if ("include_upper".equals(currentFieldName)) {
} else if ("include_upper".equals(currentFieldName) || "includeUpper".equals(currentFieldName)) {
if (token == JsonToken.VALUE_NUMBER_INT) {
includeUpper = jp.getIntValue() != 0;
} else if (token == JsonToken.VALUE_STRING) {
@ -107,7 +107,7 @@ public class RangeJsonFilterParser extends AbstractIndexComponent implements Jso
from = jp.getText();
}
includeLower = false;
} else if ("gte".equals(currentFieldName)) {
} else if ("gte".equals(currentFieldName) || "ge".equals(currentFieldName)) {
if (jp.getCurrentToken() == JsonToken.VALUE_NULL) {
from = null;
} else {
@ -121,7 +121,7 @@ public class RangeJsonFilterParser extends AbstractIndexComponent implements Jso
to = jp.getText();
}
includeUpper = false;
} else if ("lte".equals(currentFieldName)) {
} else if ("lte".equals(currentFieldName) || "le".equals(currentFieldName)) {
if (jp.getCurrentToken() == JsonToken.VALUE_NULL) {
to = null;
} else {

View File

@ -81,7 +81,7 @@ public class RangeJsonQueryParser extends AbstractIndexComponent implements Json
} else {
to = jp.getText();
}
} else if ("include_lower".equals(currentFieldName)) {
} else if ("include_lower".equals(currentFieldName) || "includeLower".equals(currentFieldName)) {
if (token == JsonToken.VALUE_NUMBER_INT) {
includeLower = jp.getIntValue() != 0;
} else if (token == JsonToken.VALUE_STRING) {
@ -89,7 +89,7 @@ public class RangeJsonQueryParser extends AbstractIndexComponent implements Json
} else {
includeLower = token == JsonToken.VALUE_TRUE;
}
} else if ("include_upper".equals(currentFieldName)) {
} else if ("include_upper".equals(currentFieldName) || "includeUpper".equals(currentFieldName)) {
if (token == JsonToken.VALUE_NUMBER_INT) {
includeUpper = jp.getIntValue() != 0;
} else if (token == JsonToken.VALUE_STRING) {
@ -110,7 +110,7 @@ public class RangeJsonQueryParser extends AbstractIndexComponent implements Json
from = jp.getText();
}
includeLower = false;
} else if ("gte".equals(currentFieldName)) {
} else if ("gte".equals(currentFieldName) || "ge".equals(currentFieldName)) {
if (jp.getCurrentToken() == JsonToken.VALUE_NULL) {
from = null;
} else {
@ -124,7 +124,7 @@ public class RangeJsonQueryParser extends AbstractIndexComponent implements Json
to = jp.getText();
}
includeUpper = false;
} else if ("lte".equals(currentFieldName)) {
} else if ("lte".equals(currentFieldName) || "le".equals(currentFieldName)) {
if (jp.getCurrentToken() == JsonToken.VALUE_NULL) {
to = null;
} else {

View File

@ -29,6 +29,7 @@ import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.settings.Settings;
import java.io.IOException;
@ -45,7 +46,7 @@ public class SpanFirstJsonQueryParser extends AbstractIndexComponent implements
}
@Override public String[] names() {
return new String[]{NAME};
return new String[]{NAME, Strings.toCamelCase(NAME)};
}
@Override public Query parse(JsonQueryParseContext parseContext) throws IOException, QueryParsingException {

View File

@ -30,6 +30,7 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Booleans;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.settings.Settings;
import java.io.IOException;
@ -49,7 +50,7 @@ public class SpanNearJsonQueryParser extends AbstractIndexComponent implements J
}
@Override public String[] names() {
return new String[]{NAME};
return new String[]{NAME, Strings.toCamelCase(NAME)};
}
@Override public Query parse(JsonQueryParseContext parseContext) throws IOException, QueryParsingException {
@ -78,9 +79,9 @@ public class SpanNearJsonQueryParser extends AbstractIndexComponent implements J
}
}
} else if (token == JsonToken.VALUE_STRING) {
if ("in_order".equals(currentFieldName)) {
if ("in_order".equals(currentFieldName) || "inOrder".equals(currentFieldName)) {
inOrder = Booleans.parseBoolean(jp.getText(), inOrder);
} else if ("collect_payloads".equals(currentFieldName)) {
} else if ("collect_payloads".equals(currentFieldName) || "collectPayloads".equals(currentFieldName)) {
collectPayloads = Booleans.parseBoolean(jp.getText(), collectPayloads);
} else if ("slop".equals(currentFieldName)) {
slop = Integer.parseInt(jp.getText());
@ -88,15 +89,15 @@ public class SpanNearJsonQueryParser extends AbstractIndexComponent implements J
boost = Float.parseFloat(jp.getText());
}
} else if (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE) {
if ("in_order".equals(currentFieldName)) {
if ("in_order".equals(currentFieldName) || "inOrder".equals(currentFieldName)) {
inOrder = token == JsonToken.VALUE_TRUE;
} else if ("collect_payloads".equals(currentFieldName)) {
} else if ("collect_payloads".equals(currentFieldName) || "collectPayloads".equals(currentFieldName)) {
collectPayloads = token == JsonToken.VALUE_TRUE;
}
} else if (token == JsonToken.VALUE_NUMBER_INT) {
if ("in_order".equals(currentFieldName)) {
if ("in_order".equals(currentFieldName) || "inOrder".equals(currentFieldName)) {
inOrder = jp.getIntValue() != 0;
} else if ("collect_payloads".equals(currentFieldName)) {
} else if ("collect_payloads".equals(currentFieldName) || "collectPayloads".equals(currentFieldName)) {
collectPayloads = jp.getIntValue() != 0;
} else if ("slop".equals(currentFieldName)) {
slop = jp.getIntValue();

View File

@ -29,6 +29,7 @@ import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.settings.Settings;
import java.io.IOException;
@ -45,7 +46,7 @@ public class SpanNotJsonQueryParser extends AbstractIndexComponent implements Js
}
@Override public String[] names() {
return new String[]{NAME};
return new String[]{NAME, Strings.toCamelCase(NAME)};
}
@Override public Query parse(JsonQueryParseContext parseContext) throws IOException, QueryParsingException {

View File

@ -29,6 +29,7 @@ import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.settings.Settings;
import java.io.IOException;
@ -48,7 +49,7 @@ public class SpanOrJsonQueryParser extends AbstractIndexComponent implements Jso
}
@Override public String[] names() {
return new String[]{NAME};
return new String[]{NAME, Strings.toCamelCase(NAME)};
}
@Override public Query parse(JsonQueryParseContext parseContext) throws IOException, QueryParsingException {

View File

@ -30,6 +30,7 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.settings.Settings;
import java.io.IOException;
@ -48,7 +49,7 @@ public class SpanTermJsonQueryParser extends AbstractIndexComponent implements J
}
@Override public String[] names() {
return new String[]{NAME};
return new String[]{NAME, Strings.toCamelCase(NAME)};
}
@Override public Query parse(JsonQueryParseContext parseContext) throws IOException, QueryParsingException {