Query DSL: Filtered query to make query optional (defaults to mach_all)
closes #2718
This commit is contained in:
parent
dfd92265b7
commit
6687ecb038
|
@ -51,8 +51,7 @@ public class FilteredQueryParser implements QueryParser {
|
||||||
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
|
|
||||||
Query query = null;
|
Query query = Queries.MATCH_ALL_QUERY;
|
||||||
boolean queryFound = false;
|
|
||||||
Filter filter = null;
|
Filter filter = null;
|
||||||
boolean filterFound = false;
|
boolean filterFound = false;
|
||||||
float boost = 1.0f;
|
float boost = 1.0f;
|
||||||
|
@ -68,7 +67,6 @@ public class FilteredQueryParser implements QueryParser {
|
||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||||
if ("query".equals(currentFieldName)) {
|
if ("query".equals(currentFieldName)) {
|
||||||
queryFound = true;
|
|
||||||
query = parseContext.parseInnerQuery();
|
query = parseContext.parseInnerQuery();
|
||||||
} else if ("filter".equals(currentFieldName)) {
|
} else if ("filter".equals(currentFieldName)) {
|
||||||
filterFound = true;
|
filterFound = true;
|
||||||
|
@ -109,12 +107,12 @@ public class FilteredQueryParser implements QueryParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!queryFound) {
|
|
||||||
throw new QueryParsingException(parseContext.index(), "[filtered] requires 'query' element");
|
// parsed internally, but returned null during parsing...
|
||||||
}
|
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter == null) {
|
if (filter == null) {
|
||||||
if (!filterFound) {
|
if (!filterFound) {
|
||||||
// we allow for null filter, so it makes compositions on the client side to be simpler
|
// we allow for null filter, so it makes compositions on the client side to be simpler
|
||||||
|
|
Loading…
Reference in New Issue