Skip to content

Commit fcb99b4

Browse files
committed
Query DSL: Allow for CamelCase field names, closes #134.
1 parent 2d6de97 commit fcb99b4

19 files changed

+144
-133
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/BoolJsonFilterParser.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class BoolJsonFilterParser extends AbstractIndexComponent implements Json
6363
} else if (token == JsonToken.START_OBJECT) {
6464
if ("must".equals(currentFieldName)) {
6565
clauses.add(new FilterClause(parseContext.parseInnerFilter(), BooleanClause.Occur.MUST));
66-
} else if ("must_not".equals(currentFieldName)) {
66+
} else if ("must_not".equals(currentFieldName) || "mustNot".equals(currentFieldName)) {
6767
clauses.add(new FilterClause(parseContext.parseInnerFilter(), BooleanClause.Occur.MUST_NOT));
6868
} else if ("should".equals(currentFieldName)) {
6969
clauses.add(new FilterClause(parseContext.parseInnerFilter(), BooleanClause.Occur.SHOULD));
@@ -73,7 +73,7 @@ public class BoolJsonFilterParser extends AbstractIndexComponent implements Json
7373
while ((token = jp.nextToken()) != JsonToken.END_ARRAY) {
7474
clauses.add(new FilterClause(parseContext.parseInnerFilter(), BooleanClause.Occur.MUST));
7575
}
76-
} else if ("must_not".equals(currentFieldName)) {
76+
} else if ("must_not".equals(currentFieldName) || "mustNot".equals(currentFieldName)) {
7777
while ((token = jp.nextToken()) != JsonToken.END_ARRAY) {
7878
clauses.add(new FilterClause(parseContext.parseInnerFilter(), BooleanClause.Occur.MUST_NOT));
7979
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/BoolJsonQueryParser.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class BoolJsonQueryParser extends AbstractIndexComponent implements JsonQ
6868
} else if (token == JsonToken.START_OBJECT) {
6969
if ("must".equals(currentFieldName)) {
7070
clauses.add(new BooleanClause(parseContext.parseInnerQuery(), BooleanClause.Occur.MUST));
71-
} else if ("must_not".equals(currentFieldName)) {
71+
} else if ("must_not".equals(currentFieldName) || "mustNot".equals(currentFieldName)) {
7272
clauses.add(new BooleanClause(parseContext.parseInnerQuery(), BooleanClause.Occur.MUST_NOT));
7373
} else if ("should".equals(currentFieldName)) {
7474
clauses.add(new BooleanClause(parseContext.parseInnerQuery(), BooleanClause.Occur.SHOULD));
@@ -78,7 +78,7 @@ public class BoolJsonQueryParser extends AbstractIndexComponent implements JsonQ
7878
while ((token = jp.nextToken()) != JsonToken.END_ARRAY) {
7979
clauses.add(new BooleanClause(parseContext.parseInnerQuery(), BooleanClause.Occur.MUST));
8080
}
81-
} else if ("must_not".equals(currentFieldName)) {
81+
} else if ("must_not".equals(currentFieldName) || "mustNot".equals(currentFieldName)) {
8282
while ((token = jp.nextToken()) != JsonToken.END_ARRAY) {
8383
clauses.add(new BooleanClause(parseContext.parseInnerQuery(), BooleanClause.Occur.MUST_NOT));
8484
}
@@ -88,13 +88,13 @@ public class BoolJsonQueryParser extends AbstractIndexComponent implements JsonQ
8888
}
8989
}
9090
} else if (token == JsonToken.VALUE_TRUE || token == JsonToken.VALUE_FALSE) {
91-
if ("disable_coord".equals(currentFieldName)) {
91+
if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) {
9292
disableCoord = token == JsonToken.VALUE_TRUE;
9393
}
9494
} else if (token == JsonToken.VALUE_NUMBER_INT) {
95-
if ("disable_coord".equals(currentFieldName)) {
95+
if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) {
9696
disableCoord = jp.getIntValue() != 0;
97-
} else if ("minimum_number_should_match".equals(currentFieldName)) {
97+
} else if ("minimum_number_should_match".equals(currentFieldName) || "minimumNumberShouldMatch".equals(currentFieldName)) {
9898
minimumNumberShouldMatch = jp.getIntValue();
9999
} else if ("boost".equals(currentFieldName)) {
100100
boost = jp.getIntValue();
@@ -104,9 +104,9 @@ public class BoolJsonQueryParser extends AbstractIndexComponent implements JsonQ
104104
boost = jp.getFloatValue();
105105
}
106106
} else if (token == JsonToken.VALUE_STRING) {
107-
if ("disable_coord".equals(currentFieldName)) {
107+
if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) {
108108
disableCoord = Booleans.parseBoolean(jp.getText(), false);
109-
} else if ("minimum_number_should_match".equals(currentFieldName)) {
109+
} else if ("minimum_number_should_match".equals(currentFieldName) || "minimumNumberShouldMatch".equals(currentFieldName)) {
110110
minimumNumberShouldMatch = Integer.parseInt(jp.getText());
111111
} else if ("boost".equals(currentFieldName)) {
112112
boost = Float.parseFloat(jp.getText());

modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/DisMaxJsonQueryParser.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.index.Index;
2929
import org.elasticsearch.index.query.QueryParsingException;
3030
import org.elasticsearch.index.settings.IndexSettings;
31+
import org.elasticsearch.util.Strings;
3132
import org.elasticsearch.util.settings.Settings;
3233

3334
import java.io.IOException;
@@ -47,7 +48,7 @@ public class DisMaxJsonQueryParser extends AbstractIndexComponent implements Jso
4748
}
4849

4950
@Override public String[] names() {
50-
return new String[]{NAME};
51+
return new String[]{NAME, Strings.toCamelCase(NAME)};
5152
}
5253

5354
@Override public Query parse(JsonQueryParseContext parseContext) throws IOException, QueryParsingException {
@@ -81,7 +82,7 @@ public class DisMaxJsonQueryParser extends AbstractIndexComponent implements Jso
8182
} else {
8283
boost = jp.getFloatValue();
8384
}
84-
} else if ("tie_breaker".equals(currentFieldName)) {
85+
} else if ("tie_breaker".equals(currentFieldName) || "tieBreaker".equals(currentFieldName)) {
8586
if (token == JsonToken.VALUE_STRING) {
8687
tieBreaker = Float.parseFloat(jp.getText());
8788
} else {

modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/FieldJsonQueryParser.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ public class FieldJsonQueryParser extends AbstractIndexComponent implements Json
8686
queryString = jp.getText();
8787
} else if ("boost".equals(currentFieldName)) {
8888
boost = Float.parseFloat(jp.getText());
89-
} else if ("enable_position_increments".equals(currentFieldName)) {
89+
} else if ("enable_position_increments".equals(currentFieldName) || "enablePositionIncrements".equals(currentFieldName)) {
9090
enablePositionIncrements = Booleans.parseBoolean(jp.getText(), true);
91-
} else if ("lowercase_expanded_terms".equals(currentFieldName)) {
91+
} else if ("lowercase_expanded_terms".equals(currentFieldName) || "lowercaseExpandedTerms".equals(currentFieldName)) {
9292
lowercaseExpandedTerms = Booleans.parseBoolean(jp.getText(), true);
93-
} else if ("phrase_slop".equals(currentFieldName)) {
93+
} else if ("phrase_slop".equals(currentFieldName) || "phraseSlop".equals(currentFieldName)) {
9494
phraseSlop = Integer.parseInt(jp.getText());
9595
} else if ("analyzer".equals(currentFieldName)) {
9696
analyzer = analysisService.analyzer(jp.getText());
97-
} else if ("default_operator".equals(currentFieldName)) {
97+
} else if ("default_operator".equals(currentFieldName) || "defaultOperator".equals(currentFieldName)) {
9898
String op = jp.getText();
9999
if ("or".equalsIgnoreCase(op)) {
100100
defaultOperator = QueryParser.Operator.OR;
@@ -103,9 +103,9 @@ public class FieldJsonQueryParser extends AbstractIndexComponent implements Json
103103
} else {
104104
throw new QueryParsingException(index, "Query default operator [" + op + "] is not allowed");
105105
}
106-
} else if ("fuzzy_min_sim".equals(currentFieldName)) {
106+
} else if ("fuzzy_min_sim".equals(currentFieldName) || "fuzzyMinSim".equals(currentFieldName)) {
107107
fuzzyMinSim = Float.parseFloat(jp.getText());
108-
} else if ("fuzzy_prefix_length".equals(currentFieldName)) {
108+
} else if ("fuzzy_prefix_length".equals(currentFieldName) || "fuzzyPrefixLength".equals(currentFieldName)) {
109109
fuzzyPrefixLength = Integer.parseInt(jp.getText());
110110
} else if ("escape".equals(currentFieldName)) {
111111
escape = Booleans.parseBoolean(jp.getText(), false);
@@ -115,15 +115,15 @@ public class FieldJsonQueryParser extends AbstractIndexComponent implements Json
115115
queryString = jp.getText();
116116
} else if ("boost".equals(currentFieldName)) {
117117
boost = jp.getIntValue();
118-
} else if ("enable_position_increments".equals(currentFieldName)) {
118+
} else if ("enable_position_increments".equals(currentFieldName) || "enablePositionIncrements".equals(currentFieldName)) {
119119
enablePositionIncrements = jp.getIntValue() != 0;
120-
} else if ("lowercase_expanded_terms".equals(currentFieldName)) {
120+
} else if ("lowercase_expanded_terms".equals(currentFieldName) || "lowercaseExpandedTerms".equals(currentFieldName)) {
121121
lowercaseExpandedTerms = jp.getIntValue() != 0;
122-
} else if ("phrase_slop".equals(currentFieldName)) {
122+
} else if ("phrase_slop".equals(currentFieldName) || "phraseSlop".equals(currentFieldName)) {
123123
phraseSlop = jp.getIntValue();
124-
} else if ("fuzzy_min_sim".equals(currentFieldName)) {
124+
} else if ("fuzzy_min_sim".equals(currentFieldName) || "fuzzyMinSim".equals(currentFieldName)) {
125125
fuzzyMinSim = jp.getIntValue();
126-
} else if ("fuzzy_prefix_length".equals(currentFieldName)) {
126+
} else if ("fuzzy_prefix_length".equals(currentFieldName) || "fuzzyPrefixLength".equals(currentFieldName)) {
127127
fuzzyPrefixLength = jp.getIntValue();
128128
} else if ("escape".equals(currentFieldName)) {
129129
escape = jp.getIntValue() != 0;
@@ -133,25 +133,25 @@ public class FieldJsonQueryParser extends AbstractIndexComponent implements Json
133133
queryString = jp.getText();
134134
} else if ("boost".equals(currentFieldName)) {
135135
boost = jp.getFloatValue();
136-
} else if ("fuzzy_prefix_length".equals(currentFieldName)) {
136+
} else if ("fuzzy_prefix_length".equals(currentFieldName) || "fuzzyPrefixLength".equals(currentFieldName)) {
137137
fuzzyPrefixLength = jp.getIntValue();
138138
}
139139
} else if (token == JsonToken.VALUE_TRUE) {
140140
if ("query".equals(currentFieldName)) {
141141
queryString = jp.getText();
142-
} else if ("enable_position_increments".equals(currentFieldName)) {
142+
} else if ("enable_position_increments".equals(currentFieldName) || "enablePositionIncrements".equals(currentFieldName)) {
143143
enablePositionIncrements = true;
144-
} else if ("lowercase_expanded_terms".equals(currentFieldName)) {
144+
} else if ("lowercase_expanded_terms".equals(currentFieldName) || "lowercaseExpandedTerms".equals(currentFieldName)) {
145145
lowercaseExpandedTerms = true;
146146
} else if ("escape".equals(currentFieldName)) {
147147
escape = true;
148148
}
149149
} else if (token == JsonToken.VALUE_FALSE) {
150150
if ("query".equals(currentFieldName)) {
151151
queryString = jp.getText();
152-
} else if ("enable_position_increments".equals(currentFieldName)) {
152+
} else if ("enable_position_increments".equals(currentFieldName) || "enablePositionIncrements".equals(currentFieldName)) {
153153
enablePositionIncrements = false;
154-
} else if ("lowercase_expanded_terms".equals(currentFieldName)) {
154+
} else if ("lowercase_expanded_terms".equals(currentFieldName) || "lowercaseExpandedTerms".equals(currentFieldName)) {
155155
lowercaseExpandedTerms = false;
156156
} else if ("escape".equals(currentFieldName)) {
157157
escape = false;

modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/FuzzyLikeThisFieldJsonQueryParser.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.index.query.QueryParsingException;
3131
import org.elasticsearch.index.settings.IndexSettings;
3232
import org.elasticsearch.util.Booleans;
33+
import org.elasticsearch.util.Strings;
3334
import org.elasticsearch.util.settings.Settings;
3435

3536
import java.io.IOException;
@@ -59,7 +60,7 @@ public FuzzyLikeThisFieldJsonQueryParser(Index index, @IndexSettings Settings in
5960
}
6061

6162
@Override public String[] names() {
62-
return new String[]{NAME, "fuzzy_like_this_field"};
63+
return new String[]{NAME, "fuzzy_like_this_field", Strings.toCamelCase(NAME), "fuzzyLikeThisField"};
6364
}
6465

6566
@Override public Query parse(JsonQueryParseContext parseContext) throws IOException, QueryParsingException {
@@ -86,25 +87,25 @@ public FuzzyLikeThisFieldJsonQueryParser(Index index, @IndexSettings Settings in
8687
if (token == JsonToken.FIELD_NAME) {
8788
currentFieldName = jp.getCurrentName();
8889
} else if (token == JsonToken.VALUE_STRING) {
89-
if ("like_text".equals(currentFieldName)) {
90+
if ("like_text".equals(currentFieldName) || "likeText".equals(currentFieldName)) {
9091
likeText = jp.getText();
91-
} else if ("max_query_terms".equals(currentFieldName)) {
92+
} else if ("max_query_terms".equals(currentFieldName) || "maxQueryTerms".equals(currentFieldName)) {
9293
maxNumTerms = Integer.parseInt(jp.getText());
9394
} else if ("boost".equals(currentFieldName)) {
9495
boost = Float.parseFloat(jp.getText());
95-
} else if ("ignore_tf".equals(currentFieldName)) {
96+
} else if ("ignore_tf".equals(currentFieldName) || "ignoreTF".equals(currentFieldName)) {
9697
ignoreTF = Booleans.parseBoolean(jp.getText(), false);
9798
}
9899
} else if (token == JsonToken.VALUE_NUMBER_INT) {
99-
if ("max_query_terms".equals(currentFieldName)) {
100+
if ("max_query_terms".equals(currentFieldName) || "maxQueryTerms".equals(currentFieldName)) {
100101
maxNumTerms = jp.getIntValue();
101102
} else if ("boost".equals(currentFieldName)) {
102103
boost = jp.getIntValue();
103-
} else if ("ignore_tf".equals(currentFieldName)) {
104+
} else if ("ignore_tf".equals(currentFieldName) || "ignoreTF".equals(currentFieldName)) {
104105
ignoreTF = jp.getIntValue() != 0;
105106
}
106107
} else if (token == JsonToken.VALUE_TRUE) {
107-
if ("ignore_tf".equals(currentFieldName)) {
108+
if ("ignore_tf".equals(currentFieldName) || "ignoreTF".equals(currentFieldName)) {
108109
ignoreTF = true;
109110
}
110111
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
@@ -115,7 +116,7 @@ public FuzzyLikeThisFieldJsonQueryParser(Index index, @IndexSettings Settings in
115116
}
116117

117118
if (likeText == null) {
118-
throw new QueryParsingException(index, "fuzzy_like_This_field requires 'likeText' to be specified");
119+
throw new QueryParsingException(index, "fuzzy_like_This_field requires 'like_text' to be specified");
119120
}
120121

121122
Analyzer analyzer = null;

modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/FuzzyLikeThisJsonQueryParser.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public FuzzyLikeThisJsonQueryParser(Index index, @IndexSettings Settings indexSe
5858
}
5959

6060
@Override public String[] names() {
61-
return new String[]{NAME, "fuzzy_like_this"};
61+
return new String[]{NAME, "fuzzy_like_this", "fuzzyLikeThis"};
6262
}
6363

6464
@Override public Query parse(JsonQueryParseContext parseContext) throws IOException, QueryParsingException {
@@ -78,25 +78,25 @@ public FuzzyLikeThisJsonQueryParser(Index index, @IndexSettings Settings indexSe
7878
if (token == JsonToken.FIELD_NAME) {
7979
currentFieldName = jp.getCurrentName();
8080
} else if (token == JsonToken.VALUE_STRING) {
81-
if ("like_text".equals(currentFieldName)) {
81+
if ("like_text".equals(currentFieldName) || "likeText".equals(currentFieldName)) {
8282
likeText = jp.getText();
83-
} else if ("max_query_terms".equals(currentFieldName)) {
83+
} else if ("max_query_terms".equals(currentFieldName) || "maxQueryTerms".equals(currentFieldName)) {
8484
maxNumTerms = Integer.parseInt(jp.getText());
8585
} else if ("boost".equals(currentFieldName)) {
8686
boost = Float.parseFloat(jp.getText());
87-
} else if ("ignore_tf".equals(currentFieldName)) {
87+
} else if ("ignore_tf".equals(currentFieldName) || "ignoreTF".equals(currentFieldName)) {
8888
ignoreTF = Booleans.parseBoolean(jp.getText(), false);
8989
}
9090
} else if (token == JsonToken.VALUE_NUMBER_INT) {
91-
if ("max_query_terms".equals(currentFieldName)) {
91+
if ("max_query_terms".equals(currentFieldName) || "maxQueryTerms".equals(currentFieldName)) {
9292
maxNumTerms = jp.getIntValue();
9393
} else if ("boost".equals(currentFieldName)) {
9494
boost = jp.getIntValue();
95-
} else if ("ignore_tf".equals(currentFieldName)) {
95+
} else if ("ignore_tf".equals(currentFieldName) || "ignoreTF".equals(currentFieldName)) {
9696
ignoreTF = jp.getIntValue() != 0;
9797
}
9898
} else if (token == JsonToken.VALUE_TRUE) {
99-
if ("ignore_tf".equals(currentFieldName)) {
99+
if ("ignore_tf".equals(currentFieldName) || "ignoreTF".equals(currentFieldName)) {
100100
ignoreTF = true;
101101
}
102102
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
@@ -114,7 +114,7 @@ public FuzzyLikeThisJsonQueryParser(Index index, @IndexSettings Settings indexSe
114114
}
115115

116116
if (likeText == null) {
117-
throw new QueryParsingException(index, "fuzzy_like_this requires 'likeText' to be specified");
117+
throw new QueryParsingException(index, "fuzzy_like_this requires 'like_text' to be specified");
118118
}
119119

120120
FuzzyLikeThisQuery query = new FuzzyLikeThisQuery(maxNumTerms, parseContext.mapperService().searchAnalyzer());

modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/JsonQueryParseContext.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import java.io.IOException;
3737

3838
/**
39-
* @author kimchy (Shay Banon)
39+
* @author kimchy (shay.banon)
4040
*/
4141
public class JsonQueryParseContext {
4242

0 commit comments

Comments
 (0)