Query enhancement: return positions of parse errors found in JSON

Extend SearchParseException and QueryParsingException to report position information in query JSON where errors were found. All query DSL parser classes that throw these exception types now pass the underlying position information (line and column number) at the point the error was found.

Closes #3303
This commit is contained in:
markharwood 2015-04-27 14:45:32 +01:00
parent 6e076efdb9
commit 528f6481ea
115 changed files with 834 additions and 482 deletions

View File

@ -0,0 +1,37 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.common.xcontent;
/**
* Simple data structure representing the line and column number of a position
* in some XContent e.g. JSON. Locations are typically used to communicate the
* position of a parsing error to end users and consequently have line and
* column numbers starting from 1.
*/
public class XContentLocation {
public final int lineNumber;
public final int columnNumber;
public XContentLocation(int lineNumber, int columnNumber) {
super();
this.lineNumber = lineNumber;
this.columnNumber = columnNumber;
}
}

View File

@ -241,4 +241,12 @@ public interface XContentParser extends Releasable {
* *
*/ */
byte[] binaryValue() throws IOException; byte[] binaryValue() throws IOException;
/**
* Used for error reporting to highlight where syntax errors occur in
* content being parsed.
*
* @return last token's location or null if cannot be determined
*/
XContentLocation getTokenLocation();
} }

View File

@ -19,10 +19,13 @@
package org.elasticsearch.common.xcontent.json; package org.elasticsearch.common.xcontent.json;
import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.JsonToken;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.elasticsearch.common.xcontent.XContentLocation;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.support.AbstractXContentParser; import org.elasticsearch.common.xcontent.support.AbstractXContentParser;
@ -187,6 +190,15 @@ public class JsonXContentParser extends AbstractXContentParser {
return parser.getBinaryValue(); return parser.getBinaryValue();
} }
@Override
public XContentLocation getTokenLocation() {
JsonLocation loc = parser.getTokenLocation();
if (loc == null) {
return null;
}
return new XContentLocation(loc.getLineNr(), loc.getColumnNr());
}
@Override @Override
public void close() { public void close() {
IOUtils.closeWhileHandlingException(parser); IOUtils.closeWhileHandlingException(parser);

View File

@ -223,7 +223,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent imple
context.setMapUnmappedFieldAsString(mapUnmappedFieldsAsString ? true : false); context.setMapUnmappedFieldAsString(mapUnmappedFieldsAsString ? true : false);
return queryParserService.parseInnerQuery(context); return queryParserService.parseInnerQuery(context);
} catch (IOException e) { } catch (IOException e) {
throw new QueryParsingException(queryParserService.index(), "Failed to parse", e); throw new QueryParsingException(context, "Failed to parse", e);
} finally { } finally {
if (type != null) { if (type != null) {
QueryParseContext.setTypes(previousTypes); QueryParseContext.setTypes(previousTypes);

View File

@ -100,14 +100,14 @@ public class AndFilterParser implements FilterParser {
} else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) { } else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) {
cacheKey = new HashedBytesRef(parser.text()); cacheKey = new HashedBytesRef(parser.text());
} else { } else {
throw new QueryParsingException(parseContext.index(), "[and] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[and] filter does not support [" + currentFieldName + "]");
} }
} }
} }
} }
if (!filtersFound) { if (!filtersFound) {
throw new QueryParsingException(parseContext.index(), "[and] filter requires 'filters' to be set on it'"); throw new QueryParsingException(parseContext, "[and] filter requires 'filters' to be set on it'");
} }
if (filters.isEmpty()) { if (filters.isEmpty()) {

View File

@ -85,7 +85,7 @@ public class BoolFilterParser implements FilterParser {
boolFilter.add(new BooleanClause(filter, BooleanClause.Occur.SHOULD)); boolFilter.add(new BooleanClause(filter, BooleanClause.Occur.SHOULD));
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[bool] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[bool] filter does not support [" + currentFieldName + "]");
} }
} else if (token == XContentParser.Token.START_ARRAY) { } else if (token == XContentParser.Token.START_ARRAY) {
if ("must".equals(currentFieldName)) { if ("must".equals(currentFieldName)) {
@ -114,7 +114,7 @@ public class BoolFilterParser implements FilterParser {
} }
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[bool] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[bool] filter does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("_cache".equals(currentFieldName)) { if ("_cache".equals(currentFieldName)) {
@ -124,13 +124,13 @@ public class BoolFilterParser implements FilterParser {
} else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) { } else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) {
cacheKey = new HashedBytesRef(parser.text()); cacheKey = new HashedBytesRef(parser.text());
} else { } else {
throw new QueryParsingException(parseContext.index(), "[bool] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[bool] filter does not support [" + currentFieldName + "]");
} }
} }
} }
if (!hasAnyFilter) { if (!hasAnyFilter) {
throw new QueryParsingException(parseContext.index(), "[bool] filter has no inner should/must/must_not elements"); throw new QueryParsingException(parseContext, "[bool] filter has no inner should/must/must_not elements");
} }
if (boolFilter.clauses().isEmpty()) { if (boolFilter.clauses().isEmpty()) {

View File

@ -85,7 +85,7 @@ public class BoolQueryParser implements QueryParser {
clauses.add(new BooleanClause(query, BooleanClause.Occur.SHOULD)); clauses.add(new BooleanClause(query, BooleanClause.Occur.SHOULD));
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[bool] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[bool] query does not support [" + currentFieldName + "]");
} }
} else if (token == XContentParser.Token.START_ARRAY) { } else if (token == XContentParser.Token.START_ARRAY) {
if ("must".equals(currentFieldName)) { if ("must".equals(currentFieldName)) {
@ -110,7 +110,7 @@ public class BoolQueryParser implements QueryParser {
} }
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "bool query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "bool query does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) { if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) {
@ -126,7 +126,7 @@ public class BoolQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[bool] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[bool] query does not support [" + currentFieldName + "]");
} }
} }
} }

View File

@ -66,7 +66,7 @@ public class BoostingQueryParser implements QueryParser {
negativeQuery = parseContext.parseInnerQuery(); negativeQuery = parseContext.parseInnerQuery();
negativeQueryFound = true; negativeQueryFound = true;
} else { } else {
throw new QueryParsingException(parseContext.index(), "[boosting] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[boosting] query does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("negative_boost".equals(currentFieldName) || "negativeBoost".equals(currentFieldName)) { if ("negative_boost".equals(currentFieldName) || "negativeBoost".equals(currentFieldName)) {
@ -74,19 +74,19 @@ public class BoostingQueryParser implements QueryParser {
} else if ("boost".equals(currentFieldName)) { } else if ("boost".equals(currentFieldName)) {
boost = parser.floatValue(); boost = parser.floatValue();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[boosting] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[boosting] query does not support [" + currentFieldName + "]");
} }
} }
} }
if (positiveQuery == null && !positiveQueryFound) { if (positiveQuery == null && !positiveQueryFound) {
throw new QueryParsingException(parseContext.index(), "[boosting] query requires 'positive' query to be set'"); throw new QueryParsingException(parseContext, "[boosting] query requires 'positive' query to be set'");
} }
if (negativeQuery == null && !negativeQueryFound) { if (negativeQuery == null && !negativeQueryFound) {
throw new QueryParsingException(parseContext.index(), "[boosting] query requires 'negative' query to be set'"); throw new QueryParsingException(parseContext, "[boosting] query requires 'negative' query to be set'");
} }
if (negativeBoost == -1) { if (negativeBoost == -1) {
throw new QueryParsingException(parseContext.index(), "[boosting] query requires 'negative_boost' to be set'"); throw new QueryParsingException(parseContext, "[boosting] query requires 'negative_boost' to be set'");
} }
// parsers returned null // parsers returned null

View File

@ -65,7 +65,7 @@ public class CommonTermsQueryParser implements QueryParser {
XContentParser parser = parseContext.parser(); XContentParser parser = parseContext.parser();
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
if (token != XContentParser.Token.FIELD_NAME) { if (token != XContentParser.Token.FIELD_NAME) {
throw new QueryParsingException(parseContext.index(), "[common] query malformed, no field"); throw new QueryParsingException(parseContext, "[common] query malformed, no field");
} }
String fieldName = parser.currentName(); String fieldName = parser.currentName();
Object value = null; Object value = null;
@ -96,12 +96,13 @@ public class CommonTermsQueryParser implements QueryParser {
} else if ("high_freq".equals(innerFieldName) || "highFreq".equals(innerFieldName)) { } else if ("high_freq".equals(innerFieldName) || "highFreq".equals(innerFieldName)) {
highFreqMinimumShouldMatch = parser.text(); highFreqMinimumShouldMatch = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[common] query does not support [" + innerFieldName + "] for [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[common] query does not support [" + innerFieldName
+ "] for [" + currentFieldName + "]");
} }
} }
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[common] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[common] query does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("query".equals(currentFieldName)) { if ("query".equals(currentFieldName)) {
@ -109,7 +110,7 @@ public class CommonTermsQueryParser implements QueryParser {
} else if ("analyzer".equals(currentFieldName)) { } else if ("analyzer".equals(currentFieldName)) {
String analyzer = parser.text(); String analyzer = parser.text();
if (parseContext.analysisService().analyzer(analyzer) == null) { if (parseContext.analysisService().analyzer(analyzer) == null) {
throw new QueryParsingException(parseContext.index(), "[common] analyzer [" + parser.text() + "] not found"); throw new QueryParsingException(parseContext, "[common] analyzer [" + parser.text() + "] not found");
} }
queryAnalyzer = analyzer; queryAnalyzer = analyzer;
} else if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) { } else if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) {
@ -123,7 +124,7 @@ public class CommonTermsQueryParser implements QueryParser {
} else if ("and".equalsIgnoreCase(op)) { } else if ("and".equalsIgnoreCase(op)) {
highFreqOccur = BooleanClause.Occur.MUST; highFreqOccur = BooleanClause.Occur.MUST;
} else { } else {
throw new QueryParsingException(parseContext.index(), throw new QueryParsingException(parseContext,
"[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); "[common] query requires operator to be either 'and' or 'or', not [" + op + "]");
} }
} else if ("low_freq_operator".equals(currentFieldName) || "lowFreqOperator".equals(currentFieldName)) { } else if ("low_freq_operator".equals(currentFieldName) || "lowFreqOperator".equals(currentFieldName)) {
@ -133,7 +134,7 @@ public class CommonTermsQueryParser implements QueryParser {
} else if ("and".equalsIgnoreCase(op)) { } else if ("and".equalsIgnoreCase(op)) {
lowFreqOccur = BooleanClause.Occur.MUST; lowFreqOccur = BooleanClause.Occur.MUST;
} else { } else {
throw new QueryParsingException(parseContext.index(), throw new QueryParsingException(parseContext,
"[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); "[common] query requires operator to be either 'and' or 'or', not [" + op + "]");
} }
} else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { } else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) {
@ -143,7 +144,7 @@ public class CommonTermsQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[common] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[common] query does not support [" + currentFieldName + "]");
} }
} }
} }
@ -154,13 +155,13 @@ public class CommonTermsQueryParser implements QueryParser {
token = parser.nextToken(); token = parser.nextToken();
if (token != XContentParser.Token.END_OBJECT) { if (token != XContentParser.Token.END_OBJECT) {
throw new QueryParsingException( throw new QueryParsingException(
parseContext.index(), parseContext,
"[common] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?"); "[common] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?");
} }
} }
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No text specified for text query"); throw new QueryParsingException(parseContext, "No text specified for text query");
} }
FieldMapper<?> mapper = null; FieldMapper<?> mapper = null;
String field; String field;

View File

@ -71,7 +71,7 @@ public class ConstantScoreQueryParser implements QueryParser {
query = parseContext.parseInnerQuery(); query = parseContext.parseInnerQuery();
queryFound = true; queryFound = true;
} else { } else {
throw new QueryParsingException(parseContext.index(), "[constant_score] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[constant_score] query does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("boost".equals(currentFieldName)) { if ("boost".equals(currentFieldName)) {
@ -81,12 +81,12 @@ public class ConstantScoreQueryParser implements QueryParser {
} else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) { } else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) {
cacheKey = new HashedBytesRef(parser.text()); cacheKey = new HashedBytesRef(parser.text());
} else { } else {
throw new QueryParsingException(parseContext.index(), "[constant_score] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[constant_score] query does not support [" + currentFieldName + "]");
} }
} }
} }
if (!filterFound && !queryFound) { if (!filterFound && !queryFound) {
throw new QueryParsingException(parseContext.index(), "[constant_score] requires either 'filter' or 'query' element"); throw new QueryParsingException(parseContext, "[constant_score] requires either 'filter' or 'query' element");
} }
if (query == null && filter == null) { if (query == null && filter == null) {

View File

@ -70,7 +70,7 @@ public class DisMaxQueryParser implements QueryParser {
queries.add(query); queries.add(query);
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[dis_max] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[dis_max] query does not support [" + currentFieldName + "]");
} }
} else if (token == XContentParser.Token.START_ARRAY) { } else if (token == XContentParser.Token.START_ARRAY) {
if ("queries".equals(currentFieldName)) { if ("queries".equals(currentFieldName)) {
@ -83,7 +83,7 @@ public class DisMaxQueryParser implements QueryParser {
token = parser.nextToken(); token = parser.nextToken();
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[dis_max] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[dis_max] query does not support [" + currentFieldName + "]");
} }
} else { } else {
if ("boost".equals(currentFieldName)) { if ("boost".equals(currentFieldName)) {
@ -93,13 +93,13 @@ public class DisMaxQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[dis_max] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[dis_max] query does not support [" + currentFieldName + "]");
} }
} }
} }
if (!queriesFound) { if (!queriesFound) {
throw new QueryParsingException(parseContext.index(), "[dis_max] requires 'queries' field"); throw new QueryParsingException(parseContext, "[dis_max] requires 'queries' field");
} }
if (queries.isEmpty()) { if (queries.isEmpty()) {

View File

@ -23,8 +23,6 @@ import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Filter; import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryWrapperFilter;
import org.apache.lucene.search.TermRangeFilter;
import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.TermRangeQuery;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.HashedBytesRef; import org.elasticsearch.common.lucene.HashedBytesRef;
@ -71,13 +69,13 @@ public class ExistsFilterParser implements FilterParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
filterName = parser.text(); filterName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[exists] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[exists] filter does not support [" + currentFieldName + "]");
} }
} }
} }
if (fieldPattern == null) { if (fieldPattern == null) {
throw new QueryParsingException(parseContext.index(), "exists must be provided with a [field]"); throw new QueryParsingException(parseContext, "exists must be provided with a [field]");
} }
return newFilter(parseContext, fieldPattern, filterName); return newFilter(parseContext, fieldPattern, filterName);

View File

@ -66,7 +66,7 @@ public class FQueryFilterParser implements FilterParser {
queryFound = true; queryFound = true;
query = parseContext.parseInnerQuery(); query = parseContext.parseInnerQuery();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[fquery] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[fquery] filter does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("_name".equals(currentFieldName)) { if ("_name".equals(currentFieldName)) {
@ -76,12 +76,12 @@ public class FQueryFilterParser implements FilterParser {
} else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) { } else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) {
cacheKey = new HashedBytesRef(parser.text()); cacheKey = new HashedBytesRef(parser.text());
} else { } else {
throw new QueryParsingException(parseContext.index(), "[fquery] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[fquery] filter does not support [" + currentFieldName + "]");
} }
} }
} }
if (!queryFound) { if (!queryFound) {
throw new QueryParsingException(parseContext.index(), "[fquery] requires 'query' element"); throw new QueryParsingException(parseContext, "[fquery] requires 'query' element");
} }
if (query == null) { if (query == null) {
return null; return null;

View File

@ -64,11 +64,12 @@ public class FieldMaskingSpanQueryParser implements QueryParser {
if ("query".equals(currentFieldName)) { if ("query".equals(currentFieldName)) {
Query query = parseContext.parseInnerQuery(); Query query = parseContext.parseInnerQuery();
if (!(query instanceof SpanQuery)) { if (!(query instanceof SpanQuery)) {
throw new QueryParsingException(parseContext.index(), "[field_masking_span] query] must be of type span query"); throw new QueryParsingException(parseContext, "[field_masking_span] query] must be of type span query");
} }
inner = (SpanQuery) query; inner = (SpanQuery) query;
} else { } else {
throw new QueryParsingException(parseContext.index(), "[field_masking_span] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[field_masking_span] query does not support ["
+ currentFieldName + "]");
} }
} else { } else {
if ("boost".equals(currentFieldName)) { if ("boost".equals(currentFieldName)) {
@ -78,15 +79,15 @@ public class FieldMaskingSpanQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[field_masking_span] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[field_masking_span] query does not support [" + currentFieldName + "]");
} }
} }
} }
if (inner == null) { if (inner == null) {
throw new QueryParsingException(parseContext.index(), "field_masking_span must have [query] span query clause"); throw new QueryParsingException(parseContext, "field_masking_span must have [query] span query clause");
} }
if (field == null) { if (field == null) {
throw new QueryParsingException(parseContext.index(), "field_masking_span must have [field] set for it"); throw new QueryParsingException(parseContext, "field_masking_span must have [field] set for it");
} }
FieldMapper mapper = parseContext.fieldMapper(field); FieldMapper mapper = parseContext.fieldMapper(field);

View File

@ -73,7 +73,7 @@ public class FilteredQueryParser implements QueryParser {
filterFound = true; filterFound = true;
filter = parseContext.parseInnerFilter(); filter = parseContext.parseInnerFilter();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[filtered] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[filtered] query does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("strategy".equals(currentFieldName)) { if ("strategy".equals(currentFieldName)) {
@ -93,7 +93,7 @@ public class FilteredQueryParser implements QueryParser {
} else if ("leap_frog_filter_first".equals(value) || "leapFrogFilterFirst".equals(value)) { } else if ("leap_frog_filter_first".equals(value) || "leapFrogFilterFirst".equals(value)) {
filterStrategy = FilteredQuery.LEAP_FROG_FILTER_FIRST_STRATEGY; filterStrategy = FilteredQuery.LEAP_FROG_FILTER_FIRST_STRATEGY;
} else { } else {
throw new QueryParsingException(parseContext.index(), "[filtered] strategy value not supported [" + value + "]"); throw new QueryParsingException(parseContext, "[filtered] strategy value not supported [" + value + "]");
} }
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
@ -104,7 +104,7 @@ public class FilteredQueryParser implements QueryParser {
} else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) { } else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) {
cacheKey = new HashedBytesRef(parser.text()); cacheKey = new HashedBytesRef(parser.text());
} else { } else {
throw new QueryParsingException(parseContext.index(), "[filtered] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[filtered] query does not support [" + currentFieldName + "]");
} }
} }
} }

View File

@ -57,7 +57,7 @@ public class FuzzyQueryParser implements QueryParser {
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
if (token != XContentParser.Token.FIELD_NAME) { if (token != XContentParser.Token.FIELD_NAME) {
throw new QueryParsingException(parseContext.index(), "[fuzzy] query malformed, no field"); throw new QueryParsingException(parseContext, "[fuzzy] query malformed, no field");
} }
String fieldName = parser.currentName(); String fieldName = parser.currentName();
@ -95,7 +95,7 @@ public class FuzzyQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[fuzzy] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[fuzzy] query does not support [" + currentFieldName + "]");
} }
} }
} }
@ -107,7 +107,7 @@ public class FuzzyQueryParser implements QueryParser {
} }
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No value specified for fuzzy query"); throw new QueryParsingException(parseContext, "No value specified for fuzzy query");
} }
Query query = null; Query query = null;

View File

@ -147,7 +147,7 @@ public class GeoBoundingBoxFilterParser implements FilterParser {
} else if ("type".equals(currentFieldName)) { } else if ("type".equals(currentFieldName)) {
type = parser.text(); type = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[geo_bbox] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[geo_bbox] filter does not support [" + currentFieldName + "]");
} }
} }
} }
@ -169,11 +169,11 @@ public class GeoBoundingBoxFilterParser implements FilterParser {
MapperService.SmartNameFieldMappers smartMappers = parseContext.smartFieldMappers(fieldName); MapperService.SmartNameFieldMappers smartMappers = parseContext.smartFieldMappers(fieldName);
if (smartMappers == null || !smartMappers.hasMapper()) { if (smartMappers == null || !smartMappers.hasMapper()) {
throw new QueryParsingException(parseContext.index(), "failed to find geo_point field [" + fieldName + "]"); throw new QueryParsingException(parseContext, "failed to find geo_point field [" + fieldName + "]");
} }
FieldMapper<?> mapper = smartMappers.mapper(); FieldMapper<?> mapper = smartMappers.mapper();
if (!(mapper instanceof GeoPointFieldMapper)) { if (!(mapper instanceof GeoPointFieldMapper)) {
throw new QueryParsingException(parseContext.index(), "field [" + fieldName + "] is not a geo_point field"); throw new QueryParsingException(parseContext, "field [" + fieldName + "] is not a geo_point field");
} }
GeoPointFieldMapper geoMapper = ((GeoPointFieldMapper) mapper); GeoPointFieldMapper geoMapper = ((GeoPointFieldMapper) mapper);
@ -184,7 +184,8 @@ public class GeoBoundingBoxFilterParser implements FilterParser {
IndexGeoPointFieldData indexFieldData = parseContext.getForField(mapper); IndexGeoPointFieldData indexFieldData = parseContext.getForField(mapper);
filter = new InMemoryGeoBoundingBoxFilter(topLeft, bottomRight, indexFieldData); filter = new InMemoryGeoBoundingBoxFilter(topLeft, bottomRight, indexFieldData);
} else { } else {
throw new QueryParsingException(parseContext.index(), "geo bounding box type [" + type + "] not supported, either 'indexed' or 'memory' are allowed"); throw new QueryParsingException(parseContext, "geo bounding box type [" + type
+ "] not supported, either 'indexed' or 'memory' are allowed");
} }
if (cache != null) { if (cache != null) {

View File

@ -98,7 +98,8 @@ public class GeoDistanceFilterParser implements FilterParser {
} else if (currentName.equals(GeoPointFieldMapper.Names.GEOHASH)) { } else if (currentName.equals(GeoPointFieldMapper.Names.GEOHASH)) {
GeoHashUtils.decode(parser.text(), point); GeoHashUtils.decode(parser.text(), point);
} else { } else {
throw new QueryParsingException(parseContext.index(), "[geo_distance] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[geo_distance] filter does not support [" + currentFieldName
+ "]");
} }
} }
} }
@ -141,7 +142,7 @@ public class GeoDistanceFilterParser implements FilterParser {
} }
if (vDistance == null) { if (vDistance == null) {
throw new QueryParsingException(parseContext.index(), "geo_distance requires 'distance' to be specified"); throw new QueryParsingException(parseContext, "geo_distance requires 'distance' to be specified");
} else if (vDistance instanceof Number) { } else if (vDistance instanceof Number) {
distance = DistanceUnit.DEFAULT.convert(((Number) vDistance).doubleValue(), unit); distance = DistanceUnit.DEFAULT.convert(((Number) vDistance).doubleValue(), unit);
} else { } else {
@ -155,11 +156,11 @@ public class GeoDistanceFilterParser implements FilterParser {
MapperService.SmartNameFieldMappers smartMappers = parseContext.smartFieldMappers(fieldName); MapperService.SmartNameFieldMappers smartMappers = parseContext.smartFieldMappers(fieldName);
if (smartMappers == null || !smartMappers.hasMapper()) { if (smartMappers == null || !smartMappers.hasMapper()) {
throw new QueryParsingException(parseContext.index(), "failed to find geo_point field [" + fieldName + "]"); throw new QueryParsingException(parseContext, "failed to find geo_point field [" + fieldName + "]");
} }
FieldMapper<?> mapper = smartMappers.mapper(); FieldMapper<?> mapper = smartMappers.mapper();
if (!(mapper instanceof GeoPointFieldMapper)) { if (!(mapper instanceof GeoPointFieldMapper)) {
throw new QueryParsingException(parseContext.index(), "field [" + fieldName + "] is not a geo_point field"); throw new QueryParsingException(parseContext, "field [" + fieldName + "] is not a geo_point field");
} }
GeoPointFieldMapper geoMapper = ((GeoPointFieldMapper) mapper); GeoPointFieldMapper geoMapper = ((GeoPointFieldMapper) mapper);

View File

@ -196,11 +196,11 @@ public class GeoDistanceRangeFilterParser implements FilterParser {
MapperService.SmartNameFieldMappers smartMappers = parseContext.smartFieldMappers(fieldName); MapperService.SmartNameFieldMappers smartMappers = parseContext.smartFieldMappers(fieldName);
if (smartMappers == null || !smartMappers.hasMapper()) { if (smartMappers == null || !smartMappers.hasMapper()) {
throw new QueryParsingException(parseContext.index(), "failed to find geo_point field [" + fieldName + "]"); throw new QueryParsingException(parseContext, "failed to find geo_point field [" + fieldName + "]");
} }
FieldMapper<?> mapper = smartMappers.mapper(); FieldMapper<?> mapper = smartMappers.mapper();
if (!(mapper instanceof GeoPointFieldMapper)) { if (!(mapper instanceof GeoPointFieldMapper)) {
throw new QueryParsingException(parseContext.index(), "field [" + fieldName + "] is not a geo_point field"); throw new QueryParsingException(parseContext, "field [" + fieldName + "] is not a geo_point field");
} }
GeoPointFieldMapper geoMapper = ((GeoPointFieldMapper) mapper); GeoPointFieldMapper geoMapper = ((GeoPointFieldMapper) mapper);

View File

@ -96,10 +96,12 @@ public class GeoPolygonFilterParser implements FilterParser {
shell.add(GeoUtils.parseGeoPoint(parser)); shell.add(GeoUtils.parseGeoPoint(parser));
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[geo_polygon] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[geo_polygon] filter does not support [" + currentFieldName
+ "]");
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[geo_polygon] filter does not support token type [" + token.name() + "] under [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[geo_polygon] filter does not support token type [" + token.name()
+ "] under [" + currentFieldName + "]");
} }
} }
} else if (token.isValue()) { } else if (token.isValue()) {
@ -113,25 +115,25 @@ public class GeoPolygonFilterParser implements FilterParser {
normalizeLat = parser.booleanValue(); normalizeLat = parser.booleanValue();
normalizeLon = parser.booleanValue(); normalizeLon = parser.booleanValue();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[geo_polygon] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[geo_polygon] filter does not support [" + currentFieldName + "]");
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[geo_polygon] unexpected token type [" + token.name() + "]"); throw new QueryParsingException(parseContext, "[geo_polygon] unexpected token type [" + token.name() + "]");
} }
} }
if (shell.isEmpty()) { if (shell.isEmpty()) {
throw new QueryParsingException(parseContext.index(), "no points defined for geo_polygon filter"); throw new QueryParsingException(parseContext, "no points defined for geo_polygon filter");
} else { } else {
if (shell.size() < 3) { if (shell.size() < 3) {
throw new QueryParsingException(parseContext.index(), "too few points defined for geo_polygon filter"); throw new QueryParsingException(parseContext, "too few points defined for geo_polygon filter");
} }
GeoPoint start = shell.get(0); GeoPoint start = shell.get(0);
if (!start.equals(shell.get(shell.size() - 1))) { if (!start.equals(shell.get(shell.size() - 1))) {
shell.add(start); shell.add(start);
} }
if (shell.size() < 4) { if (shell.size() < 4) {
throw new QueryParsingException(parseContext.index(), "too few points defined for geo_polygon filter"); throw new QueryParsingException(parseContext, "too few points defined for geo_polygon filter");
} }
} }
@ -143,11 +145,11 @@ public class GeoPolygonFilterParser implements FilterParser {
MapperService.SmartNameFieldMappers smartMappers = parseContext.smartFieldMappers(fieldName); MapperService.SmartNameFieldMappers smartMappers = parseContext.smartFieldMappers(fieldName);
if (smartMappers == null || !smartMappers.hasMapper()) { if (smartMappers == null || !smartMappers.hasMapper()) {
throw new QueryParsingException(parseContext.index(), "failed to find geo_point field [" + fieldName + "]"); throw new QueryParsingException(parseContext, "failed to find geo_point field [" + fieldName + "]");
} }
FieldMapper<?> mapper = smartMappers.mapper(); FieldMapper<?> mapper = smartMappers.mapper();
if (!(mapper instanceof GeoPointFieldMapper)) { if (!(mapper instanceof GeoPointFieldMapper)) {
throw new QueryParsingException(parseContext.index(), "field [" + fieldName + "] is not a geo_point field"); throw new QueryParsingException(parseContext, "field [" + fieldName + "] is not a geo_point field");
} }
IndexGeoPointFieldData indexFieldData = parseContext.getForField(mapper); IndexGeoPointFieldData indexFieldData = parseContext.getForField(mapper);

View File

@ -113,7 +113,7 @@ public class GeoShapeFilterParser implements FilterParser {
} else if ("relation".equals(currentFieldName)) { } else if ("relation".equals(currentFieldName)) {
shapeRelation = ShapeRelation.getRelationByName(parser.text()); shapeRelation = ShapeRelation.getRelationByName(parser.text());
if (shapeRelation == null) { if (shapeRelation == null) {
throw new QueryParsingException(parseContext.index(), "Unknown shape operation [" + parser.text() + "]"); throw new QueryParsingException(parseContext, "Unknown shape operation [" + parser.text() + "]");
} }
} else if ("strategy".equals(currentFieldName)) { } else if ("strategy".equals(currentFieldName)) {
strategyName = parser.text(); strategyName = parser.text();
@ -134,13 +134,13 @@ public class GeoShapeFilterParser implements FilterParser {
} }
} }
if (id == null) { if (id == null) {
throw new QueryParsingException(parseContext.index(), "ID for indexed shape not provided"); throw new QueryParsingException(parseContext, "ID for indexed shape not provided");
} else if (type == null) { } else if (type == null) {
throw new QueryParsingException(parseContext.index(), "Type for indexed shape not provided"); throw new QueryParsingException(parseContext, "Type for indexed shape not provided");
} }
shape = fetchService.fetch(id, type, index, shapePath); shape = fetchService.fetch(id, type, index, shapePath);
} else { } else {
throw new QueryParsingException(parseContext.index(), "[geo_shape] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[geo_shape] filter does not support [" + currentFieldName + "]");
} }
} }
} }
@ -152,26 +152,26 @@ public class GeoShapeFilterParser implements FilterParser {
} else if ("_cache_key".equals(currentFieldName)) { } else if ("_cache_key".equals(currentFieldName)) {
cacheKey = new HashedBytesRef(parser.text()); cacheKey = new HashedBytesRef(parser.text());
} else { } else {
throw new QueryParsingException(parseContext.index(), "[geo_shape] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[geo_shape] filter does not support [" + currentFieldName + "]");
} }
} }
} }
if (shape == null) { if (shape == null) {
throw new QueryParsingException(parseContext.index(), "No Shape defined"); throw new QueryParsingException(parseContext, "No Shape defined");
} else if (shapeRelation == null) { } else if (shapeRelation == null) {
throw new QueryParsingException(parseContext.index(), "No Shape Relation defined"); throw new QueryParsingException(parseContext, "No Shape Relation defined");
} }
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName); MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
if (smartNameFieldMappers == null || !smartNameFieldMappers.hasMapper()) { if (smartNameFieldMappers == null || !smartNameFieldMappers.hasMapper()) {
throw new QueryParsingException(parseContext.index(), "Failed to find geo_shape field [" + fieldName + "]"); throw new QueryParsingException(parseContext, "Failed to find geo_shape field [" + fieldName + "]");
} }
FieldMapper fieldMapper = smartNameFieldMappers.mapper(); FieldMapper fieldMapper = smartNameFieldMappers.mapper();
// TODO: This isn't the nicest way to check this // TODO: This isn't the nicest way to check this
if (!(fieldMapper instanceof GeoShapeFieldMapper)) { if (!(fieldMapper instanceof GeoShapeFieldMapper)) {
throw new QueryParsingException(parseContext.index(), "Field [" + fieldName + "] is not a geo_shape"); throw new QueryParsingException(parseContext, "Field [" + fieldName + "] is not a geo_shape");
} }
GeoShapeFieldMapper shapeFieldMapper = (GeoShapeFieldMapper) fieldMapper; GeoShapeFieldMapper shapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;

View File

@ -93,7 +93,7 @@ public class GeoShapeQueryParser implements QueryParser {
} else if ("relation".equals(currentFieldName)) { } else if ("relation".equals(currentFieldName)) {
shapeRelation = ShapeRelation.getRelationByName(parser.text()); shapeRelation = ShapeRelation.getRelationByName(parser.text());
if (shapeRelation == null) { if (shapeRelation == null) {
throw new QueryParsingException(parseContext.index(), "Unknown shape operation [" + parser.text() + " ]"); throw new QueryParsingException(parseContext, "Unknown shape operation [" + parser.text() + " ]");
} }
} else if ("indexed_shape".equals(currentFieldName) || "indexedShape".equals(currentFieldName)) { } else if ("indexed_shape".equals(currentFieldName) || "indexedShape".equals(currentFieldName)) {
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
@ -112,13 +112,13 @@ public class GeoShapeQueryParser implements QueryParser {
} }
} }
if (id == null) { if (id == null) {
throw new QueryParsingException(parseContext.index(), "ID for indexed shape not provided"); throw new QueryParsingException(parseContext, "ID for indexed shape not provided");
} else if (type == null) { } else if (type == null) {
throw new QueryParsingException(parseContext.index(), "Type for indexed shape not provided"); throw new QueryParsingException(parseContext, "Type for indexed shape not provided");
} }
shape = fetchService.fetch(id, type, index, shapePath); shape = fetchService.fetch(id, type, index, shapePath);
} else { } else {
throw new QueryParsingException(parseContext.index(), "[geo_shape] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[geo_shape] query does not support [" + currentFieldName + "]");
} }
} }
} }
@ -128,26 +128,26 @@ public class GeoShapeQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[geo_shape] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[geo_shape] query does not support [" + currentFieldName + "]");
} }
} }
} }
if (shape == null) { if (shape == null) {
throw new QueryParsingException(parseContext.index(), "No Shape defined"); throw new QueryParsingException(parseContext, "No Shape defined");
} else if (shapeRelation == null) { } else if (shapeRelation == null) {
throw new QueryParsingException(parseContext.index(), "No Shape Relation defined"); throw new QueryParsingException(parseContext, "No Shape Relation defined");
} }
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName); MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
if (smartNameFieldMappers == null || !smartNameFieldMappers.hasMapper()) { if (smartNameFieldMappers == null || !smartNameFieldMappers.hasMapper()) {
throw new QueryParsingException(parseContext.index(), "Failed to find geo_shape field [" + fieldName + "]"); throw new QueryParsingException(parseContext, "Failed to find geo_shape field [" + fieldName + "]");
} }
FieldMapper fieldMapper = smartNameFieldMappers.mapper(); FieldMapper fieldMapper = smartNameFieldMappers.mapper();
// TODO: This isn't the nicest way to check this // TODO: This isn't the nicest way to check this
if (!(fieldMapper instanceof GeoShapeFieldMapper)) { if (!(fieldMapper instanceof GeoShapeFieldMapper)) {
throw new QueryParsingException(parseContext.index(), "Field [" + fieldName + "] is not a geo_shape"); throw new QueryParsingException(parseContext, "Field [" + fieldName + "] is not a geo_shape");
} }
GeoShapeFieldMapper shapeFieldMapper = (GeoShapeFieldMapper) fieldMapper; GeoShapeFieldMapper shapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;

View File

@ -265,22 +265,23 @@ public class GeohashCellFilter {
} }
if (geohash == null) { if (geohash == null) {
throw new QueryParsingException(parseContext.index(), "no geohash value provided to geohash_cell filter"); throw new QueryParsingException(parseContext, "no geohash value provided to geohash_cell filter");
} }
MapperService.SmartNameFieldMappers smartMappers = parseContext.smartFieldMappers(fieldName); MapperService.SmartNameFieldMappers smartMappers = parseContext.smartFieldMappers(fieldName);
if (smartMappers == null || !smartMappers.hasMapper()) { if (smartMappers == null || !smartMappers.hasMapper()) {
throw new QueryParsingException(parseContext.index(), "failed to find geo_point field [" + fieldName + "]"); throw new QueryParsingException(parseContext, "failed to find geo_point field [" + fieldName + "]");
} }
FieldMapper<?> mapper = smartMappers.mapper(); FieldMapper<?> mapper = smartMappers.mapper();
if (!(mapper instanceof GeoPointFieldMapper)) { if (!(mapper instanceof GeoPointFieldMapper)) {
throw new QueryParsingException(parseContext.index(), "field [" + fieldName + "] is not a geo_point field"); throw new QueryParsingException(parseContext, "field [" + fieldName + "] is not a geo_point field");
} }
GeoPointFieldMapper geoMapper = ((GeoPointFieldMapper) mapper); GeoPointFieldMapper geoMapper = ((GeoPointFieldMapper) mapper);
if (!geoMapper.isEnableGeohashPrefix()) { if (!geoMapper.isEnableGeohashPrefix()) {
throw new QueryParsingException(parseContext.index(), "can't execute geohash_cell on field [" + fieldName + "], geohash_prefix is not enabled"); throw new QueryParsingException(parseContext, "can't execute geohash_cell on field [" + fieldName
+ "], geohash_prefix is not enabled");
} }
if(levels > 0) { if(levels > 0) {

View File

@ -94,7 +94,7 @@ public class HasChildFilterParser implements FilterParser {
} else if ("inner_hits".equals(currentFieldName)) { } else if ("inner_hits".equals(currentFieldName)) {
innerHits = innerHitsQueryParserHelper.parse(parseContext); innerHits = innerHitsQueryParserHelper.parse(parseContext);
} else { } else {
throw new QueryParsingException(parseContext.index(), "[has_child] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[has_child] filter does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("type".equals(currentFieldName) || "child_type".equals(currentFieldName) || "childType".equals(currentFieldName)) { if ("type".equals(currentFieldName) || "child_type".equals(currentFieldName) || "childType".equals(currentFieldName)) {
@ -112,15 +112,15 @@ public class HasChildFilterParser implements FilterParser {
} else if ("max_children".equals(currentFieldName) || "maxChildren".equals(currentFieldName)) { } else if ("max_children".equals(currentFieldName) || "maxChildren".equals(currentFieldName)) {
maxChildren = parser.intValue(true); maxChildren = parser.intValue(true);
} else { } else {
throw new QueryParsingException(parseContext.index(), "[has_child] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[has_child] filter does not support [" + currentFieldName + "]");
} }
} }
} }
if (!queryFound && !filterFound) { if (!queryFound && !filterFound) {
throw new QueryParsingException(parseContext.index(), "[has_child] filter requires 'query' or 'filter' field"); throw new QueryParsingException(parseContext, "[has_child] filter requires 'query' or 'filter' field");
} }
if (childType == null) { if (childType == null) {
throw new QueryParsingException(parseContext.index(), "[has_child] filter requires 'type' field"); throw new QueryParsingException(parseContext, "[has_child] filter requires 'type' field");
} }
Query query; Query query;
@ -136,7 +136,7 @@ public class HasChildFilterParser implements FilterParser {
DocumentMapper childDocMapper = parseContext.mapperService().documentMapper(childType); DocumentMapper childDocMapper = parseContext.mapperService().documentMapper(childType);
if (childDocMapper == null) { if (childDocMapper == null) {
throw new QueryParsingException(parseContext.index(), "No mapping for for type [" + childType + "]"); throw new QueryParsingException(parseContext, "No mapping for for type [" + childType + "]");
} }
if (innerHits != null) { if (innerHits != null) {
InnerHitsContext.ParentChildInnerHits parentChildInnerHits = new InnerHitsContext.ParentChildInnerHits(innerHits.v2(), query, null, childDocMapper); InnerHitsContext.ParentChildInnerHits parentChildInnerHits = new InnerHitsContext.ParentChildInnerHits(innerHits.v2(), query, null, childDocMapper);
@ -145,7 +145,7 @@ public class HasChildFilterParser implements FilterParser {
} }
ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper(); ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper();
if (!parentFieldMapper.active()) { if (!parentFieldMapper.active()) {
throw new QueryParsingException(parseContext.index(), "Type [" + childType + "] does not have parent mapping"); throw new QueryParsingException(parseContext, "Type [" + childType + "] does not have parent mapping");
} }
String parentType = parentFieldMapper.type(); String parentType = parentFieldMapper.type();
@ -154,11 +154,12 @@ public class HasChildFilterParser implements FilterParser {
DocumentMapper parentDocMapper = parseContext.mapperService().documentMapper(parentType); DocumentMapper parentDocMapper = parseContext.mapperService().documentMapper(parentType);
if (parentDocMapper == null) { if (parentDocMapper == null) {
throw new QueryParsingException(parseContext.index(), "[has_child] Type [" + childType + "] points to a non existent parent type [" + parentType + "]"); throw new QueryParsingException(parseContext, "[has_child] Type [" + childType + "] points to a non existent parent type ["
+ parentType + "]");
} }
if (maxChildren > 0 && maxChildren < minChildren) { if (maxChildren > 0 && maxChildren < minChildren) {
throw new QueryParsingException(parseContext.index(), "[has_child] 'max_children' is less than 'min_children'"); throw new QueryParsingException(parseContext, "[has_child] 'max_children' is less than 'min_children'");
} }
BitDocIdSetFilter nonNestedDocsFilter = null; BitDocIdSetFilter nonNestedDocsFilter = null;

View File

@ -92,7 +92,7 @@ public class HasChildQueryParser implements QueryParser {
} else if ("inner_hits".equals(currentFieldName)) { } else if ("inner_hits".equals(currentFieldName)) {
innerHits = innerHitsQueryParserHelper.parse(parseContext); innerHits = innerHitsQueryParserHelper.parse(parseContext);
} else { } else {
throw new QueryParsingException(parseContext.index(), "[has_child] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[has_child] query does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("type".equals(currentFieldName) || "child_type".equals(currentFieldName) || "childType".equals(currentFieldName)) { if ("type".equals(currentFieldName) || "child_type".equals(currentFieldName) || "childType".equals(currentFieldName)) {
@ -112,15 +112,15 @@ public class HasChildQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[has_child] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[has_child] query does not support [" + currentFieldName + "]");
} }
} }
} }
if (!queryFound) { if (!queryFound) {
throw new QueryParsingException(parseContext.index(), "[has_child] requires 'query' field"); throw new QueryParsingException(parseContext, "[has_child] requires 'query' field");
} }
if (childType == null) { if (childType == null) {
throw new QueryParsingException(parseContext.index(), "[has_child] requires 'type' field"); throw new QueryParsingException(parseContext, "[has_child] requires 'type' field");
} }
Query innerQuery = iq.asQuery(childType); Query innerQuery = iq.asQuery(childType);
@ -132,10 +132,10 @@ public class HasChildQueryParser implements QueryParser {
DocumentMapper childDocMapper = parseContext.mapperService().documentMapper(childType); DocumentMapper childDocMapper = parseContext.mapperService().documentMapper(childType);
if (childDocMapper == null) { if (childDocMapper == null) {
throw new QueryParsingException(parseContext.index(), "[has_child] No mapping for for type [" + childType + "]"); throw new QueryParsingException(parseContext, "[has_child] No mapping for for type [" + childType + "]");
} }
if (!childDocMapper.parentFieldMapper().active()) { if (!childDocMapper.parentFieldMapper().active()) {
throw new QueryParsingException(parseContext.index(), "[has_child] Type [" + childType + "] does not have parent mapping"); throw new QueryParsingException(parseContext, "[has_child] Type [" + childType + "] does not have parent mapping");
} }
if (innerHits != null) { if (innerHits != null) {
@ -146,18 +146,18 @@ public class HasChildQueryParser implements QueryParser {
ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper(); ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper();
if (!parentFieldMapper.active()) { if (!parentFieldMapper.active()) {
throw new QueryParsingException(parseContext.index(), "[has_child] _parent field not configured"); throw new QueryParsingException(parseContext, "[has_child] _parent field not configured");
} }
String parentType = parentFieldMapper.type(); String parentType = parentFieldMapper.type();
DocumentMapper parentDocMapper = parseContext.mapperService().documentMapper(parentType); DocumentMapper parentDocMapper = parseContext.mapperService().documentMapper(parentType);
if (parentDocMapper == null) { if (parentDocMapper == null) {
throw new QueryParsingException(parseContext.index(), "[has_child] Type [" + childType throw new QueryParsingException(parseContext, "[has_child] Type [" + childType + "] points to a non existent parent type ["
+ "] points to a non existent parent type [" + parentType + "]"); + parentType + "]");
} }
if (maxChildren > 0 && maxChildren < minChildren) { if (maxChildren > 0 && maxChildren < minChildren) {
throw new QueryParsingException(parseContext.index(), "[has_child] 'max_children' is less than 'min_children'"); throw new QueryParsingException(parseContext, "[has_child] 'max_children' is less than 'min_children'");
} }
BitDocIdSetFilter nonNestedDocsFilter = null; BitDocIdSetFilter nonNestedDocsFilter = null;

View File

@ -83,7 +83,7 @@ public class HasParentFilterParser implements FilterParser {
} else if ("inner_hits".equals(currentFieldName)) { } else if ("inner_hits".equals(currentFieldName)) {
innerHits = innerHitsQueryParserHelper.parse(parseContext); innerHits = innerHitsQueryParserHelper.parse(parseContext);
} else { } else {
throw new QueryParsingException(parseContext.index(), "[has_parent] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[has_parent] filter does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("type".equals(currentFieldName) || "parent_type".equals(currentFieldName) || "parentType".equals(currentFieldName)) { if ("type".equals(currentFieldName) || "parent_type".equals(currentFieldName) || "parentType".equals(currentFieldName)) {
@ -95,15 +95,15 @@ public class HasParentFilterParser implements FilterParser {
} else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) { } else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) {
// noop to be backwards compatible // noop to be backwards compatible
} else { } else {
throw new QueryParsingException(parseContext.index(), "[has_parent] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[has_parent] filter does not support [" + currentFieldName + "]");
} }
} }
} }
if (!queryFound && !filterFound) { if (!queryFound && !filterFound) {
throw new QueryParsingException(parseContext.index(), "[has_parent] filter requires 'query' or 'filter' field"); throw new QueryParsingException(parseContext, "[has_parent] filter requires 'query' or 'filter' field");
} }
if (parentType == null) { if (parentType == null) {
throw new QueryParsingException(parseContext.index(), "[has_parent] filter requires 'parent_type' field"); throw new QueryParsingException(parseContext, "[has_parent] filter requires 'parent_type' field");
} }
Query innerQuery; Query innerQuery;

View File

@ -23,7 +23,6 @@ import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Filter; import org.apache.lucene.search.Filter;
import org.apache.lucene.search.FilteredQuery; import org.apache.lucene.search.FilteredQuery;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryWrapperFilter;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
@ -88,7 +87,7 @@ public class HasParentQueryParser implements QueryParser {
} else if ("inner_hits".equals(currentFieldName)) { } else if ("inner_hits".equals(currentFieldName)) {
innerHits = innerHitsQueryParserHelper.parse(parseContext); innerHits = innerHitsQueryParserHelper.parse(parseContext);
} else { } else {
throw new QueryParsingException(parseContext.index(), "[has_parent] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[has_parent] query does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("type".equals(currentFieldName) || "parent_type".equals(currentFieldName) || "parentType".equals(currentFieldName)) { if ("type".equals(currentFieldName) || "parent_type".equals(currentFieldName) || "parentType".equals(currentFieldName)) {
@ -112,15 +111,15 @@ public class HasParentQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[has_parent] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[has_parent] query does not support [" + currentFieldName + "]");
} }
} }
} }
if (!queryFound) { if (!queryFound) {
throw new QueryParsingException(parseContext.index(), "[has_parent] query requires 'query' field"); throw new QueryParsingException(parseContext, "[has_parent] query requires 'query' field");
} }
if (parentType == null) { if (parentType == null) {
throw new QueryParsingException(parseContext.index(), "[has_parent] query requires 'parent_type' field"); throw new QueryParsingException(parseContext, "[has_parent] query requires 'parent_type' field");
} }
Query innerQuery = iq.asQuery(parentType); Query innerQuery = iq.asQuery(parentType);
@ -145,7 +144,8 @@ public class HasParentQueryParser implements QueryParser {
static Query createParentQuery(Query innerQuery, String parentType, boolean score, QueryParseContext parseContext, Tuple<String, SubSearchContext> innerHits) { static Query createParentQuery(Query innerQuery, String parentType, boolean score, QueryParseContext parseContext, Tuple<String, SubSearchContext> innerHits) {
DocumentMapper parentDocMapper = parseContext.mapperService().documentMapper(parentType); DocumentMapper parentDocMapper = parseContext.mapperService().documentMapper(parentType);
if (parentDocMapper == null) { if (parentDocMapper == null) {
throw new QueryParsingException(parseContext.index(), "[has_parent] query configured 'parent_type' [" + parentType + "] is not a valid type"); throw new QueryParsingException(parseContext, "[has_parent] query configured 'parent_type' [" + parentType
+ "] is not a valid type");
} }
if (innerHits != null) { if (innerHits != null) {
@ -169,7 +169,7 @@ public class HasParentQueryParser implements QueryParser {
} }
} }
if (parentChildIndexFieldData == null) { if (parentChildIndexFieldData == null) {
throw new QueryParsingException(parseContext.index(), "[has_parent] no _parent field configured"); throw new QueryParsingException(parseContext, "[has_parent] no _parent field configured");
} }
Filter parentFilter = null; Filter parentFilter = null;

View File

@ -68,7 +68,7 @@ public class IdsFilterParser implements FilterParser {
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
BytesRef value = parser.utf8BytesOrNull(); BytesRef value = parser.utf8BytesOrNull();
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No value specified for term filter"); throw new QueryParsingException(parseContext, "No value specified for term filter");
} }
ids.add(value); ids.add(value);
} }
@ -77,12 +77,12 @@ public class IdsFilterParser implements FilterParser {
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
String value = parser.textOrNull(); String value = parser.textOrNull();
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No type specified for term filter"); throw new QueryParsingException(parseContext, "No type specified for term filter");
} }
types.add(value); types.add(value);
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[ids] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[ids] filter does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("type".equals(currentFieldName) || "_type".equals(currentFieldName)) { if ("type".equals(currentFieldName) || "_type".equals(currentFieldName)) {
@ -90,13 +90,13 @@ public class IdsFilterParser implements FilterParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
filterName = parser.text(); filterName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[ids] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[ids] filter does not support [" + currentFieldName + "]");
} }
} }
} }
if (!idsProvided) { if (!idsProvided) {
throw new QueryParsingException(parseContext.index(), "[ids] filter requires providing a values element"); throw new QueryParsingException(parseContext, "[ids] filter requires providing a values element");
} }
if (ids.isEmpty()) { if (ids.isEmpty()) {

View File

@ -74,12 +74,12 @@ public class IdsQueryParser implements QueryParser {
(token == XContentParser.Token.VALUE_NUMBER)) { (token == XContentParser.Token.VALUE_NUMBER)) {
BytesRef value = parser.utf8BytesOrNull(); BytesRef value = parser.utf8BytesOrNull();
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No value specified for term filter"); throw new QueryParsingException(parseContext, "No value specified for term filter");
} }
ids.add(value); ids.add(value);
} else { } else {
throw new QueryParsingException(parseContext.index(), throw new QueryParsingException(parseContext, "Illegal value for id, expecting a string or number, got: "
"Illegal value for id, expecting a string or number, got: " + token); + token);
} }
} }
} else if ("types".equals(currentFieldName) || "type".equals(currentFieldName)) { } else if ("types".equals(currentFieldName) || "type".equals(currentFieldName)) {
@ -87,12 +87,12 @@ public class IdsQueryParser implements QueryParser {
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
String value = parser.textOrNull(); String value = parser.textOrNull();
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No type specified for term filter"); throw new QueryParsingException(parseContext, "No type specified for term filter");
} }
types.add(value); types.add(value);
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[ids] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[ids] query does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("type".equals(currentFieldName) || "_type".equals(currentFieldName)) { if ("type".equals(currentFieldName) || "_type".equals(currentFieldName)) {
@ -102,13 +102,13 @@ public class IdsQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[ids] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[ids] query does not support [" + currentFieldName + "]");
} }
} }
} }
if (!idsProvided) { if (!idsProvided) {
throw new QueryParsingException(parseContext.index(), "[ids] query, no ids values provided"); throw new QueryParsingException(parseContext, "[ids] query, no ids values provided");
} }
if (ids.isEmpty()) { if (ids.isEmpty()) {

View File

@ -210,7 +210,7 @@ public class IndexQueryParserService extends AbstractIndexComponent {
} catch (QueryParsingException e) { } catch (QueryParsingException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
throw new QueryParsingException(index, "Failed to parse", e); throw new QueryParsingException(getParseContext(), "Failed to parse", e);
} finally { } finally {
if (parser != null) { if (parser != null) {
parser.close(); parser.close();
@ -230,7 +230,7 @@ public class IndexQueryParserService extends AbstractIndexComponent {
} catch (QueryParsingException e) { } catch (QueryParsingException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
throw new QueryParsingException(index, "Failed to parse", e); throw new QueryParsingException(getParseContext(), "Failed to parse", e);
} finally { } finally {
if (parser != null) { if (parser != null) {
parser.close(); parser.close();
@ -250,7 +250,7 @@ public class IndexQueryParserService extends AbstractIndexComponent {
} catch (QueryParsingException e) { } catch (QueryParsingException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
throw new QueryParsingException(index, "Failed to parse", e); throw new QueryParsingException(context, "Failed to parse", e);
} finally { } finally {
if (parser != null) { if (parser != null) {
parser.close(); parser.close();
@ -266,7 +266,7 @@ public class IndexQueryParserService extends AbstractIndexComponent {
} catch (QueryParsingException e) { } catch (QueryParsingException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
throw new QueryParsingException(index, "Failed to parse [" + source + "]", e); throw new QueryParsingException(getParseContext(), "Failed to parse [" + source + "]", e);
} finally { } finally {
if (parser != null) { if (parser != null) {
parser.close(); parser.close();
@ -282,7 +282,7 @@ public class IndexQueryParserService extends AbstractIndexComponent {
try { try {
return innerParse(context, parser); return innerParse(context, parser);
} catch (IOException e) { } catch (IOException e) {
throw new QueryParsingException(index, "Failed to parse", e); throw new QueryParsingException(context, "Failed to parse", e);
} }
} }
@ -359,7 +359,7 @@ public class IndexQueryParserService extends AbstractIndexComponent {
XContentParser qSourceParser = XContentFactory.xContent(querySource).createParser(querySource); XContentParser qSourceParser = XContentFactory.xContent(querySource).createParser(querySource);
parsedQuery = parse(qSourceParser); parsedQuery = parse(qSourceParser);
} else { } else {
throw new QueryParsingException(index(), "request does not support [" + fieldName + "]"); throw new QueryParsingException(getParseContext(), "request does not support [" + fieldName + "]");
} }
} }
} }
@ -369,10 +369,10 @@ public class IndexQueryParserService extends AbstractIndexComponent {
} catch (QueryParsingException e) { } catch (QueryParsingException e) {
throw e; throw e;
} catch (Throwable e) { } catch (Throwable e) {
throw new QueryParsingException(index, "Failed to parse", e); throw new QueryParsingException(getParseContext(), "Failed to parse", e);
} }
throw new QueryParsingException(index(), "Required query is missing"); throw new QueryParsingException(getParseContext(), "Required query is missing");
} }
private ParsedQuery innerParse(QueryParseContext parseContext, XContentParser parser) throws IOException, QueryParsingException { private ParsedQuery innerParse(QueryParseContext parseContext, XContentParser parser) throws IOException, QueryParsingException {

View File

@ -83,30 +83,30 @@ public class IndicesFilterParser implements FilterParser {
noMatchFilter = parseContext.parseInnerFilter(); noMatchFilter = parseContext.parseInnerFilter();
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[indices] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[indices] filter does not support [" + currentFieldName + "]");
} }
} else if (token == XContentParser.Token.START_ARRAY) { } else if (token == XContentParser.Token.START_ARRAY) {
if ("indices".equals(currentFieldName)) { if ("indices".equals(currentFieldName)) {
if (indicesFound) { if (indicesFound) {
throw new QueryParsingException(parseContext.index(), "[indices] indices or index already specified"); throw new QueryParsingException(parseContext, "[indices] indices or index already specified");
} }
indicesFound = true; indicesFound = true;
Collection<String> indices = new ArrayList<>(); Collection<String> indices = new ArrayList<>();
while (parser.nextToken() != XContentParser.Token.END_ARRAY) { while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
String value = parser.textOrNull(); String value = parser.textOrNull();
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "[indices] no value specified for 'indices' entry"); throw new QueryParsingException(parseContext, "[indices] no value specified for 'indices' entry");
} }
indices.add(value); indices.add(value);
} }
currentIndexMatchesIndices = matchesIndices(parseContext.index().name(), indices.toArray(new String[indices.size()])); currentIndexMatchesIndices = matchesIndices(parseContext.index().name(), indices.toArray(new String[indices.size()]));
} else { } else {
throw new QueryParsingException(parseContext.index(), "[indices] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[indices] filter does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("index".equals(currentFieldName)) { if ("index".equals(currentFieldName)) {
if (indicesFound) { if (indicesFound) {
throw new QueryParsingException(parseContext.index(), "[indices] indices or index already specified"); throw new QueryParsingException(parseContext, "[indices] indices or index already specified");
} }
indicesFound = true; indicesFound = true;
currentIndexMatchesIndices = matchesIndices(parseContext.index().name(), parser.text()); currentIndexMatchesIndices = matchesIndices(parseContext.index().name(), parser.text());
@ -120,15 +120,15 @@ public class IndicesFilterParser implements FilterParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
filterName = parser.text(); filterName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[indices] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[indices] filter does not support [" + currentFieldName + "]");
} }
} }
} }
if (!filterFound) { if (!filterFound) {
throw new QueryParsingException(parseContext.index(), "[indices] requires 'filter' element"); throw new QueryParsingException(parseContext, "[indices] requires 'filter' element");
} }
if (!indicesFound) { if (!indicesFound) {
throw new QueryParsingException(parseContext.index(), "[indices] requires 'indices' or 'index' element"); throw new QueryParsingException(parseContext, "[indices] requires 'indices' or 'index' element");
} }
Filter chosenFilter; Filter chosenFilter;

View File

@ -76,30 +76,30 @@ public class IndicesQueryParser implements QueryParser {
} else if ("no_match_query".equals(currentFieldName)) { } else if ("no_match_query".equals(currentFieldName)) {
innerNoMatchQuery = new XContentStructure.InnerQuery(parseContext, null); innerNoMatchQuery = new XContentStructure.InnerQuery(parseContext, null);
} else { } else {
throw new QueryParsingException(parseContext.index(), "[indices] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[indices] query does not support [" + currentFieldName + "]");
} }
} else if (token == XContentParser.Token.START_ARRAY) { } else if (token == XContentParser.Token.START_ARRAY) {
if ("indices".equals(currentFieldName)) { if ("indices".equals(currentFieldName)) {
if (indicesFound) { if (indicesFound) {
throw new QueryParsingException(parseContext.index(), "[indices] indices or index already specified"); throw new QueryParsingException(parseContext, "[indices] indices or index already specified");
} }
indicesFound = true; indicesFound = true;
Collection<String> indices = new ArrayList<>(); Collection<String> indices = new ArrayList<>();
while (parser.nextToken() != XContentParser.Token.END_ARRAY) { while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
String value = parser.textOrNull(); String value = parser.textOrNull();
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "[indices] no value specified for 'indices' entry"); throw new QueryParsingException(parseContext, "[indices] no value specified for 'indices' entry");
} }
indices.add(value); indices.add(value);
} }
currentIndexMatchesIndices = matchesIndices(parseContext.index().name(), indices.toArray(new String[indices.size()])); currentIndexMatchesIndices = matchesIndices(parseContext.index().name(), indices.toArray(new String[indices.size()]));
} else { } else {
throw new QueryParsingException(parseContext.index(), "[indices] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[indices] query does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("index".equals(currentFieldName)) { if ("index".equals(currentFieldName)) {
if (indicesFound) { if (indicesFound) {
throw new QueryParsingException(parseContext.index(), "[indices] indices or index already specified"); throw new QueryParsingException(parseContext, "[indices] indices or index already specified");
} }
indicesFound = true; indicesFound = true;
currentIndexMatchesIndices = matchesIndices(parseContext.index().name(), parser.text()); currentIndexMatchesIndices = matchesIndices(parseContext.index().name(), parser.text());
@ -113,15 +113,15 @@ public class IndicesQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[indices] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[indices] query does not support [" + currentFieldName + "]");
} }
} }
} }
if (!queryFound) { if (!queryFound) {
throw new QueryParsingException(parseContext.index(), "[indices] requires 'query' element"); throw new QueryParsingException(parseContext, "[indices] requires 'query' element");
} }
if (!indicesFound) { if (!indicesFound) {
throw new QueryParsingException(parseContext.index(), "[indices] requires 'indices' or 'index' element"); throw new QueryParsingException(parseContext, "[indices] requires 'indices' or 'index' element");
} }
Query chosenQuery; Query chosenQuery;

View File

@ -53,13 +53,13 @@ public class LimitFilterParser implements FilterParser {
if ("value".equals(currentFieldName)) { if ("value".equals(currentFieldName)) {
limit = parser.intValue(); limit = parser.intValue();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[limit] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[limit] filter does not support [" + currentFieldName + "]");
} }
} }
} }
if (limit == -1) { if (limit == -1) {
throw new QueryParsingException(parseContext.index(), "No value specified for limit filter"); throw new QueryParsingException(parseContext, "No value specified for limit filter");
} }
// this filter is deprecated and parses to a filter that matches everything // this filter is deprecated and parses to a filter that matches everything

View File

@ -59,7 +59,7 @@ public class MatchAllQueryParser implements QueryParser {
if ("boost".equals(currentFieldName)) { if ("boost".equals(currentFieldName)) {
boost = parser.floatValue(); boost = parser.floatValue();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[match_all] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[match_all] query does not support [" + currentFieldName + "]");
} }
} }
} }

View File

@ -65,7 +65,7 @@ public class MatchQueryParser implements QueryParser {
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
if (token != XContentParser.Token.FIELD_NAME) { if (token != XContentParser.Token.FIELD_NAME) {
throw new QueryParsingException(parseContext.index(), "[match] query malformed, no field"); throw new QueryParsingException(parseContext, "[match] query malformed, no field");
} }
String fieldName = parser.currentName(); String fieldName = parser.currentName();
@ -93,12 +93,12 @@ public class MatchQueryParser implements QueryParser {
} else if ("phrase_prefix".equals(tStr) || "phrasePrefix".equals(currentFieldName)) { } else if ("phrase_prefix".equals(tStr) || "phrasePrefix".equals(currentFieldName)) {
type = MatchQuery.Type.PHRASE_PREFIX; type = MatchQuery.Type.PHRASE_PREFIX;
} else { } else {
throw new QueryParsingException(parseContext.index(), "[match] query does not support type " + tStr); throw new QueryParsingException(parseContext, "[match] query does not support type " + tStr);
} }
} else if ("analyzer".equals(currentFieldName)) { } else if ("analyzer".equals(currentFieldName)) {
String analyzer = parser.text(); String analyzer = parser.text();
if (parseContext.analysisService().analyzer(analyzer) == null) { if (parseContext.analysisService().analyzer(analyzer) == null) {
throw new QueryParsingException(parseContext.index(), "[match] analyzer [" + parser.text() + "] not found"); throw new QueryParsingException(parseContext, "[match] analyzer [" + parser.text() + "] not found");
} }
matchQuery.setAnalyzer(analyzer); matchQuery.setAnalyzer(analyzer);
} else if ("boost".equals(currentFieldName)) { } else if ("boost".equals(currentFieldName)) {
@ -118,7 +118,8 @@ public class MatchQueryParser implements QueryParser {
} else if ("and".equalsIgnoreCase(op)) { } else if ("and".equalsIgnoreCase(op)) {
matchQuery.setOccur(BooleanClause.Occur.MUST); matchQuery.setOccur(BooleanClause.Occur.MUST);
} else { } else {
throw new QueryParsingException(parseContext.index(), "text query requires operator to be either 'and' or 'or', not [" + op + "]"); throw new QueryParsingException(parseContext, "text query requires operator to be either 'and' or 'or', not ["
+ op + "]");
} }
} else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { } else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) {
minimumShouldMatch = parser.textOrNull(); minimumShouldMatch = parser.textOrNull();
@ -139,12 +140,12 @@ public class MatchQueryParser implements QueryParser {
} else if ("all".equalsIgnoreCase(zeroTermsDocs)) { } else if ("all".equalsIgnoreCase(zeroTermsDocs)) {
matchQuery.setZeroTermsQuery(MatchQuery.ZeroTermsQuery.ALL); matchQuery.setZeroTermsQuery(MatchQuery.ZeroTermsQuery.ALL);
} else { } else {
throw new QueryParsingException(parseContext.index(), "Unsupported zero_terms_docs value [" + zeroTermsDocs + "]"); throw new QueryParsingException(parseContext, "Unsupported zero_terms_docs value [" + zeroTermsDocs + "]");
} }
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[match] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[match] query does not support [" + currentFieldName + "]");
} }
} }
} }
@ -154,12 +155,13 @@ public class MatchQueryParser implements QueryParser {
// move to the next token // move to the next token
token = parser.nextToken(); token = parser.nextToken();
if (token != XContentParser.Token.END_OBJECT) { if (token != XContentParser.Token.END_OBJECT) {
throw new QueryParsingException(parseContext.index(), "[match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?"); throw new QueryParsingException(parseContext,
"[match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?");
} }
} }
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No text specified for text query"); throw new QueryParsingException(parseContext, "No text specified for text query");
} }
Query query = matchQuery.parse(type, fieldName, value); Query query = matchQuery.parse(type, fieldName, value);

View File

@ -23,7 +23,6 @@ import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Filter; import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryWrapperFilter;
import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.TermRangeQuery;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.HashedBytesRef; import org.elasticsearch.common.lucene.HashedBytesRef;
@ -78,13 +77,13 @@ public class MissingFilterParser implements FilterParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
filterName = parser.text(); filterName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[missing] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[missing] filter does not support [" + currentFieldName + "]");
} }
} }
} }
if (fieldPattern == null) { if (fieldPattern == null) {
throw new QueryParsingException(parseContext.index(), "missing must be provided with a [field]"); throw new QueryParsingException(parseContext, "missing must be provided with a [field]");
} }
return newFilter(parseContext, fieldPattern, existence, nullValue, filterName); return newFilter(parseContext, fieldPattern, existence, nullValue, filterName);
@ -92,7 +91,7 @@ public class MissingFilterParser implements FilterParser {
public static Filter newFilter(QueryParseContext parseContext, String fieldPattern, boolean existence, boolean nullValue, String filterName) { public static Filter newFilter(QueryParseContext parseContext, String fieldPattern, boolean existence, boolean nullValue, String filterName) {
if (!existence && !nullValue) { if (!existence && !nullValue) {
throw new QueryParsingException(parseContext.index(), "missing must have either existence, or null_value, or both set to true"); throw new QueryParsingException(parseContext, "missing must have either existence, or null_value, or both set to true");
} }
final FieldMappers fieldNamesMappers = parseContext.mapperService().fullName(FieldNamesFieldMapper.NAME); final FieldMappers fieldNamesMappers = parseContext.mapperService().fullName(FieldNamesFieldMapper.NAME);

View File

@ -155,7 +155,7 @@ public class MoreLikeThisQueryParser implements QueryParser {
} else if (Fields.INCLUDE.match(currentFieldName, parseContext.parseFlags())) { } else if (Fields.INCLUDE.match(currentFieldName, parseContext.parseFlags())) {
include = parser.booleanValue(); include = parser.booleanValue();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[mlt] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[mlt] query does not support [" + currentFieldName + "]");
} }
} else if (token == XContentParser.Token.START_ARRAY) { } else if (token == XContentParser.Token.START_ARRAY) {
if (Fields.STOP_WORDS.match(currentFieldName, parseContext.parseFlags())) { if (Fields.STOP_WORDS.match(currentFieldName, parseContext.parseFlags())) {
@ -192,7 +192,7 @@ public class MoreLikeThisQueryParser implements QueryParser {
parseLikeField(parser, ignoreTexts, ignoreItems); parseLikeField(parser, ignoreTexts, ignoreItems);
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[mlt] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[mlt] query does not support [" + currentFieldName + "]");
} }
} else if (token == XContentParser.Token.START_OBJECT) { } else if (token == XContentParser.Token.START_OBJECT) {
if (Fields.LIKE.match(currentFieldName, parseContext.parseFlags())) { if (Fields.LIKE.match(currentFieldName, parseContext.parseFlags())) {
@ -201,16 +201,16 @@ public class MoreLikeThisQueryParser implements QueryParser {
else if (Fields.IGNORE_LIKE.match(currentFieldName, parseContext.parseFlags())) { else if (Fields.IGNORE_LIKE.match(currentFieldName, parseContext.parseFlags())) {
parseLikeField(parser, ignoreTexts, ignoreItems); parseLikeField(parser, ignoreTexts, ignoreItems);
} else { } else {
throw new QueryParsingException(parseContext.index(), "[mlt] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[mlt] query does not support [" + currentFieldName + "]");
} }
} }
} }
if (likeTexts.isEmpty() && likeItems.isEmpty()) { if (likeTexts.isEmpty() && likeItems.isEmpty()) {
throw new QueryParsingException(parseContext.index(), "more_like_this requires 'like' to be specified"); throw new QueryParsingException(parseContext, "more_like_this requires 'like' to be specified");
} }
if (moreLikeFields != null && moreLikeFields.isEmpty()) { if (moreLikeFields != null && moreLikeFields.isEmpty()) {
throw new QueryParsingException(parseContext.index(), "more_like_this requires 'fields' to be non-empty"); throw new QueryParsingException(parseContext, "more_like_this requires 'fields' to be non-empty");
} }
// set analyzer // set analyzer
@ -258,8 +258,9 @@ public class MoreLikeThisQueryParser implements QueryParser {
} }
if (item.type() == null) { if (item.type() == null) {
if (parseContext.queryTypes().size() > 1) { if (parseContext.queryTypes().size() > 1) {
throw new QueryParsingException(parseContext.index(), throw new QueryParsingException(parseContext,
"ambiguous type for item with id: " + item.id() + " and index: " + item.index()); "ambiguous type for item with id: " + item.id()
+ " and index: " + item.index());
} else { } else {
item.type(parseContext.queryTypes().iterator().next()); item.type(parseContext.queryTypes().iterator().next());
} }

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.query; package org.elasticsearch.index.query;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
@ -77,8 +78,7 @@ public class MultiMatchQueryParser implements QueryParser {
} else if (token.isValue()) { } else if (token.isValue()) {
extractFieldAndBoost(parseContext, parser, fieldNameWithBoosts); extractFieldAndBoost(parseContext, parser, fieldNameWithBoosts);
} else { } else {
throw new QueryParsingException(parseContext.index(), "[" + NAME + "] query does not support [" + currentFieldName throw new QueryParsingException(parseContext, "[" + NAME + "] query does not support [" + currentFieldName + "]");
+ "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("query".equals(currentFieldName)) { if ("query".equals(currentFieldName)) {
@ -88,7 +88,7 @@ public class MultiMatchQueryParser implements QueryParser {
} else if ("analyzer".equals(currentFieldName)) { } else if ("analyzer".equals(currentFieldName)) {
String analyzer = parser.text(); String analyzer = parser.text();
if (parseContext.analysisService().analyzer(analyzer) == null) { if (parseContext.analysisService().analyzer(analyzer) == null) {
throw new QueryParsingException(parseContext.index(), "["+ NAME +"] analyzer [" + parser.text() + "] not found"); throw new QueryParsingException(parseContext, "[" + NAME + "] analyzer [" + parser.text() + "] not found");
} }
multiMatchQuery.setAnalyzer(analyzer); multiMatchQuery.setAnalyzer(analyzer);
} else if ("boost".equals(currentFieldName)) { } else if ("boost".equals(currentFieldName)) {
@ -108,7 +108,8 @@ public class MultiMatchQueryParser implements QueryParser {
} else if ("and".equalsIgnoreCase(op)) { } else if ("and".equalsIgnoreCase(op)) {
multiMatchQuery.setOccur(BooleanClause.Occur.MUST); multiMatchQuery.setOccur(BooleanClause.Occur.MUST);
} else { } else {
throw new QueryParsingException(parseContext.index(), "text query requires operator to be either 'and' or 'or', not [" + op + "]"); throw new QueryParsingException(parseContext, "text query requires operator to be either 'and' or 'or', not [" + op
+ "]");
} }
} else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { } else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) {
minimumShouldMatch = parser.textOrNull(); minimumShouldMatch = parser.textOrNull();
@ -131,22 +132,22 @@ public class MultiMatchQueryParser implements QueryParser {
} else if ("all".equalsIgnoreCase(zeroTermsDocs)) { } else if ("all".equalsIgnoreCase(zeroTermsDocs)) {
multiMatchQuery.setZeroTermsQuery(MatchQuery.ZeroTermsQuery.ALL); multiMatchQuery.setZeroTermsQuery(MatchQuery.ZeroTermsQuery.ALL);
} else { } else {
throw new QueryParsingException(parseContext.index(), "Unsupported zero_terms_docs value [" + zeroTermsDocs + "]"); throw new QueryParsingException(parseContext, "Unsupported zero_terms_docs value [" + zeroTermsDocs + "]");
} }
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[match] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[match] query does not support [" + currentFieldName + "]");
} }
} }
} }
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No text specified for multi_match query"); throw new QueryParsingException(parseContext, "No text specified for multi_match query");
} }
if (fieldNameWithBoosts.isEmpty()) { if (fieldNameWithBoosts.isEmpty()) {
throw new QueryParsingException(parseContext.index(), "No fields specified for multi_match query"); throw new QueryParsingException(parseContext, "No fields specified for multi_match query");
} }
if (type == null) { if (type == null) {
type = MultiMatchQueryBuilder.Type.BEST_FIELDS; type = MultiMatchQueryBuilder.Type.BEST_FIELDS;

View File

@ -70,7 +70,7 @@ public class NestedFilterParser implements FilterParser {
} else if ("inner_hits".equals(currentFieldName)) { } else if ("inner_hits".equals(currentFieldName)) {
builder.setInnerHits(innerHitsQueryParserHelper.parse(parseContext)); builder.setInnerHits(innerHitsQueryParserHelper.parse(parseContext));
} else { } else {
throw new QueryParsingException(parseContext.index(), "[nested] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[nested] filter does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("path".equals(currentFieldName)) { if ("path".equals(currentFieldName)) {
@ -84,7 +84,7 @@ public class NestedFilterParser implements FilterParser {
} else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) { } else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) {
cacheKey = new HashedBytesRef(parser.text()); cacheKey = new HashedBytesRef(parser.text());
} else { } else {
throw new QueryParsingException(parseContext.index(), "[nested] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[nested] filter does not support [" + currentFieldName + "]");
} }
} }
} }

View File

@ -75,7 +75,7 @@ public class NestedQueryParser implements QueryParser {
} else if ("inner_hits".equals(currentFieldName)) { } else if ("inner_hits".equals(currentFieldName)) {
builder.setInnerHits(innerHitsQueryParserHelper.parse(parseContext)); builder.setInnerHits(innerHitsQueryParserHelper.parse(parseContext));
} else { } else {
throw new QueryParsingException(parseContext.index(), "[nested] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[nested] query does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("path".equals(currentFieldName)) { if ("path".equals(currentFieldName)) {
@ -93,12 +93,12 @@ public class NestedQueryParser implements QueryParser {
} else if ("none".equals(sScoreMode)) { } else if ("none".equals(sScoreMode)) {
scoreMode = ScoreMode.None; scoreMode = ScoreMode.None;
} else { } else {
throw new QueryParsingException(parseContext.index(), "illegal score_mode for nested query [" + sScoreMode + "]"); throw new QueryParsingException(parseContext, "illegal score_mode for nested query [" + sScoreMode + "]");
} }
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[nested] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[nested] query does not support [" + currentFieldName + "]");
} }
} }
} }
@ -144,7 +144,7 @@ public class NestedQueryParser implements QueryParser {
innerQuery = null; innerQuery = null;
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[nested] requires either 'query' or 'filter' field"); throw new QueryParsingException(parseContext, "[nested] requires either 'query' or 'filter' field");
} }
if (innerHits != null) { if (innerHits != null) {

View File

@ -20,7 +20,6 @@
package org.elasticsearch.index.query; package org.elasticsearch.index.query;
import org.apache.lucene.search.Filter; import org.apache.lucene.search.Filter;
import org.apache.lucene.search.QueryWrapperFilter;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.HashedBytesRef; import org.elasticsearch.common.lucene.HashedBytesRef;
import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.lucene.search.Queries;
@ -80,13 +79,13 @@ public class NotFilterParser implements FilterParser {
} else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) { } else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) {
cacheKey = new HashedBytesRef(parser.text()); cacheKey = new HashedBytesRef(parser.text());
} else { } else {
throw new QueryParsingException(parseContext.index(), "[not] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[not] filter does not support [" + currentFieldName + "]");
} }
} }
} }
if (!filterFound) { if (!filterFound) {
throw new QueryParsingException(parseContext.index(), "filter is required when using `not` filter"); throw new QueryParsingException(parseContext, "filter is required when using `not` filter");
} }
if (filter == null) { if (filter == null) {

View File

@ -100,14 +100,14 @@ public class OrFilterParser implements FilterParser {
} else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) { } else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) {
cacheKey = new HashedBytesRef(parser.text()); cacheKey = new HashedBytesRef(parser.text());
} else { } else {
throw new QueryParsingException(parseContext.index(), "[or] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[or] filter does not support [" + currentFieldName + "]");
} }
} }
} }
} }
if (!filtersFound) { if (!filtersFound) {
throw new QueryParsingException(parseContext.index(), "[or] filter requires 'filters' to be set on it'"); throw new QueryParsingException(parseContext, "[or] filter requires 'filters' to be set on it'");
} }
if (filters.isEmpty()) { if (filters.isEmpty()) {

View File

@ -78,7 +78,7 @@ public class PrefixFilterParser implements FilterParser {
} }
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No value specified for prefix filter"); throw new QueryParsingException(parseContext, "No value specified for prefix filter");
} }
Filter filter = null; Filter filter = null;

View File

@ -53,7 +53,7 @@ public class PrefixQueryParser implements QueryParser {
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
if (token != XContentParser.Token.FIELD_NAME) { if (token != XContentParser.Token.FIELD_NAME) {
throw new QueryParsingException(parseContext.index(), "[prefix] query malformed, no field"); throw new QueryParsingException(parseContext, "[prefix] query malformed, no field");
} }
String fieldName = parser.currentName(); String fieldName = parser.currentName();
String rewriteMethod = null; String rewriteMethod = null;
@ -80,7 +80,7 @@ public class PrefixQueryParser implements QueryParser {
queryName = parser.text(); queryName = parser.text();
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[prefix] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[prefix] query does not support [" + currentFieldName + "]");
} }
} }
parser.nextToken(); parser.nextToken();
@ -90,7 +90,7 @@ public class PrefixQueryParser implements QueryParser {
} }
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No value specified for prefix query"); throw new QueryParsingException(parseContext, "No value specified for prefix query");
} }
MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(rewriteMethod, null); MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(rewriteMethod, null);

View File

@ -292,23 +292,23 @@ public class QueryParseContext {
if (parser.currentToken() != XContentParser.Token.START_OBJECT) { if (parser.currentToken() != XContentParser.Token.START_OBJECT) {
token = parser.nextToken(); token = parser.nextToken();
if (token != XContentParser.Token.START_OBJECT) { if (token != XContentParser.Token.START_OBJECT) {
throw new QueryParsingException(index, "[_na] query malformed, must start with start_object"); throw new QueryParsingException(this, "[_na] query malformed, must start with start_object");
} }
} }
token = parser.nextToken(); token = parser.nextToken();
if (token != XContentParser.Token.FIELD_NAME) { if (token != XContentParser.Token.FIELD_NAME) {
throw new QueryParsingException(index, "[_na] query malformed, no field after start_object"); throw new QueryParsingException(this, "[_na] query malformed, no field after start_object");
} }
String queryName = parser.currentName(); String queryName = parser.currentName();
// move to the next START_OBJECT // move to the next START_OBJECT
token = parser.nextToken(); token = parser.nextToken();
if (token != XContentParser.Token.START_OBJECT && token != XContentParser.Token.START_ARRAY) { if (token != XContentParser.Token.START_OBJECT && token != XContentParser.Token.START_ARRAY) {
throw new QueryParsingException(index, "[_na] query malformed, no field after start_object"); throw new QueryParsingException(this, "[_na] query malformed, no field after start_object");
} }
QueryParser queryParser = indexQueryParser.queryParser(queryName); QueryParser queryParser = indexQueryParser.queryParser(queryName);
if (queryParser == null) { if (queryParser == null) {
throw new QueryParsingException(index, "No query registered for [" + queryName + "]"); throw new QueryParsingException(this, "No query registered for [" + queryName + "]");
} }
Query result = queryParser.parse(this); Query result = queryParser.parse(this);
if (parser.currentToken() == XContentParser.Token.END_OBJECT || parser.currentToken() == XContentParser.Token.END_ARRAY) { if (parser.currentToken() == XContentParser.Token.END_OBJECT || parser.currentToken() == XContentParser.Token.END_ARRAY) {
@ -335,7 +335,7 @@ public class QueryParseContext {
if (parser.currentToken() != XContentParser.Token.START_OBJECT) { if (parser.currentToken() != XContentParser.Token.START_OBJECT) {
token = parser.nextToken(); token = parser.nextToken();
if (token != XContentParser.Token.START_OBJECT) { if (token != XContentParser.Token.START_OBJECT) {
throw new QueryParsingException(index, "[_na] filter malformed, must start with start_object"); throw new QueryParsingException(this, "[_na] filter malformed, must start with start_object");
} }
} }
token = parser.nextToken(); token = parser.nextToken();
@ -344,18 +344,18 @@ public class QueryParseContext {
if (token == XContentParser.Token.END_OBJECT || token == XContentParser.Token.VALUE_NULL) { if (token == XContentParser.Token.END_OBJECT || token == XContentParser.Token.VALUE_NULL) {
return null; return null;
} }
throw new QueryParsingException(index, "[_na] filter malformed, no field after start_object"); throw new QueryParsingException(this, "[_na] filter malformed, no field after start_object");
} }
String filterName = parser.currentName(); String filterName = parser.currentName();
// move to the next START_OBJECT or START_ARRAY // move to the next START_OBJECT or START_ARRAY
token = parser.nextToken(); token = parser.nextToken();
if (token != XContentParser.Token.START_OBJECT && token != XContentParser.Token.START_ARRAY) { if (token != XContentParser.Token.START_OBJECT && token != XContentParser.Token.START_ARRAY) {
throw new QueryParsingException(index, "[_na] filter malformed, no field after start_object"); throw new QueryParsingException(this, "[_na] filter malformed, no field after start_object");
} }
FilterParser filterParser = indexQueryParser.filterParser(filterName); FilterParser filterParser = indexQueryParser.filterParser(filterName);
if (filterParser == null) { if (filterParser == null) {
throw new QueryParsingException(index, "No filter registered for [" + filterName + "]"); throw new QueryParsingException(this, "No filter registered for [" + filterName + "]");
} }
Filter result = executeFilterParser(filterParser); Filter result = executeFilterParser(filterParser);
if (parser.currentToken() == XContentParser.Token.END_OBJECT || parser.currentToken() == XContentParser.Token.END_ARRAY) { if (parser.currentToken() == XContentParser.Token.END_OBJECT || parser.currentToken() == XContentParser.Token.END_ARRAY) {
@ -368,7 +368,7 @@ public class QueryParseContext {
public Filter parseInnerFilter(String filterName) throws IOException, QueryParsingException { public Filter parseInnerFilter(String filterName) throws IOException, QueryParsingException {
FilterParser filterParser = indexQueryParser.filterParser(filterName); FilterParser filterParser = indexQueryParser.filterParser(filterName);
if (filterParser == null) { if (filterParser == null) {
throw new QueryParsingException(index, "No filter registered for [" + filterName + "]"); throw new QueryParsingException(this, "No filter registered for [" + filterName + "]");
} }
return executeFilterParser(filterParser); return executeFilterParser(filterParser);
} }
@ -432,7 +432,8 @@ public class QueryParseContext {
} else { } else {
Version indexCreatedVersion = indexQueryParser.getIndexCreatedVersion(); Version indexCreatedVersion = indexQueryParser.getIndexCreatedVersion();
if (fieldMapping == null && indexCreatedVersion.onOrAfter(Version.V_1_4_0_Beta1)) { if (fieldMapping == null && indexCreatedVersion.onOrAfter(Version.V_1_4_0_Beta1)) {
throw new QueryParsingException(index, "Strict field resolution and no field mapping can be found for the field with name [" + name + "]"); throw new QueryParsingException(this, "Strict field resolution and no field mapping can be found for the field with name ["
+ name + "]");
} else { } else {
return fieldMapping; return fieldMapping;
} }

View File

@ -19,21 +19,67 @@
package org.elasticsearch.index.query; package org.elasticsearch.index.query;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentLocation;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.Index; import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexException; import org.elasticsearch.index.IndexException;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
/** /**
* *
*/ */
public class QueryParsingException extends IndexException { public class QueryParsingException extends IndexException {
public QueryParsingException(Index index, String msg) { static final int UNKNOWN_POSITION = -1;
super(index, msg); private int lineNumber = UNKNOWN_POSITION;
private int columnNumber = UNKNOWN_POSITION;
public QueryParsingException(QueryParseContext parseContext, String msg) {
this(parseContext, msg, null);
} }
public QueryParsingException(Index index, String msg, Throwable cause) { public QueryParsingException(QueryParseContext parseContext, String msg, Throwable cause) {
super(parseContext.index(), msg, cause);
XContentParser parser = parseContext.parser();
if (parser != null) {
XContentLocation location = parser.getTokenLocation();
if (location != null) {
lineNumber = location.lineNumber;
columnNumber = location.columnNumber;
}
}
}
/**
* This constructor is provided for use in unit tests where a
* {@link QueryParseContext} may not be available
*/
QueryParsingException(Index index, int line, int col, String msg, Throwable cause) {
super(index, msg, cause); super(index, msg, cause);
this.lineNumber = line;
this.columnNumber = col;
}
/**
* Line number of the location of the error
*
* @return the line number or -1 if unknown
*/
public int getLineNumber() {
return lineNumber;
}
/**
* Column number of the location of the error
*
* @return the column number or -1 if unknown
*/
public int getColumnNumber() {
return columnNumber;
} }
@Override @Override
@ -41,4 +87,13 @@ public class QueryParsingException extends IndexException {
return RestStatus.BAD_REQUEST; return RestStatus.BAD_REQUEST;
} }
@Override
protected void innerToXContent(XContentBuilder builder, Params params) throws IOException {
if (lineNumber != UNKNOWN_POSITION) {
builder.field("line", lineNumber);
builder.field("col", columnNumber);
}
super.innerToXContent(builder, params);
}
} }

View File

@ -126,7 +126,8 @@ public class QueryStringQueryParser implements QueryParser {
} }
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[query_string] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[query_string] query does not support [" + currentFieldName
+ "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("query".equals(currentFieldName)) { if ("query".equals(currentFieldName)) {
@ -140,18 +141,19 @@ public class QueryStringQueryParser implements QueryParser {
} else if ("and".equalsIgnoreCase(op)) { } else if ("and".equalsIgnoreCase(op)) {
qpSettings.defaultOperator(org.apache.lucene.queryparser.classic.QueryParser.Operator.AND); qpSettings.defaultOperator(org.apache.lucene.queryparser.classic.QueryParser.Operator.AND);
} else { } else {
throw new QueryParsingException(parseContext.index(), "Query default operator [" + op + "] is not allowed"); throw new QueryParsingException(parseContext, "Query default operator [" + op + "] is not allowed");
} }
} else if ("analyzer".equals(currentFieldName)) { } else if ("analyzer".equals(currentFieldName)) {
NamedAnalyzer analyzer = parseContext.analysisService().analyzer(parser.text()); NamedAnalyzer analyzer = parseContext.analysisService().analyzer(parser.text());
if (analyzer == null) { if (analyzer == null) {
throw new QueryParsingException(parseContext.index(), "[query_string] analyzer [" + parser.text() + "] not found"); throw new QueryParsingException(parseContext, "[query_string] analyzer [" + parser.text() + "] not found");
} }
qpSettings.forcedAnalyzer(analyzer); qpSettings.forcedAnalyzer(analyzer);
} else if ("quote_analyzer".equals(currentFieldName) || "quoteAnalyzer".equals(currentFieldName)) { } else if ("quote_analyzer".equals(currentFieldName) || "quoteAnalyzer".equals(currentFieldName)) {
NamedAnalyzer analyzer = parseContext.analysisService().analyzer(parser.text()); NamedAnalyzer analyzer = parseContext.analysisService().analyzer(parser.text());
if (analyzer == null) { if (analyzer == null) {
throw new QueryParsingException(parseContext.index(), "[query_string] quote_analyzer [" + parser.text() + "] not found"); throw new QueryParsingException(parseContext, "[query_string] quote_analyzer [" + parser.text()
+ "] not found");
} }
qpSettings.forcedQuoteAnalyzer(analyzer); qpSettings.forcedQuoteAnalyzer(analyzer);
} else if ("allow_leading_wildcard".equals(currentFieldName) || "allowLeadingWildcard".equals(currentFieldName)) { } else if ("allow_leading_wildcard".equals(currentFieldName) || "allowLeadingWildcard".equals(currentFieldName)) {
@ -199,17 +201,19 @@ public class QueryStringQueryParser implements QueryParser {
try { try {
qpSettings.timeZone(DateTimeZone.forID(parser.text())); qpSettings.timeZone(DateTimeZone.forID(parser.text()));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new QueryParsingException(parseContext.index(), "[query_string] time_zone [" + parser.text() + "] is unknown"); throw new QueryParsingException(parseContext,
"[query_string] time_zone [" + parser.text() + "] is unknown");
} }
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[query_string] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[query_string] query does not support [" + currentFieldName
+ "]");
} }
} }
} }
if (qpSettings.queryString() == null) { if (qpSettings.queryString() == null) {
throw new QueryParsingException(parseContext.index(), "query_string must be provided with a [query]"); throw new QueryParsingException(parseContext, "query_string must be provided with a [query]");
} }
qpSettings.defaultAnalyzer(parseContext.mapperService().searchAnalyzer()); qpSettings.defaultAnalyzer(parseContext.mapperService().searchAnalyzer());
qpSettings.defaultQuoteAnalyzer(parseContext.mapperService().searchQuoteAnalyzer()); qpSettings.defaultQuoteAnalyzer(parseContext.mapperService().searchQuoteAnalyzer());
@ -239,7 +243,7 @@ public class QueryStringQueryParser implements QueryParser {
} }
return query; return query;
} catch (org.apache.lucene.queryparser.classic.ParseException e) { } catch (org.apache.lucene.queryparser.classic.ParseException e) {
throw new QueryParsingException(parseContext.index(), "Failed to parse query [" + qpSettings.queryString() + "]", e); throw new QueryParsingException(parseContext, "Failed to parse query [" + qpSettings.queryString() + "]", e);
} }
} }
} }

View File

@ -105,7 +105,7 @@ public class RangeFilterParser implements FilterParser {
} else if ("format".equals(currentFieldName)) { } else if ("format".equals(currentFieldName)) {
forcedDateParser = new DateMathParser(Joda.forPattern(parser.text()), DateFieldMapper.Defaults.TIME_UNIT); forcedDateParser = new DateMathParser(Joda.forPattern(parser.text()), DateFieldMapper.Defaults.TIME_UNIT);
} else { } else {
throw new QueryParsingException(parseContext.index(), "[range] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[range] filter does not support [" + currentFieldName + "]");
} }
} }
} }
@ -119,13 +119,13 @@ public class RangeFilterParser implements FilterParser {
} else if ("execution".equals(currentFieldName)) { } else if ("execution".equals(currentFieldName)) {
execution = parser.text(); execution = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[range] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[range] filter does not support [" + currentFieldName + "]");
} }
} }
} }
if (fieldName == null) { if (fieldName == null) {
throw new QueryParsingException(parseContext.index(), "[range] filter no field specified for range filter"); throw new QueryParsingException(parseContext, "[range] filter no field specified for range filter");
} }
Filter filter = null; Filter filter = null;
@ -136,33 +136,39 @@ public class RangeFilterParser implements FilterParser {
FieldMapper mapper = smartNameFieldMappers.mapper(); FieldMapper mapper = smartNameFieldMappers.mapper();
if (mapper instanceof DateFieldMapper) { if (mapper instanceof DateFieldMapper) {
if ((from instanceof Number || to instanceof Number) && timeZone != null) { if ((from instanceof Number || to instanceof Number) && timeZone != null) {
throw new QueryParsingException(parseContext.index(), "[range] time_zone when using ms since epoch format as it's UTC based can not be applied to [" + fieldName + "]"); throw new QueryParsingException(parseContext,
"[range] time_zone when using ms since epoch format as it's UTC based can not be applied to ["
+ fieldName + "]");
} }
filter = ((DateFieldMapper) mapper).rangeFilter(from, to, includeLower, includeUpper, timeZone, forcedDateParser, parseContext); filter = ((DateFieldMapper) mapper).rangeFilter(from, to, includeLower, includeUpper, timeZone, forcedDateParser, parseContext);
} else { } else {
if (timeZone != null) { if (timeZone != null) {
throw new QueryParsingException(parseContext.index(), "[range] time_zone can not be applied to non date field [" + fieldName + "]"); throw new QueryParsingException(parseContext, "[range] time_zone can not be applied to non date field ["
+ fieldName + "]");
} }
filter = mapper.rangeFilter(from, to, includeLower, includeUpper, parseContext); filter = mapper.rangeFilter(from, to, includeLower, includeUpper, parseContext);
} }
} else if ("fielddata".equals(execution)) { } else if ("fielddata".equals(execution)) {
FieldMapper mapper = smartNameFieldMappers.mapper(); FieldMapper mapper = smartNameFieldMappers.mapper();
if (!(mapper instanceof NumberFieldMapper)) { if (!(mapper instanceof NumberFieldMapper)) {
throw new QueryParsingException(parseContext.index(), "[range] filter field [" + fieldName + "] is not a numeric type"); throw new QueryParsingException(parseContext, "[range] filter field [" + fieldName + "] is not a numeric type");
} }
if (mapper instanceof DateFieldMapper) { if (mapper instanceof DateFieldMapper) {
if ((from instanceof Number || to instanceof Number) && timeZone != null) { if ((from instanceof Number || to instanceof Number) && timeZone != null) {
throw new QueryParsingException(parseContext.index(), "[range] time_zone when using ms since epoch format as it's UTC based can not be applied to [" + fieldName + "]"); throw new QueryParsingException(parseContext,
"[range] time_zone when using ms since epoch format as it's UTC based can not be applied to ["
+ fieldName + "]");
} }
filter = ((DateFieldMapper) mapper).rangeFilter(parseContext, from, to, includeLower, includeUpper, timeZone, forcedDateParser, parseContext); filter = ((DateFieldMapper) mapper).rangeFilter(parseContext, from, to, includeLower, includeUpper, timeZone, forcedDateParser, parseContext);
} else { } else {
if (timeZone != null) { if (timeZone != null) {
throw new QueryParsingException(parseContext.index(), "[range] time_zone can not be applied to non date field [" + fieldName + "]"); throw new QueryParsingException(parseContext, "[range] time_zone can not be applied to non date field ["
+ fieldName + "]");
} }
filter = ((NumberFieldMapper) mapper).rangeFilter(parseContext, from, to, includeLower, includeUpper, parseContext); filter = ((NumberFieldMapper) mapper).rangeFilter(parseContext, from, to, includeLower, includeUpper, parseContext);
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[range] filter doesn't support [" + execution + "] execution"); throw new QueryParsingException(parseContext, "[range] filter doesn't support [" + execution + "] execution");
} }
} }
} }

View File

@ -55,12 +55,12 @@ public class RangeQueryParser implements QueryParser {
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
if (token != XContentParser.Token.FIELD_NAME) { if (token != XContentParser.Token.FIELD_NAME) {
throw new QueryParsingException(parseContext.index(), "[range] query malformed, no field to indicate field name"); throw new QueryParsingException(parseContext, "[range] query malformed, no field to indicate field name");
} }
String fieldName = parser.currentName(); String fieldName = parser.currentName();
token = parser.nextToken(); token = parser.nextToken();
if (token != XContentParser.Token.START_OBJECT) { if (token != XContentParser.Token.START_OBJECT) {
throw new QueryParsingException(parseContext.index(), "[range] query malformed, after field missing start object"); throw new QueryParsingException(parseContext, "[range] query malformed, after field missing start object");
} }
Object from = null; Object from = null;
@ -106,7 +106,7 @@ public class RangeQueryParser implements QueryParser {
} else if ("format".equals(currentFieldName)) { } else if ("format".equals(currentFieldName)) {
forcedDateParser = new DateMathParser(Joda.forPattern(parser.text()), DateFieldMapper.Defaults.TIME_UNIT); forcedDateParser = new DateMathParser(Joda.forPattern(parser.text()), DateFieldMapper.Defaults.TIME_UNIT);
} else { } else {
throw new QueryParsingException(parseContext.index(), "[range] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[range] query does not support [" + currentFieldName + "]");
} }
} }
} }
@ -114,7 +114,7 @@ public class RangeQueryParser implements QueryParser {
// move to the next end object, to close the field name // move to the next end object, to close the field name
token = parser.nextToken(); token = parser.nextToken();
if (token != XContentParser.Token.END_OBJECT) { if (token != XContentParser.Token.END_OBJECT) {
throw new QueryParsingException(parseContext.index(), "[range] query malformed, does not end with an object"); throw new QueryParsingException(parseContext, "[range] query malformed, does not end with an object");
} }
Query query = null; Query query = null;
@ -124,12 +124,15 @@ public class RangeQueryParser implements QueryParser {
FieldMapper mapper = smartNameFieldMappers.mapper(); FieldMapper mapper = smartNameFieldMappers.mapper();
if (mapper instanceof DateFieldMapper) { if (mapper instanceof DateFieldMapper) {
if ((from instanceof Number || to instanceof Number) && timeZone != null) { if ((from instanceof Number || to instanceof Number) && timeZone != null) {
throw new QueryParsingException(parseContext.index(), "[range] time_zone when using ms since epoch format as it's UTC based can not be applied to [" + fieldName + "]"); throw new QueryParsingException(parseContext,
"[range] time_zone when using ms since epoch format as it's UTC based can not be applied to [" + fieldName
+ "]");
} }
query = ((DateFieldMapper) mapper).rangeQuery(from, to, includeLower, includeUpper, timeZone, forcedDateParser, parseContext); query = ((DateFieldMapper) mapper).rangeQuery(from, to, includeLower, includeUpper, timeZone, forcedDateParser, parseContext);
} else { } else {
if (timeZone != null) { if (timeZone != null) {
throw new QueryParsingException(parseContext.index(), "[range] time_zone can not be applied to non date field [" + fieldName + "]"); throw new QueryParsingException(parseContext, "[range] time_zone can not be applied to non date field ["
+ fieldName + "]");
} }
//LUCENE 4 UPGRADE Mapper#rangeQuery should use bytesref as well? //LUCENE 4 UPGRADE Mapper#rangeQuery should use bytesref as well?
query = mapper.rangeQuery(from, to, includeLower, includeUpper, parseContext); query = mapper.rangeQuery(from, to, includeLower, includeUpper, parseContext);

View File

@ -84,7 +84,7 @@ public class RegexpFilterParser implements FilterParser {
} else if ("flags_value".equals(currentFieldName)) { } else if ("flags_value".equals(currentFieldName)) {
flagsValue = parser.intValue(); flagsValue = parser.intValue();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[regexp] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[regexp] filter does not support [" + currentFieldName + "]");
} }
} }
} }
@ -108,7 +108,7 @@ public class RegexpFilterParser implements FilterParser {
} }
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No value specified for regexp filter"); throw new QueryParsingException(parseContext, "No value specified for regexp filter");
} }
Filter filter = null; Filter filter = null;

View File

@ -55,7 +55,7 @@ public class RegexpQueryParser implements QueryParser {
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
if (token != XContentParser.Token.FIELD_NAME) { if (token != XContentParser.Token.FIELD_NAME) {
throw new QueryParsingException(parseContext.index(), "[regexp] query malformed, no field"); throw new QueryParsingException(parseContext, "[regexp] query malformed, no field");
} }
String fieldName = parser.currentName(); String fieldName = parser.currentName();
String rewriteMethod = null; String rewriteMethod = null;
@ -92,7 +92,7 @@ public class RegexpQueryParser implements QueryParser {
queryName = parser.text(); queryName = parser.text();
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[regexp] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[regexp] query does not support [" + currentFieldName + "]");
} }
} }
parser.nextToken(); parser.nextToken();
@ -102,7 +102,7 @@ public class RegexpQueryParser implements QueryParser {
} }
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No value specified for regexp query"); throw new QueryParsingException(parseContext, "No value specified for regexp query");
} }
MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(rewriteMethod, null); MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(rewriteMethod, null);

View File

@ -85,7 +85,7 @@ public class ScriptFilterParser implements FilterParser {
if ("params".equals(currentFieldName)) { if ("params".equals(currentFieldName)) {
params = parser.map(); params = parser.map();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[script] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[script] filter does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("_name".equals(currentFieldName)) { if ("_name".equals(currentFieldName)) {
@ -95,7 +95,7 @@ public class ScriptFilterParser implements FilterParser {
} else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) { } else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) {
cacheKey = new HashedBytesRef(parser.text()); cacheKey = new HashedBytesRef(parser.text());
} else if (!scriptParameterParser.token(currentFieldName, token, parser)){ } else if (!scriptParameterParser.token(currentFieldName, token, parser)){
throw new QueryParsingException(parseContext.index(), "[script] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[script] filter does not support [" + currentFieldName + "]");
} }
} }
} }
@ -108,7 +108,7 @@ public class ScriptFilterParser implements FilterParser {
scriptLang = scriptParameterParser.lang(); scriptLang = scriptParameterParser.lang();
if (script == null) { if (script == null) {
throw new QueryParsingException(parseContext.index(), "script must be provided with a [script] filter"); throw new QueryParsingException(parseContext, "script must be provided with a [script] filter");
} }
if (params == null) { if (params == null) {
params = newHashMap(); params = newHashMap();

View File

@ -139,8 +139,9 @@ public class SimpleQueryStringParser implements QueryParser {
} }
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), throw new QueryParsingException(parseContext,
"[" + NAME + "] query does not support [" + currentFieldName + "]"); "[" + NAME + "] query does not support [" + currentFieldName
+ "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("query".equals(currentFieldName)) { if ("query".equals(currentFieldName)) {
@ -148,7 +149,7 @@ public class SimpleQueryStringParser implements QueryParser {
} else if ("analyzer".equals(currentFieldName)) { } else if ("analyzer".equals(currentFieldName)) {
analyzer = parseContext.analysisService().analyzer(parser.text()); analyzer = parseContext.analysisService().analyzer(parser.text());
if (analyzer == null) { if (analyzer == null) {
throw new QueryParsingException(parseContext.index(), "[" + NAME + "] analyzer [" + parser.text() + "] not found"); throw new QueryParsingException(parseContext, "[" + NAME + "] analyzer [" + parser.text() + "] not found");
} }
} else if ("field".equals(currentFieldName)) { } else if ("field".equals(currentFieldName)) {
field = parser.text(); field = parser.text();
@ -159,8 +160,7 @@ public class SimpleQueryStringParser implements QueryParser {
} else if ("and".equalsIgnoreCase(op)) { } else if ("and".equalsIgnoreCase(op)) {
defaultOperator = BooleanClause.Occur.MUST; defaultOperator = BooleanClause.Occur.MUST;
} else { } else {
throw new QueryParsingException(parseContext.index(), throw new QueryParsingException(parseContext, "[" + NAME + "] default operator [" + op + "] is not allowed");
"[" + NAME + "] default operator [" + op + "] is not allowed");
} }
} else if ("flags".equals(currentFieldName)) { } else if ("flags".equals(currentFieldName)) {
if (parser.currentToken() != XContentParser.Token.VALUE_NUMBER) { if (parser.currentToken() != XContentParser.Token.VALUE_NUMBER) {
@ -188,14 +188,14 @@ public class SimpleQueryStringParser implements QueryParser {
} else if ("minimum_should_match".equals(currentFieldName)) { } else if ("minimum_should_match".equals(currentFieldName)) {
minimumShouldMatch = parser.textOrNull(); minimumShouldMatch = parser.textOrNull();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[" + NAME + "] unsupported field [" + parser.currentName() + "]"); throw new QueryParsingException(parseContext, "[" + NAME + "] unsupported field [" + parser.currentName() + "]");
} }
} }
} }
// Query text is required // Query text is required
if (queryBody == null) { if (queryBody == null) {
throw new QueryParsingException(parseContext.index(), "[" + NAME + "] query text missing"); throw new QueryParsingException(parseContext, "[" + NAME + "] query text missing");
} }
// Support specifying only a field instead of a map // Support specifying only a field instead of a map

View File

@ -63,11 +63,11 @@ public class SpanFirstQueryParser implements QueryParser {
if ("match".equals(currentFieldName)) { if ("match".equals(currentFieldName)) {
Query query = parseContext.parseInnerQuery(); Query query = parseContext.parseInnerQuery();
if (!(query instanceof SpanQuery)) { if (!(query instanceof SpanQuery)) {
throw new QueryParsingException(parseContext.index(), "spanFirst [match] must be of type span query"); throw new QueryParsingException(parseContext, "spanFirst [match] must be of type span query");
} }
match = (SpanQuery) query; match = (SpanQuery) query;
} else { } else {
throw new QueryParsingException(parseContext.index(), "[span_first] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[span_first] query does not support [" + currentFieldName + "]");
} }
} else { } else {
if ("boost".equals(currentFieldName)) { if ("boost".equals(currentFieldName)) {
@ -77,15 +77,15 @@ public class SpanFirstQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[span_first] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[span_first] query does not support [" + currentFieldName + "]");
} }
} }
} }
if (match == null) { if (match == null) {
throw new QueryParsingException(parseContext.index(), "spanFirst must have [match] span query clause"); throw new QueryParsingException(parseContext, "spanFirst must have [match] span query clause");
} }
if (end == -1) { if (end == -1) {
throw new QueryParsingException(parseContext.index(), "spanFirst must have [end] set for it"); throw new QueryParsingException(parseContext, "spanFirst must have [end] set for it");
} }
SpanFirstQuery query = new SpanFirstQuery(match, end); SpanFirstQuery query = new SpanFirstQuery(match, end);

View File

@ -51,17 +51,17 @@ public class SpanMultiTermQueryParser implements QueryParser {
Token token = parser.nextToken(); Token token = parser.nextToken();
if (!MATCH_NAME.equals(parser.currentName()) || token != XContentParser.Token.FIELD_NAME) { if (!MATCH_NAME.equals(parser.currentName()) || token != XContentParser.Token.FIELD_NAME) {
throw new QueryParsingException(parseContext.index(), "spanMultiTerm must have [" + MATCH_NAME + "] multi term query clause"); throw new QueryParsingException(parseContext, "spanMultiTerm must have [" + MATCH_NAME + "] multi term query clause");
} }
token = parser.nextToken(); token = parser.nextToken();
if (token != XContentParser.Token.START_OBJECT) { if (token != XContentParser.Token.START_OBJECT) {
throw new QueryParsingException(parseContext.index(), "spanMultiTerm must have [" + MATCH_NAME + "] multi term query clause"); throw new QueryParsingException(parseContext, "spanMultiTerm must have [" + MATCH_NAME + "] multi term query clause");
} }
Query subQuery = parseContext.parseInnerQuery(); Query subQuery = parseContext.parseInnerQuery();
if (!(subQuery instanceof MultiTermQuery)) { if (!(subQuery instanceof MultiTermQuery)) {
throw new QueryParsingException(parseContext.index(), "spanMultiTerm [" + MATCH_NAME + "] must be of type multi term query"); throw new QueryParsingException(parseContext, "spanMultiTerm [" + MATCH_NAME + "] must be of type multi term query");
} }
parser.nextToken(); parser.nextToken();

View File

@ -69,12 +69,12 @@ public class SpanNearQueryParser implements QueryParser {
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
Query query = parseContext.parseInnerQuery(); Query query = parseContext.parseInnerQuery();
if (!(query instanceof SpanQuery)) { if (!(query instanceof SpanQuery)) {
throw new QueryParsingException(parseContext.index(), "spanNear [clauses] must be of type span query"); throw new QueryParsingException(parseContext, "spanNear [clauses] must be of type span query");
} }
clauses.add((SpanQuery) query); clauses.add((SpanQuery) query);
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[span_near] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[span_near] query does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("in_order".equals(currentFieldName) || "inOrder".equals(currentFieldName)) { if ("in_order".equals(currentFieldName) || "inOrder".equals(currentFieldName)) {
@ -88,17 +88,17 @@ public class SpanNearQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[span_near] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[span_near] query does not support [" + currentFieldName + "]");
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[span_near] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[span_near] query does not support [" + currentFieldName + "]");
} }
} }
if (clauses.isEmpty()) { if (clauses.isEmpty()) {
throw new QueryParsingException(parseContext.index(), "span_near must include [clauses]"); throw new QueryParsingException(parseContext, "span_near must include [clauses]");
} }
if (slop == null) { if (slop == null) {
throw new QueryParsingException(parseContext.index(), "span_near must include [slop]"); throw new QueryParsingException(parseContext, "span_near must include [slop]");
} }
SpanNearQuery query = new SpanNearQuery(clauses.toArray(new SpanQuery[clauses.size()]), slop.intValue(), inOrder, collectPayloads); SpanNearQuery query = new SpanNearQuery(clauses.toArray(new SpanQuery[clauses.size()]), slop.intValue(), inOrder, collectPayloads);

View File

@ -68,17 +68,17 @@ public class SpanNotQueryParser implements QueryParser {
if ("include".equals(currentFieldName)) { if ("include".equals(currentFieldName)) {
Query query = parseContext.parseInnerQuery(); Query query = parseContext.parseInnerQuery();
if (!(query instanceof SpanQuery)) { if (!(query instanceof SpanQuery)) {
throw new QueryParsingException(parseContext.index(), "spanNot [include] must be of type span query"); throw new QueryParsingException(parseContext, "spanNot [include] must be of type span query");
} }
include = (SpanQuery) query; include = (SpanQuery) query;
} else if ("exclude".equals(currentFieldName)) { } else if ("exclude".equals(currentFieldName)) {
Query query = parseContext.parseInnerQuery(); Query query = parseContext.parseInnerQuery();
if (!(query instanceof SpanQuery)) { if (!(query instanceof SpanQuery)) {
throw new QueryParsingException(parseContext.index(), "spanNot [exclude] must be of type span query"); throw new QueryParsingException(parseContext, "spanNot [exclude] must be of type span query");
} }
exclude = (SpanQuery) query; exclude = (SpanQuery) query;
} else { } else {
throw new QueryParsingException(parseContext.index(), "[span_not] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[span_not] query does not support [" + currentFieldName + "]");
} }
} else { } else {
if ("dist".equals(currentFieldName)) { if ("dist".equals(currentFieldName)) {
@ -92,18 +92,18 @@ public class SpanNotQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[span_not] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[span_not] query does not support [" + currentFieldName + "]");
} }
} }
} }
if (include == null) { if (include == null) {
throw new QueryParsingException(parseContext.index(), "spanNot must have [include] span query clause"); throw new QueryParsingException(parseContext, "spanNot must have [include] span query clause");
} }
if (exclude == null) { if (exclude == null) {
throw new QueryParsingException(parseContext.index(), "spanNot must have [exclude] span query clause"); throw new QueryParsingException(parseContext, "spanNot must have [exclude] span query clause");
} }
if (dist != null && (pre != null || post != null)) { if (dist != null && (pre != null || post != null)) {
throw new QueryParsingException(parseContext.index(), "spanNot can either use [dist] or [pre] & [post] (or none)"); throw new QueryParsingException(parseContext, "spanNot can either use [dist] or [pre] & [post] (or none)");
} }
// set appropriate defaults // set appropriate defaults

View File

@ -66,12 +66,12 @@ public class SpanOrQueryParser implements QueryParser {
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
Query query = parseContext.parseInnerQuery(); Query query = parseContext.parseInnerQuery();
if (!(query instanceof SpanQuery)) { if (!(query instanceof SpanQuery)) {
throw new QueryParsingException(parseContext.index(), "spanOr [clauses] must be of type span query"); throw new QueryParsingException(parseContext, "spanOr [clauses] must be of type span query");
} }
clauses.add((SpanQuery) query); clauses.add((SpanQuery) query);
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[span_or] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[span_or] query does not support [" + currentFieldName + "]");
} }
} else { } else {
if ("boost".equals(currentFieldName)) { if ("boost".equals(currentFieldName)) {
@ -79,12 +79,12 @@ public class SpanOrQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[span_or] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[span_or] query does not support [" + currentFieldName + "]");
} }
} }
} }
if (clauses.isEmpty()) { if (clauses.isEmpty()) {
throw new QueryParsingException(parseContext.index(), "spanOr must include [clauses]"); throw new QueryParsingException(parseContext, "spanOr must include [clauses]");
} }
SpanOrQuery query = new SpanOrQuery(clauses.toArray(new SpanQuery[clauses.size()])); SpanOrQuery query = new SpanOrQuery(clauses.toArray(new SpanQuery[clauses.size()]));

View File

@ -77,7 +77,7 @@ public class SpanTermQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[span_term] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[span_term] query does not support [" + currentFieldName + "]");
} }
} }
} }
@ -89,7 +89,7 @@ public class SpanTermQueryParser implements QueryParser {
} }
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No value specified for term query"); throw new QueryParsingException(parseContext, "No value specified for term query");
} }
BytesRef valueBytes = null; BytesRef valueBytes = null;

View File

@ -81,7 +81,7 @@ public class TermFilterParser implements FilterParser {
} else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) { } else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) {
cacheKey = new HashedBytesRef(parser.text()); cacheKey = new HashedBytesRef(parser.text());
} else { } else {
throw new QueryParsingException(parseContext.index(), "[term] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[term] filter does not support [" + currentFieldName + "]");
} }
} }
} }
@ -100,11 +100,11 @@ public class TermFilterParser implements FilterParser {
} }
if (fieldName == null) { if (fieldName == null) {
throw new QueryParsingException(parseContext.index(), "No field specified for term filter"); throw new QueryParsingException(parseContext, "No field specified for term filter");
} }
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No value specified for term filter"); throw new QueryParsingException(parseContext, "No value specified for term filter");
} }
Filter filter = null; Filter filter = null;

View File

@ -51,7 +51,7 @@ public class TermQueryParser implements QueryParser {
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
if (token != XContentParser.Token.FIELD_NAME) { if (token != XContentParser.Token.FIELD_NAME) {
throw new QueryParsingException(parseContext.index(), "[term] query malformed, no field"); throw new QueryParsingException(parseContext, "[term] query malformed, no field");
} }
String fieldName = parser.currentName(); String fieldName = parser.currentName();
@ -74,7 +74,7 @@ public class TermQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[term] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[term] query does not support [" + currentFieldName + "]");
} }
} }
} }
@ -86,7 +86,7 @@ public class TermQueryParser implements QueryParser {
} }
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No value specified for term query"); throw new QueryParsingException(parseContext, "No value specified for term query");
} }
Query query = null; Query query = null;

View File

@ -90,14 +90,14 @@ public class TermsFilterParser implements FilterParser {
currentFieldName = parser.currentName(); currentFieldName = parser.currentName();
} else if (token == XContentParser.Token.START_ARRAY) { } else if (token == XContentParser.Token.START_ARRAY) {
if (fieldName != null) { if (fieldName != null) {
throw new QueryParsingException(parseContext.index(), "[terms] filter does not support multiple fields"); throw new QueryParsingException(parseContext, "[terms] filter does not support multiple fields");
} }
fieldName = currentFieldName; fieldName = currentFieldName;
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
Object value = parser.objectBytes(); Object value = parser.objectBytes();
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No value specified for terms filter"); throw new QueryParsingException(parseContext, "No value specified for terms filter");
} }
terms.add(value); terms.add(value);
} }
@ -118,18 +118,19 @@ public class TermsFilterParser implements FilterParser {
} else if ("routing".equals(currentFieldName)) { } else if ("routing".equals(currentFieldName)) {
lookupRouting = parser.textOrNull(); lookupRouting = parser.textOrNull();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[terms] filter does not support [" + currentFieldName + "] within lookup element"); throw new QueryParsingException(parseContext, "[terms] filter does not support [" + currentFieldName
+ "] within lookup element");
} }
} }
} }
if (lookupType == null) { if (lookupType == null) {
throw new QueryParsingException(parseContext.index(), "[terms] filter lookup element requires specifying the type"); throw new QueryParsingException(parseContext, "[terms] filter lookup element requires specifying the type");
} }
if (lookupId == null) { if (lookupId == null) {
throw new QueryParsingException(parseContext.index(), "[terms] filter lookup element requires specifying the id"); throw new QueryParsingException(parseContext, "[terms] filter lookup element requires specifying the id");
} }
if (lookupPath == null) { if (lookupPath == null) {
throw new QueryParsingException(parseContext.index(), "[terms] filter lookup element requires specifying the path"); throw new QueryParsingException(parseContext, "[terms] filter lookup element requires specifying the path");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if (EXECUTION_KEY.equals(currentFieldName)) { if (EXECUTION_KEY.equals(currentFieldName)) {
@ -141,13 +142,13 @@ public class TermsFilterParser implements FilterParser {
} else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) { } else if ("_cache_key".equals(currentFieldName) || "_cacheKey".equals(currentFieldName)) {
cacheKey = new HashedBytesRef(parser.text()); cacheKey = new HashedBytesRef(parser.text());
} else { } else {
throw new QueryParsingException(parseContext.index(), "[terms] filter does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[terms] filter does not support [" + currentFieldName + "]");
} }
} }
} }
if (fieldName == null) { if (fieldName == null) {
throw new QueryParsingException(parseContext.index(), "terms filter requires a field name, followed by array of terms"); throw new QueryParsingException(parseContext, "terms filter requires a field name, followed by array of terms");
} }
FieldMapper<?> fieldMapper = null; FieldMapper<?> fieldMapper = null;

View File

@ -75,13 +75,13 @@ public class TermsQueryParser implements QueryParser {
currentFieldName = parser.currentName(); currentFieldName = parser.currentName();
} else if (token == XContentParser.Token.START_ARRAY) { } else if (token == XContentParser.Token.START_ARRAY) {
if (fieldName != null) { if (fieldName != null) {
throw new QueryParsingException(parseContext.index(), "[terms] query does not support multiple fields"); throw new QueryParsingException(parseContext, "[terms] query does not support multiple fields");
} }
fieldName = currentFieldName; fieldName = currentFieldName;
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
Object value = parser.objectBytes(); Object value = parser.objectBytes();
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No value specified for terms query"); throw new QueryParsingException(parseContext, "No value specified for terms query");
} }
values.add(value); values.add(value);
} }
@ -97,15 +97,15 @@ public class TermsQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[terms] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[terms] query does not support [" + currentFieldName + "]");
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), "[terms] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[terms] query does not support [" + currentFieldName + "]");
} }
} }
if (fieldName == null) { if (fieldName == null) {
throw new QueryParsingException(parseContext.index(), "No field specified for terms query"); throw new QueryParsingException(parseContext, "No field specified for terms query");
} }
FieldMapper mapper = null; FieldMapper mapper = null;

View File

@ -78,7 +78,7 @@ public class TopChildrenQueryParser implements QueryParser {
iq = new XContentStructure.InnerQuery(parseContext, childType == null ? null : new String[] {childType}); iq = new XContentStructure.InnerQuery(parseContext, childType == null ? null : new String[] {childType});
queryFound = true; queryFound = true;
} else { } else {
throw new QueryParsingException(parseContext.index(), "[top_children] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[top_children] query does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if ("type".equals(currentFieldName)) { if ("type".equals(currentFieldName)) {
@ -96,15 +96,15 @@ public class TopChildrenQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[top_children] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[top_children] query does not support [" + currentFieldName + "]");
} }
} }
} }
if (!queryFound) { if (!queryFound) {
throw new QueryParsingException(parseContext.index(), "[top_children] requires 'query' field"); throw new QueryParsingException(parseContext, "[top_children] requires 'query' field");
} }
if (childType == null) { if (childType == null) {
throw new QueryParsingException(parseContext.index(), "[top_children] requires 'type' field"); throw new QueryParsingException(parseContext, "[top_children] requires 'type' field");
} }
Query innerQuery = iq.asQuery(childType); Query innerQuery = iq.asQuery(childType);
@ -115,11 +115,11 @@ public class TopChildrenQueryParser implements QueryParser {
DocumentMapper childDocMapper = parseContext.mapperService().documentMapper(childType); DocumentMapper childDocMapper = parseContext.mapperService().documentMapper(childType);
if (childDocMapper == null) { if (childDocMapper == null) {
throw new QueryParsingException(parseContext.index(), "No mapping for for type [" + childType + "]"); throw new QueryParsingException(parseContext, "No mapping for for type [" + childType + "]");
} }
ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper(); ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper();
if (!parentFieldMapper.active()) { if (!parentFieldMapper.active()) {
throw new QueryParsingException(parseContext.index(), "Type [" + childType + "] does not have parent mapping"); throw new QueryParsingException(parseContext, "Type [" + childType + "] does not have parent mapping");
} }
String parentType = childDocMapper.parentFieldMapper().type(); String parentType = childDocMapper.parentFieldMapper().type();

View File

@ -50,15 +50,15 @@ public class TypeFilterParser implements FilterParser {
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
if (token != XContentParser.Token.FIELD_NAME) { if (token != XContentParser.Token.FIELD_NAME) {
throw new QueryParsingException(parseContext.index(), "[type] filter should have a value field, and the type name"); throw new QueryParsingException(parseContext, "[type] filter should have a value field, and the type name");
} }
String fieldName = parser.currentName(); String fieldName = parser.currentName();
if (!fieldName.equals("value")) { if (!fieldName.equals("value")) {
throw new QueryParsingException(parseContext.index(), "[type] filter should have a value field, and the type name"); throw new QueryParsingException(parseContext, "[type] filter should have a value field, and the type name");
} }
token = parser.nextToken(); token = parser.nextToken();
if (token != XContentParser.Token.VALUE_STRING) { if (token != XContentParser.Token.VALUE_STRING) {
throw new QueryParsingException(parseContext.index(), "[type] filter should have a value field, and the type name"); throw new QueryParsingException(parseContext, "[type] filter should have a value field, and the type name");
} }
BytesRef type = parser.utf8Bytes(); BytesRef type = parser.utf8Bytes();
// move to the next token // move to the next token

View File

@ -52,7 +52,7 @@ public class WildcardQueryParser implements QueryParser {
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
if (token != XContentParser.Token.FIELD_NAME) { if (token != XContentParser.Token.FIELD_NAME) {
throw new QueryParsingException(parseContext.index(), "[wildcard] query malformed, no field"); throw new QueryParsingException(parseContext, "[wildcard] query malformed, no field");
} }
String fieldName = parser.currentName(); String fieldName = parser.currentName();
String rewriteMethod = null; String rewriteMethod = null;
@ -78,7 +78,7 @@ public class WildcardQueryParser implements QueryParser {
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
queryName = parser.text(); queryName = parser.text();
} else { } else {
throw new QueryParsingException(parseContext.index(), "[wildcard] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, "[wildcard] query does not support [" + currentFieldName + "]");
} }
} }
} }
@ -89,7 +89,7 @@ public class WildcardQueryParser implements QueryParser {
} }
if (value == null) { if (value == null) {
throw new QueryParsingException(parseContext.index(), "No value specified for prefix query"); throw new QueryParsingException(parseContext, "No value specified for prefix query");
} }
BytesRef valueBytes; BytesRef valueBytes;

View File

@ -48,11 +48,11 @@ public class WrapperFilterParser implements FilterParser {
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
if (token != XContentParser.Token.FIELD_NAME) { if (token != XContentParser.Token.FIELD_NAME) {
throw new QueryParsingException(parseContext.index(), "[wrapper] filter malformed"); throw new QueryParsingException(parseContext, "[wrapper] filter malformed");
} }
String fieldName = parser.currentName(); String fieldName = parser.currentName();
if (!fieldName.equals("filter")) { if (!fieldName.equals("filter")) {
throw new QueryParsingException(parseContext.index(), "[wrapper] filter malformed"); throw new QueryParsingException(parseContext, "[wrapper] filter malformed");
} }
parser.nextToken(); parser.nextToken();

View File

@ -48,11 +48,11 @@ public class WrapperQueryParser implements QueryParser {
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
if (token != XContentParser.Token.FIELD_NAME) { if (token != XContentParser.Token.FIELD_NAME) {
throw new QueryParsingException(parseContext.index(), "[wrapper] query malformed"); throw new QueryParsingException(parseContext, "[wrapper] query malformed");
} }
String fieldName = parser.currentName(); String fieldName = parser.currentName();
if (!fieldName.equals("query")) { if (!fieldName.equals("query")) {
throw new QueryParsingException(parseContext.index(), "[wrapper] query malformed"); throw new QueryParsingException(parseContext, "[wrapper] query malformed");
} }
parser.nextToken(); parser.nextToken();

View File

@ -154,7 +154,7 @@ public abstract class DecayFunctionParser implements ScoreFunctionParser {
// the doc later // the doc later
MapperService.SmartNameFieldMappers smartMappers = parseContext.smartFieldMappers(fieldName); MapperService.SmartNameFieldMappers smartMappers = parseContext.smartFieldMappers(fieldName);
if (smartMappers == null || !smartMappers.hasMapper()) { if (smartMappers == null || !smartMappers.hasMapper()) {
throw new QueryParsingException(parseContext.index(), "Unknown field [" + fieldName + "]"); throw new QueryParsingException(parseContext, "Unknown field [" + fieldName + "]");
} }
FieldMapper<?> mapper = smartMappers.fieldMappers().mapper(); FieldMapper<?> mapper = smartMappers.fieldMappers().mapper();
@ -167,7 +167,7 @@ public abstract class DecayFunctionParser implements ScoreFunctionParser {
} else if (mapper instanceof NumberFieldMapper<?>) { } else if (mapper instanceof NumberFieldMapper<?>) {
return parseNumberVariable(fieldName, parser, parseContext, (NumberFieldMapper<?>) mapper, mode); return parseNumberVariable(fieldName, parser, parseContext, (NumberFieldMapper<?>) mapper, mode);
} else { } else {
throw new QueryParsingException(parseContext.index(), "Field " + fieldName + " is of type " + mapper.fieldType() throw new QueryParsingException(parseContext, "Field " + fieldName + " is of type " + mapper.fieldType()
+ ", but only numeric types are supported."); + ", but only numeric types are supported.");
} }
} }

View File

@ -134,7 +134,7 @@ public class FunctionScoreQueryParser implements QueryParser {
// we try to parse a score function. If there is no score // we try to parse a score function. If there is no score
// function for the current field name, // function for the current field name,
// functionParserMapper.get() will throw an Exception. // functionParserMapper.get() will throw an Exception.
scoreFunction = functionParserMapper.get(parseContext.index(), currentFieldName).parse(parseContext, parser); scoreFunction = functionParserMapper.get(parseContext, currentFieldName).parse(parseContext, parser);
} }
if (functionArrayFound) { if (functionArrayFound) {
String errorString = "Found \"functions\": [...] already, now encountering \"" + currentFieldName + "\"."; String errorString = "Found \"functions\": [...] already, now encountering \"" + currentFieldName + "\".";
@ -202,8 +202,8 @@ public class FunctionScoreQueryParser implements QueryParser {
ScoreFunction scoreFunction = null; ScoreFunction scoreFunction = null;
Float functionWeight = null; Float functionWeight = null;
if (token != XContentParser.Token.START_OBJECT) { if (token != XContentParser.Token.START_OBJECT) {
throw new QueryParsingException(parseContext.index(), NAME + ": malformed query, expected a " throw new QueryParsingException(parseContext, NAME + ": malformed query, expected a " + XContentParser.Token.START_OBJECT
+ XContentParser.Token.START_OBJECT + " while parsing functions but got a " + token); + " while parsing functions but got a " + token);
} else { } else {
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) { if (token == XContentParser.Token.FIELD_NAME) {
@ -217,7 +217,7 @@ public class FunctionScoreQueryParser implements QueryParser {
// do not need to check null here, // do not need to check null here,
// functionParserMapper throws exception if parser // functionParserMapper throws exception if parser
// non-existent // non-existent
ScoreFunctionParser functionParser = functionParserMapper.get(parseContext.index(), currentFieldName); ScoreFunctionParser functionParser = functionParserMapper.get(parseContext, currentFieldName);
scoreFunction = functionParser.parse(parseContext, parser); scoreFunction = functionParser.parse(parseContext, parser);
} }
} }
@ -253,7 +253,7 @@ public class FunctionScoreQueryParser implements QueryParser {
} else if ("first".equals(scoreMode)) { } else if ("first".equals(scoreMode)) {
return FiltersFunctionScoreQuery.ScoreMode.First; return FiltersFunctionScoreQuery.ScoreMode.First;
} else { } else {
throw new QueryParsingException(parseContext.index(), NAME + " illegal score_mode [" + scoreMode + "]"); throw new QueryParsingException(parseContext, NAME + " illegal score_mode [" + scoreMode + "]");
} }
} }
@ -261,7 +261,7 @@ public class FunctionScoreQueryParser implements QueryParser {
String boostMode = parser.text(); String boostMode = parser.text();
CombineFunction cf = combineFunctionsMap.get(boostMode); CombineFunction cf = combineFunctionsMap.get(boostMode);
if (cf == null) { if (cf == null) {
throw new QueryParsingException(parseContext.index(), NAME + " illegal boost_mode [" + boostMode + "]"); throw new QueryParsingException(parseContext, NAME + " illegal boost_mode [" + boostMode + "]");
} }
return cf; return cf;
} }

View File

@ -20,9 +20,10 @@
package org.elasticsearch.index.query.functionscore; package org.elasticsearch.index.query.functionscore;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.index.Index; import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.query.QueryParsingException; import org.elasticsearch.index.query.QueryParsingException;
import java.util.Set; import java.util.Set;
@ -42,10 +43,10 @@ public class ScoreFunctionParserMapper {
this.functionParsers = builder.immutableMap(); this.functionParsers = builder.immutableMap();
} }
public ScoreFunctionParser get(Index index, String parserName) { public ScoreFunctionParser get(QueryParseContext parseContext, String parserName) {
ScoreFunctionParser functionParser = get(parserName); ScoreFunctionParser functionParser = get(parserName);
if (functionParser == null) { if (functionParser == null) {
throw new QueryParsingException(index, "No function with the name [" + parserName + "] is registered."); throw new QueryParsingException(parseContext, "No function with the name [" + parserName + "] is registered.", null);
} }
return functionParser; return functionParser;
} }

View File

@ -72,15 +72,15 @@ public class FieldValueFactorFunctionParser implements ScoreFunctionParser {
} else if ("missing".equals(currentFieldName)) { } else if ("missing".equals(currentFieldName)) {
missing = parser.doubleValue(); missing = parser.doubleValue();
} else { } else {
throw new QueryParsingException(parseContext.index(), NAMES[0] + " query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, NAMES[0] + " query does not support [" + currentFieldName + "]");
} }
} else if("factor".equals(currentFieldName) && (token == XContentParser.Token.START_ARRAY || token == XContentParser.Token.START_OBJECT)) { } else if("factor".equals(currentFieldName) && (token == XContentParser.Token.START_ARRAY || token == XContentParser.Token.START_OBJECT)) {
throw new QueryParsingException(parseContext.index(), "[" + NAMES[0] + "] field 'factor' does not support lists or objects"); throw new QueryParsingException(parseContext, "[" + NAMES[0] + "] field 'factor' does not support lists or objects");
} }
} }
if (field == null) { if (field == null) {
throw new QueryParsingException(parseContext.index(), "[" + NAMES[0] + "] required field 'field' missing"); throw new QueryParsingException(parseContext, "[" + NAMES[0] + "] required field 'field' missing");
} }
SearchContext searchContext = SearchContext.current(); SearchContext searchContext = SearchContext.current();

View File

@ -21,6 +21,7 @@
package org.elasticsearch.index.query.functionscore.random; package org.elasticsearch.index.query.functionscore.random;
import com.google.common.primitives.Longs; import com.google.common.primitives.Longs;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.search.function.RandomScoreFunction; import org.elasticsearch.common.lucene.search.function.RandomScoreFunction;
import org.elasticsearch.common.lucene.search.function.ScoreFunction; import org.elasticsearch.common.lucene.search.function.ScoreFunction;
@ -66,15 +67,17 @@ public class RandomScoreFunctionParser implements ScoreFunctionParser {
} else if (parser.numberType() == XContentParser.NumberType.LONG) { } else if (parser.numberType() == XContentParser.NumberType.LONG) {
seed = Longs.hashCode(parser.longValue()); seed = Longs.hashCode(parser.longValue());
} else { } else {
throw new QueryParsingException(parseContext.index(), "random_score seed must be an int, long or string, not '" + token.toString() + "'"); throw new QueryParsingException(parseContext, "random_score seed must be an int, long or string, not '"
+ token.toString() + "'");
} }
} else if (token == XContentParser.Token.VALUE_STRING) { } else if (token == XContentParser.Token.VALUE_STRING) {
seed = parser.text().hashCode(); seed = parser.text().hashCode();
} else { } else {
throw new QueryParsingException(parseContext.index(), "random_score seed must be an int/long or string, not '" + token.toString() + "'"); throw new QueryParsingException(parseContext, "random_score seed must be an int/long or string, not '"
+ token.toString() + "'");
} }
} else { } else {
throw new QueryParsingException(parseContext.index(), NAMES[0] + " query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, NAMES[0] + " query does not support [" + currentFieldName + "]");
} }
} }
} }

View File

@ -28,7 +28,9 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.query.QueryParsingException; import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.query.functionscore.ScoreFunctionParser; import org.elasticsearch.index.query.functionscore.ScoreFunctionParser;
import org.elasticsearch.script.*; import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptParameterParser;
import org.elasticsearch.script.ScriptParameterParser.ScriptParameterValue; import org.elasticsearch.script.ScriptParameterParser.ScriptParameterValue;
import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.SearchScript; import org.elasticsearch.script.SearchScript;
@ -67,11 +69,11 @@ public class ScriptScoreFunctionParser implements ScoreFunctionParser {
if ("params".equals(currentFieldName)) { if ("params".equals(currentFieldName)) {
vars = parser.map(); vars = parser.map();
} else { } else {
throw new QueryParsingException(parseContext.index(), NAMES[0] + " query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, NAMES[0] + " query does not support [" + currentFieldName + "]");
} }
} else if (token.isValue()) { } else if (token.isValue()) {
if (!scriptParameterParser.token(currentFieldName, token, parser)) { if (!scriptParameterParser.token(currentFieldName, token, parser)) {
throw new QueryParsingException(parseContext.index(), NAMES[0] + " query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext, NAMES[0] + " query does not support [" + currentFieldName + "]");
} }
} }
} }
@ -82,7 +84,7 @@ public class ScriptScoreFunctionParser implements ScoreFunctionParser {
scriptType = scriptValue.scriptType(); scriptType = scriptValue.scriptType();
} }
if (script == null) { if (script == null) {
throw new QueryParsingException(parseContext.index(), NAMES[0] + " requires 'script' field"); throw new QueryParsingException(parseContext, NAMES[0] + " requires 'script' field");
} }
SearchScript searchScript; SearchScript searchScript;
@ -90,7 +92,7 @@ public class ScriptScoreFunctionParser implements ScoreFunctionParser {
searchScript = parseContext.scriptService().search(parseContext.lookup(), new Script(scriptParameterParser.lang(), script, scriptType, vars), ScriptContext.Standard.SEARCH); searchScript = parseContext.scriptService().search(parseContext.lookup(), new Script(scriptParameterParser.lang(), script, scriptType, vars), ScriptContext.Standard.SEARCH);
return new ScriptScoreFunction(script, vars, searchScript); return new ScriptScoreFunction(script, vars, searchScript);
} catch (Exception e) { } catch (Exception e) {
throw new QueryParsingException(parseContext.index(), NAMES[0] + " the script could not be loaded", e); throw new QueryParsingException(parseContext, NAMES[0] + " the script could not be loaded", e);
} }
} }
} }

View File

@ -72,7 +72,7 @@ public class InnerHitsQueryParserHelper {
} }
} }
} catch (Exception e) { } catch (Exception e) {
throw new QueryParsingException(parserContext.index(), "Failed to parse [_inner_hits]", e); throw new QueryParsingException(parserContext, "Failed to parse [_inner_hits]", e);
} }
return new Tuple<>(innerHitName, subSearchContext); return new Tuple<>(innerHitName, subSearchContext);
} }

View File

@ -106,10 +106,10 @@ public class NestedInnerQueryParseSupport {
return innerQuery; return innerQuery;
} else { } else {
if (path == null) { if (path == null) {
throw new QueryParsingException(parseContext.index(), "[nested] requires 'path' field"); throw new QueryParsingException(parseContext, "[nested] requires 'path' field");
} }
if (!queryFound) { if (!queryFound) {
throw new QueryParsingException(parseContext.index(), "[nested] requires either 'query' or 'filter' field"); throw new QueryParsingException(parseContext, "[nested] requires either 'query' or 'filter' field");
} }
XContentParser old = parseContext.parser(); XContentParser old = parseContext.parser();
@ -135,10 +135,10 @@ public class NestedInnerQueryParseSupport {
return innerFilter; return innerFilter;
} else { } else {
if (path == null) { if (path == null) {
throw new QueryParsingException(parseContext.index(), "[nested] requires 'path' field"); throw new QueryParsingException(parseContext, "[nested] requires 'path' field");
} }
if (!filterFound) { if (!filterFound) {
throw new QueryParsingException(parseContext.index(), "[nested] requires either 'query' or 'filter' field"); throw new QueryParsingException(parseContext, "[nested] requires either 'query' or 'filter' field");
} }
setPathLevel(); setPathLevel();
@ -160,15 +160,15 @@ public class NestedInnerQueryParseSupport {
this.path = path; this.path = path;
MapperService.SmartNameObjectMapper smart = parseContext.smartObjectMapper(path); MapperService.SmartNameObjectMapper smart = parseContext.smartObjectMapper(path);
if (smart == null) { if (smart == null) {
throw new QueryParsingException(parseContext.index(), "[nested] failed to find nested object under path [" + path + "]"); throw new QueryParsingException(parseContext, "[nested] failed to find nested object under path [" + path + "]");
} }
childDocumentMapper = smart.docMapper(); childDocumentMapper = smart.docMapper();
nestedObjectMapper = smart.mapper(); nestedObjectMapper = smart.mapper();
if (nestedObjectMapper == null) { if (nestedObjectMapper == null) {
throw new QueryParsingException(parseContext.index(), "[nested] failed to find nested object under path [" + path + "]"); throw new QueryParsingException(parseContext, "[nested] failed to find nested object under path [" + path + "]");
} }
if (!nestedObjectMapper.nested().isNested()) { if (!nestedObjectMapper.nested().isNested()) {
throw new QueryParsingException(parseContext.index(), "[nested] nested object under path [" + path + "] is not of nested type"); throw new QueryParsingException(parseContext, "[nested] nested object under path [" + path + "] is not of nested type");
} }
} }

View File

@ -19,24 +19,64 @@
package org.elasticsearch.search; package org.elasticsearch.search;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentLocation;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException;
/** /**
* *
*/ */
public class SearchParseException extends SearchContextException { public class SearchParseException extends SearchContextException {
public SearchParseException(SearchContext context, String msg) { public static final int UNKNOWN_POSITION = -1;
super(context, msg); private int lineNumber = UNKNOWN_POSITION;
private int columnNumber = UNKNOWN_POSITION;
public SearchParseException(SearchContext context, String msg, @Nullable XContentLocation location) {
this(context, msg, location, null);
} }
public SearchParseException(SearchContext context, String msg, Throwable cause) { public SearchParseException(SearchContext context, String msg, @Nullable XContentLocation location, Throwable cause) {
super(context, msg, cause); super(context, msg, cause);
if (location != null) {
lineNumber = location.lineNumber;
columnNumber = location.columnNumber;
}
} }
@Override @Override
public RestStatus status() { public RestStatus status() {
return RestStatus.BAD_REQUEST; return RestStatus.BAD_REQUEST;
} }
@Override
protected void innerToXContent(XContentBuilder builder, Params params) throws IOException {
if (lineNumber != UNKNOWN_POSITION) {
builder.field("line", lineNumber);
builder.field("col", columnNumber);
}
super.innerToXContent(builder, params);
}
/**
* Line number of the location of the error
*
* @return the line number or -1 if unknown
*/
public int getLineNumber() {
return lineNumber;
}
/**
* Column number of the location of the error
*
* @return the column number or -1 if unknown
*/
public int getColumnNumber() {
return columnNumber;
}
} }

View File

@ -24,6 +24,7 @@ import com.carrotsearch.hppc.ObjectSet;
import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.NumericDocValues;
@ -77,10 +78,23 @@ import org.elasticsearch.script.mustache.MustacheScriptEngineService;
import org.elasticsearch.search.dfs.CachedDfSource; import org.elasticsearch.search.dfs.CachedDfSource;
import org.elasticsearch.search.dfs.DfsPhase; import org.elasticsearch.search.dfs.DfsPhase;
import org.elasticsearch.search.dfs.DfsSearchResult; import org.elasticsearch.search.dfs.DfsSearchResult;
import org.elasticsearch.search.fetch.*; import org.elasticsearch.search.fetch.FetchPhase;
import org.elasticsearch.search.internal.*; import org.elasticsearch.search.fetch.FetchSearchResult;
import org.elasticsearch.search.fetch.QueryFetchSearchResult;
import org.elasticsearch.search.fetch.ScrollQueryFetchSearchResult;
import org.elasticsearch.search.fetch.ShardFetchRequest;
import org.elasticsearch.search.internal.DefaultSearchContext;
import org.elasticsearch.search.internal.InternalScrollSearchRequest;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.search.internal.SearchContext.Lifetime; import org.elasticsearch.search.internal.SearchContext.Lifetime;
import org.elasticsearch.search.query.*; import org.elasticsearch.search.internal.ShardSearchLocalRequest;
import org.elasticsearch.search.internal.ShardSearchRequest;
import org.elasticsearch.search.query.QueryPhase;
import org.elasticsearch.search.query.QueryPhaseExecutionException;
import org.elasticsearch.search.query.QuerySearchRequest;
import org.elasticsearch.search.query.QuerySearchResult;
import org.elasticsearch.search.query.QuerySearchResultProvider;
import org.elasticsearch.search.query.ScrollQuerySearchResult;
import org.elasticsearch.search.warmer.IndexWarmersMetaData; import org.elasticsearch.search.warmer.IndexWarmersMetaData;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
@ -718,7 +732,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
parser.nextToken(); parser.nextToken();
SearchParseElement element = elementParsers.get(fieldName); SearchParseElement element = elementParsers.get(fieldName);
if (element == null) { if (element == null) {
throw new SearchParseException(context, "No parser for element [" + fieldName + "]"); throw new SearchParseException(context, "No parser for element [" + fieldName + "]", parser.getTokenLocation());
} }
element.parse(parser, context); element.parse(parser, context);
} else { } else {
@ -736,7 +750,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
} catch (Throwable e1) { } catch (Throwable e1) {
// ignore // ignore
} }
throw new SearchParseException(context, "Failed to parse source [" + sSource + "]", e); throw new SearchParseException(context, "Failed to parse source [" + sSource + "]", parser.getTokenLocation(), e);
} finally { } finally {
if (parser != null) { if (parser != null) {
parser.close(); parser.close();

View File

@ -19,6 +19,7 @@
package org.elasticsearch.search.aggregations; package org.elasticsearch.search.aggregations;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -86,16 +87,19 @@ public class AggregatorParsers {
XContentParser.Token token = null; XContentParser.Token token = null;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token != XContentParser.Token.FIELD_NAME) { if (token != XContentParser.Token.FIELD_NAME) {
throw new SearchParseException(context, "Unexpected token " + token + " in [aggs]: aggregations definitions must start with the name of the aggregation."); throw new SearchParseException(context, "Unexpected token " + token
+ " in [aggs]: aggregations definitions must start with the name of the aggregation.", parser.getTokenLocation());
} }
final String aggregationName = parser.currentName(); final String aggregationName = parser.currentName();
if (!validAggMatcher.reset(aggregationName).matches()) { if (!validAggMatcher.reset(aggregationName).matches()) {
throw new SearchParseException(context, "Invalid aggregation name [" + aggregationName + "]. Aggregation names must be alpha-numeric and can only contain '_' and '-'"); throw new SearchParseException(context, "Invalid aggregation name [" + aggregationName
+ "]. Aggregation names must be alpha-numeric and can only contain '_' and '-'", parser.getTokenLocation());
} }
token = parser.nextToken(); token = parser.nextToken();
if (token != XContentParser.Token.START_OBJECT) { if (token != XContentParser.Token.START_OBJECT) {
throw new SearchParseException(context, "Aggregation definition for [" + aggregationName + " starts with a [" + token + "], expected a [" + XContentParser.Token.START_OBJECT + "]."); throw new SearchParseException(context, "Aggregation definition for [" + aggregationName + " starts with a [" + token
+ "], expected a [" + XContentParser.Token.START_OBJECT + "].", parser.getTokenLocation());
} }
AggregatorFactory factory = null; AggregatorFactory factory = null;
@ -105,13 +109,16 @@ public class AggregatorParsers {
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token != XContentParser.Token.FIELD_NAME) { if (token != XContentParser.Token.FIELD_NAME) {
throw new SearchParseException(context, "Expected [" + XContentParser.Token.FIELD_NAME + "] under a [" + XContentParser.Token.START_OBJECT + "], but got a [" + token + "] in [" + aggregationName + "]"); throw new SearchParseException(context, "Expected [" + XContentParser.Token.FIELD_NAME + "] under a ["
+ XContentParser.Token.START_OBJECT + "], but got a [" + token + "] in [" + aggregationName + "]",
parser.getTokenLocation());
} }
final String fieldName = parser.currentName(); final String fieldName = parser.currentName();
token = parser.nextToken(); token = parser.nextToken();
if (token != XContentParser.Token.START_OBJECT) { if (token != XContentParser.Token.START_OBJECT) {
throw new SearchParseException(context, "Expected [" + XContentParser.Token.START_OBJECT + "] under [" + fieldName + "], but got a [" + token + "] in [" + aggregationName + "]"); throw new SearchParseException(context, "Expected [" + XContentParser.Token.START_OBJECT + "] under [" + fieldName
+ "], but got a [" + token + "] in [" + aggregationName + "]", parser.getTokenLocation());
} }
switch (fieldName) { switch (fieldName) {
@ -121,24 +128,28 @@ public class AggregatorParsers {
case "aggregations": case "aggregations":
case "aggs": case "aggs":
if (subFactories != null) { if (subFactories != null) {
throw new SearchParseException(context, "Found two sub aggregation definitions under [" + aggregationName + "]"); throw new SearchParseException(context, "Found two sub aggregation definitions under [" + aggregationName + "]",
parser.getTokenLocation());
} }
subFactories = parseAggregators(parser, context, level+1); subFactories = parseAggregators(parser, context, level+1);
break; break;
default: default:
if (factory != null) { if (factory != null) {
throw new SearchParseException(context, "Found two aggregation type definitions in [" + aggregationName + "]: [" + factory.type + "] and [" + fieldName + "]"); throw new SearchParseException(context, "Found two aggregation type definitions in [" + aggregationName + "]: ["
+ factory.type + "] and [" + fieldName + "]", parser.getTokenLocation());
} }
Aggregator.Parser aggregatorParser = parser(fieldName); Aggregator.Parser aggregatorParser = parser(fieldName);
if (aggregatorParser == null) { if (aggregatorParser == null) {
throw new SearchParseException(context, "Could not find aggregator type [" + fieldName + "] in [" + aggregationName + "]"); throw new SearchParseException(context, "Could not find aggregator type [" + fieldName + "] in [" + aggregationName
+ "]", parser.getTokenLocation());
} }
factory = aggregatorParser.parse(aggregationName, parser, context); factory = aggregatorParser.parse(aggregationName, parser, context);
} }
} }
if (factory == null) { if (factory == null) {
throw new SearchParseException(context, "Missing definition for aggregation [" + aggregationName + "]"); throw new SearchParseException(context, "Missing definition for aggregation [" + aggregationName + "]",
parser.getTokenLocation());
} }
if (metaData != null) { if (metaData != null) {

View File

@ -56,15 +56,18 @@ public class ChildrenParser implements Aggregator.Parser {
if ("type".equals(currentFieldName)) { if ("type".equals(currentFieldName)) {
childType = parser.text(); childType = parser.text();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "]."); throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
parser.getTokenLocation());
} }
} }
if (childType == null) { if (childType == null) {
throw new SearchParseException(context, "Missing [child_type] field for children aggregation [" + aggregationName + "]"); throw new SearchParseException(context, "Missing [child_type] field for children aggregation [" + aggregationName + "]",
parser.getTokenLocation());
} }
ValuesSourceConfig<ValuesSource.Bytes.WithOrdinals.ParentChild> config = new ValuesSourceConfig<>(ValuesSource.Bytes.WithOrdinals.ParentChild.class); ValuesSourceConfig<ValuesSource.Bytes.WithOrdinals.ParentChild> config = new ValuesSourceConfig<>(ValuesSource.Bytes.WithOrdinals.ParentChild.class);
@ -76,7 +79,7 @@ public class ChildrenParser implements Aggregator.Parser {
if (childDocMapper != null) { if (childDocMapper != null) {
ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper(); ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper();
if (!parentFieldMapper.active()) { if (!parentFieldMapper.active()) {
throw new SearchParseException(context, "[children] _parent field not configured"); throw new SearchParseException(context, "[children] _parent field not configured", parser.getTokenLocation());
} }
parentType = parentFieldMapper.type(); parentType = parentFieldMapper.type();
DocumentMapper parentDocMapper = context.mapperService().documentMapper(parentType); DocumentMapper parentDocMapper = context.mapperService().documentMapper(parentType);

View File

@ -65,7 +65,8 @@ public class FiltersParser implements Aggregator.Parser {
} }
} }
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else if (token == XContentParser.Token.START_ARRAY) { } else if (token == XContentParser.Token.START_ARRAY) {
if ("filters".equals(currentFieldName)) { if ("filters".equals(currentFieldName)) {
@ -78,10 +79,12 @@ public class FiltersParser implements Aggregator.Parser {
idx++; idx++;
} }
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} }

View File

@ -108,13 +108,15 @@ public class DateHistogramParser implements Aggregator.Parser {
} else if (INTERVAL.match(currentFieldName)) { } else if (INTERVAL.match(currentFieldName)) {
interval = parser.text(); interval = parser.text();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else if (token == XContentParser.Token.VALUE_BOOLEAN) { } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
if ("keyed".equals(currentFieldName)) { if ("keyed".equals(currentFieldName)) {
keyed = parser.booleanValue(); keyed = parser.booleanValue();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else if (token == XContentParser.Token.VALUE_NUMBER) { } else if (token == XContentParser.Token.VALUE_NUMBER) {
if ("min_doc_count".equals(currentFieldName) || "minDocCount".equals(currentFieldName)) { if ("min_doc_count".equals(currentFieldName) || "minDocCount".equals(currentFieldName)) {
@ -122,7 +124,8 @@ public class DateHistogramParser implements Aggregator.Parser {
} else if ("time_zone".equals(currentFieldName) || "timeZone".equals(currentFieldName)) { } else if ("time_zone".equals(currentFieldName) || "timeZone".equals(currentFieldName)) {
timeZone = DateTimeZone.forOffsetHours(parser.intValue()); timeZone = DateTimeZone.forOffsetHours(parser.intValue());
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else if (token == XContentParser.Token.START_OBJECT) { } else if (token == XContentParser.Token.START_OBJECT) {
if ("order".equals(currentFieldName)) { if ("order".equals(currentFieldName)) {
@ -147,7 +150,8 @@ public class DateHistogramParser implements Aggregator.Parser {
} else if ("max".equals(currentFieldName)) { } else if ("max".equals(currentFieldName)) {
extendedBounds.maxAsStr = parser.text(); extendedBounds.maxAsStr = parser.text();
} else { } else {
throw new SearchParseException(context, "Unknown extended_bounds key for a " + token + " in aggregation [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown extended_bounds key for a " + token + " in aggregation ["
+ aggregationName + "]: [" + currentFieldName + "].", parser.getTokenLocation());
} }
} else if (token == XContentParser.Token.VALUE_NUMBER) { } else if (token == XContentParser.Token.VALUE_NUMBER) {
if ("min".equals(currentFieldName)) { if ("min".equals(currentFieldName)) {
@ -155,23 +159,28 @@ public class DateHistogramParser implements Aggregator.Parser {
} else if ("max".equals(currentFieldName)) { } else if ("max".equals(currentFieldName)) {
extendedBounds.max = parser.longValue(); extendedBounds.max = parser.longValue();
} else { } else {
throw new SearchParseException(context, "Unknown extended_bounds key for a " + token + " in aggregation [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown extended_bounds key for a " + token + " in aggregation ["
+ aggregationName + "]: [" + currentFieldName + "].", parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} }
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "]."); throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
parser.getTokenLocation());
} }
} }
if (interval == null) { if (interval == null) {
throw new SearchParseException(context, "Missing required field [interval] for histogram aggregation [" + aggregationName + "]"); throw new SearchParseException(context,
"Missing required field [interval] for histogram aggregation [" + aggregationName + "]", parser.getTokenLocation());
} }
TimeZoneRounding.Builder tzRoundingBuilder; TimeZoneRounding.Builder tzRoundingBuilder;

View File

@ -56,7 +56,7 @@ public class ExtendedBounds {
} }
if (min != null && max != null && min.compareTo(max) > 0) { if (min != null && max != null && min.compareTo(max) > 0) {
throw new SearchParseException(context, "[extended_bounds.min][" + min + "] cannot be greater than " + throw new SearchParseException(context, "[extended_bounds.min][" + min + "] cannot be greater than " +
"[extended_bounds.max][" + max + "] for histogram aggregation [" + aggName + "]"); "[extended_bounds.max][" + max + "] for histogram aggregation [" + aggName + "]", null);
} }
} }

View File

@ -75,7 +75,8 @@ public class HistogramParser implements Aggregator.Parser {
} else if ("offset".equals(currentFieldName)) { } else if ("offset".equals(currentFieldName)) {
offset = parser.longValue(); offset = parser.longValue();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else if (token == XContentParser.Token.START_OBJECT) { } else if (token == XContentParser.Token.START_OBJECT) {
if ("order".equals(currentFieldName)) { if ("order".equals(currentFieldName)) {
@ -86,7 +87,8 @@ public class HistogramParser implements Aggregator.Parser {
String dir = parser.text(); String dir = parser.text();
boolean asc = "asc".equals(dir); boolean asc = "asc".equals(dir);
if (!asc && !"desc".equals(dir)) { if (!asc && !"desc".equals(dir)) {
throw new SearchParseException(context, "Unknown order direction [" + dir + "] in aggregation [" + aggregationName + "]. Should be either [asc] or [desc]"); throw new SearchParseException(context, "Unknown order direction [" + dir + "] in aggregation ["
+ aggregationName + "]. Should be either [asc] or [desc]", parser.getTokenLocation());
} }
order = resolveOrder(currentFieldName, asc); order = resolveOrder(currentFieldName, asc);
} }
@ -102,21 +104,25 @@ public class HistogramParser implements Aggregator.Parser {
} else if ("max".equals(currentFieldName)) { } else if ("max".equals(currentFieldName)) {
extendedBounds.max = parser.longValue(true); extendedBounds.max = parser.longValue(true);
} else { } else {
throw new SearchParseException(context, "Unknown extended_bounds key for a " + token + " in aggregation [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown extended_bounds key for a " + token + " in aggregation ["
+ aggregationName + "]: [" + currentFieldName + "].", parser.getTokenLocation());
} }
} }
} }
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unexpected token " + token + " in aggregation [" + aggregationName + "]."); throw new SearchParseException(context, "Unexpected token " + token + " in aggregation [" + aggregationName + "].",
parser.getTokenLocation());
} }
} }
if (interval < 1) { if (interval < 1) {
throw new SearchParseException(context, "Missing required field [interval] for histogram aggregation [" + aggregationName + "]"); throw new SearchParseException(context,
"Missing required field [interval] for histogram aggregation [" + aggregationName + "]", parser.getTokenLocation());
} }
Rounding rounding = new Rounding.Interval(interval); Rounding rounding = new Rounding.Interval(interval);

View File

@ -52,7 +52,8 @@ public class MissingParser implements Aggregator.Parser {
} else if (vsParser.token(currentFieldName, token, parser)) { } else if (vsParser.token(currentFieldName, token, parser)) {
continue; continue;
} else { } else {
throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "]."); throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
parser.getTokenLocation());
} }
} }

View File

@ -49,16 +49,19 @@ public class NestedParser implements Aggregator.Parser {
if ("path".equals(currentFieldName)) { if ("path".equals(currentFieldName)) {
path = parser.text(); path = parser.text();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "]."); throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
parser.getTokenLocation());
} }
} }
if (path == null) { if (path == null) {
// "field" doesn't exist, so we fall back to the context of the ancestors // "field" doesn't exist, so we fall back to the context of the ancestors
throw new SearchParseException(context, "Missing [path] field for nested aggregation [" + aggregationName + "]"); throw new SearchParseException(context, "Missing [path] field for nested aggregation [" + aggregationName + "]",
parser.getTokenLocation());
} }
return new NestedAggregator.Factory(aggregationName, path, context.queryParserService().autoFilterCachePolicy()); return new NestedAggregator.Factory(aggregationName, path, context.queryParserService().autoFilterCachePolicy());

View File

@ -131,7 +131,8 @@ public class ReverseNestedAggregator extends SingleBucketAggregator {
// Early validation // Early validation
NestedAggregator closestNestedAggregator = findClosestNestedAggregator(parent); NestedAggregator closestNestedAggregator = findClosestNestedAggregator(parent);
if (closestNestedAggregator == null) { if (closestNestedAggregator == null) {
throw new SearchParseException(context.searchContext(), "Reverse nested aggregation [" + name + "] can only be used inside a [nested] aggregation"); throw new SearchParseException(context.searchContext(), "Reverse nested aggregation [" + name
+ "] can only be used inside a [nested] aggregation", null);
} }
final ObjectMapper objectMapper; final ObjectMapper objectMapper;

View File

@ -49,10 +49,12 @@ public class ReverseNestedParser implements Aggregator.Parser {
if ("path".equals(currentFieldName)) { if ("path".equals(currentFieldName)) {
path = parser.text(); path = parser.text();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "]."); throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
parser.getTokenLocation());
} }
} }

View File

@ -89,21 +89,25 @@ public class RangeParser implements Aggregator.Parser {
ranges.add(new RangeAggregator.Range(key, from, fromAsStr, to, toAsStr)); ranges.add(new RangeAggregator.Range(key, from, fromAsStr, to, toAsStr));
} }
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else if (token == XContentParser.Token.VALUE_BOOLEAN) { } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
if ("keyed".equals(currentFieldName)) { if ("keyed".equals(currentFieldName)) {
keyed = parser.booleanValue(); keyed = parser.booleanValue();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "]."); throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
parser.getTokenLocation());
} }
} }
if (ranges == null) { if (ranges == null) {
throw new SearchParseException(context, "Missing [ranges] in ranges aggregator [" + aggregationName + "]"); throw new SearchParseException(context, "Missing [ranges] in ranges aggregator [" + aggregationName + "]",
parser.getTokenLocation());
} }
return new RangeAggregator.Factory(aggregationName, vsParser.config(), InternalRange.FACTORY, ranges, keyed); return new RangeAggregator.Factory(aggregationName, vsParser.config(), InternalRange.FACTORY, ranges, keyed);

View File

@ -79,7 +79,8 @@ public class DateRangeParser implements Aggregator.Parser {
} else if ("to".equals(toOrFromOrKey)) { } else if ("to".equals(toOrFromOrKey)) {
to = parser.doubleValue(); to = parser.doubleValue();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName
+ "]: [" + currentFieldName + "].", parser.getTokenLocation());
} }
} else if (token == XContentParser.Token.VALUE_STRING) { } else if (token == XContentParser.Token.VALUE_STRING) {
if ("from".equals(toOrFromOrKey)) { if ("from".equals(toOrFromOrKey)) {
@ -89,7 +90,7 @@ public class DateRangeParser implements Aggregator.Parser {
} else if ("key".equals(toOrFromOrKey)) { } else if ("key".equals(toOrFromOrKey)) {
key = parser.text(); key = parser.text();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "].", parser.getTokenLocation());
} }
} }
} }
@ -100,15 +101,18 @@ public class DateRangeParser implements Aggregator.Parser {
if ("keyed".equals(currentFieldName)) { if ("keyed".equals(currentFieldName)) {
keyed = parser.booleanValue(); keyed = parser.booleanValue();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "]."); throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
parser.getTokenLocation());
} }
} }
if (ranges == null) { if (ranges == null) {
throw new SearchParseException(context, "Missing [ranges] in ranges aggregator [" + aggregationName + "]"); throw new SearchParseException(context, "Missing [ranges] in ranges aggregator [" + aggregationName + "]",
parser.getTokenLocation());
} }
return new RangeAggregator.Factory(aggregationName, vsParser.config(), InternalDateRange.FACTORY, ranges, keyed); return new RangeAggregator.Factory(aggregationName, vsParser.config(), InternalDateRange.FACTORY, ranges, keyed);

View File

@ -98,13 +98,15 @@ public class GeoDistanceParser implements Aggregator.Parser {
} else if ("distance_type".equals(currentFieldName) || "distanceType".equals(currentFieldName)) { } else if ("distance_type".equals(currentFieldName) || "distanceType".equals(currentFieldName)) {
distanceType = GeoDistance.fromString(parser.text()); distanceType = GeoDistance.fromString(parser.text());
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else if (token == XContentParser.Token.VALUE_BOOLEAN) { } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
if ("keyed".equals(currentFieldName)) { if ("keyed".equals(currentFieldName)) {
keyed = parser.booleanValue(); keyed = parser.booleanValue();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else if (token == XContentParser.Token.START_ARRAY) { } else if (token == XContentParser.Token.START_ARRAY) {
if ("ranges".equals(currentFieldName)) { if ("ranges".equals(currentFieldName)) {
@ -138,20 +140,24 @@ public class GeoDistanceParser implements Aggregator.Parser {
ranges.add(new RangeAggregator.Range(key(key, from, to), from, fromAsStr, to, toAsStr)); ranges.add(new RangeAggregator.Range(key(key, from, to), from, fromAsStr, to, toAsStr));
} }
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "]."); throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
parser.getTokenLocation());
} }
} }
if (ranges == null) { if (ranges == null) {
throw new SearchParseException(context, "Missing [ranges] in geo_distance aggregator [" + aggregationName + "]"); throw new SearchParseException(context, "Missing [ranges] in geo_distance aggregator [" + aggregationName + "]",
parser.getTokenLocation());
} }
GeoPoint origin = geoPointParser.geoPoint(); GeoPoint origin = geoPointParser.geoPoint();
if (origin == null) { if (origin == null) {
throw new SearchParseException(context, "Missing [origin] in geo_distance aggregator [" + aggregationName + "]"); throw new SearchParseException(context, "Missing [origin] in geo_distance aggregator [" + aggregationName + "]",
parser.getTokenLocation());
} }
return new GeoDistanceFactory(aggregationName, vsParser.config(), InternalGeoDistance.FACTORY, origin, unit, distanceType, ranges, keyed); return new GeoDistanceFactory(aggregationName, vsParser.config(), InternalGeoDistance.FACTORY, origin, unit, distanceType, ranges, keyed);

View File

@ -99,21 +99,25 @@ public class IpRangeParser implements Aggregator.Parser {
ranges.add(range); ranges.add(range);
} }
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else if (token == XContentParser.Token.VALUE_BOOLEAN) { } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
if ("keyed".equals(currentFieldName)) { if ("keyed".equals(currentFieldName)) {
keyed = parser.booleanValue(); keyed = parser.booleanValue();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "]."); throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
parser.getTokenLocation());
} }
} }
if (ranges == null) { if (ranges == null) {
throw new SearchParseException(context, "Missing [ranges] in ranges aggregator [" + aggregationName + "]"); throw new SearchParseException(context, "Missing [ranges] in ranges aggregator [" + aggregationName + "]",
parser.getTokenLocation());
} }
return new RangeAggregator.Factory(aggregationName, vsParser.config(), InternalIPv4Range.FACTORY, ranges, keyed); return new RangeAggregator.Factory(aggregationName, vsParser.config(), InternalIPv4Range.FACTORY, ranges, keyed);
@ -122,7 +126,8 @@ public class IpRangeParser implements Aggregator.Parser {
private static void parseMaskRange(String cidr, RangeAggregator.Range range, String aggregationName, SearchContext ctx) { private static void parseMaskRange(String cidr, RangeAggregator.Range range, String aggregationName, SearchContext ctx) {
long[] fromTo = IPv4RangeBuilder.cidrMaskToMinMax(cidr); long[] fromTo = IPv4RangeBuilder.cidrMaskToMinMax(cidr);
if (fromTo == null) { if (fromTo == null) {
throw new SearchParseException(ctx, "invalid CIDR mask [" + cidr + "] in aggregation [" + aggregationName + "]"); throw new SearchParseException(ctx, "invalid CIDR mask [" + cidr + "] in aggregation [" + aggregationName + "]",
null);
} }
range.from = fromTo[0] < 0 ? Double.NEGATIVE_INFINITY : fromTo[0]; range.from = fromTo[0] < 0 ? Double.NEGATIVE_INFINITY : fromTo[0];
range.to = fromTo[1] < 0 ? Double.POSITIVE_INFINITY : fromTo[1]; range.to = fromTo[1] < 0 ? Double.POSITIVE_INFINITY : fromTo[1];

View File

@ -73,17 +73,18 @@ public class SamplerParser implements Aggregator.Parser {
maxDocsPerValue = parser.intValue(); maxDocsPerValue = parser.intValue();
} else { } else {
throw new SearchParseException(context, "Unsupported property \"" + currentFieldName + "\" for aggregation \"" throw new SearchParseException(context, "Unsupported property \"" + currentFieldName + "\" for aggregation \""
+ aggregationName); + aggregationName, parser.getTokenLocation());
} }
} else if (!vsParser.token(currentFieldName, token, parser)) { } else if (!vsParser.token(currentFieldName, token, parser)) {
if (EXECUTION_HINT_FIELD.match(currentFieldName)) { if (EXECUTION_HINT_FIELD.match(currentFieldName)) {
executionHint = parser.text(); executionHint = parser.text();
} else { } else {
throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "]."); throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unsupported property \"" + currentFieldName + "\" for aggregation \"" throw new SearchParseException(context, "Unsupported property \"" + currentFieldName + "\" for aggregation \""
+ aggregationName); + aggregationName, parser.getTokenLocation());
} }
} }
@ -93,7 +94,8 @@ public class SamplerParser implements Aggregator.Parser {
} else { } else {
if (diversityChoiceMade) { if (diversityChoiceMade) {
throw new SearchParseException(context, "Sampler aggregation has " + MAX_DOCS_PER_VALUE_FIELD.getPreferredName() throw new SearchParseException(context, "Sampler aggregation has " + MAX_DOCS_PER_VALUE_FIELD.getPreferredName()
+ " setting but no \"field\" or \"script\" setting to provide values for aggregation \"" + aggregationName + "\""); + " setting but no \"field\" or \"script\" setting to provide values for aggregation \"" + aggregationName + "\"",
parser.getTokenLocation());
} }
return new SamplerAggregator.Factory(aggregationName, shardSize); return new SamplerAggregator.Factory(aggregationName, shardSize);

View File

@ -68,10 +68,12 @@ public class SignificantTermsParametersParser extends AbstractTermsParametersPar
} else if (BACKGROUND_FILTER.match(currentFieldName)) { } else if (BACKGROUND_FILTER.match(currentFieldName)) {
filter = context.queryParserService().parseInnerFilter(parser).filter(); filter = context.queryParserService().parseInnerFilter(parser).filter();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName
+ "].", parser.getTokenLocation());
} }
} }

View File

@ -56,7 +56,8 @@ public class TermsParametersParser extends AbstractTermsParametersParser {
if ("order".equals(currentFieldName)) { if ("order".equals(currentFieldName)) {
this.orderElements = Collections.singletonList(parseOrderParam(aggregationName, parser, context)); this.orderElements = Collections.singletonList(parseOrderParam(aggregationName, parser, context));
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else if (token == XContentParser.Token.START_ARRAY) { } else if (token == XContentParser.Token.START_ARRAY) {
if ("order".equals(currentFieldName)) { if ("order".equals(currentFieldName)) {
@ -66,18 +67,21 @@ public class TermsParametersParser extends AbstractTermsParametersParser {
OrderElement orderParam = parseOrderParam(aggregationName, parser, context); OrderElement orderParam = parseOrderParam(aggregationName, parser, context);
orderElements.add(orderParam); orderElements.add(orderParam);
} else { } else {
throw new SearchParseException(context, "Order elements must be of type object in [" + aggregationName + "]."); throw new SearchParseException(context, "Order elements must be of type object in [" + aggregationName + "].",
parser.getTokenLocation());
} }
} }
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else if (token == XContentParser.Token.VALUE_BOOLEAN) { } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
if (SHOW_TERM_DOC_COUNT_ERROR.match(currentFieldName)) { if (SHOW_TERM_DOC_COUNT_ERROR.match(currentFieldName)) {
showTermDocCountError = parser.booleanValue(); showTermDocCountError = parser.booleanValue();
} }
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName
+ "].", parser.getTokenLocation());
} }
} }
@ -96,14 +100,17 @@ public class TermsParametersParser extends AbstractTermsParametersParser {
} else if ("desc".equalsIgnoreCase(dir)) { } else if ("desc".equalsIgnoreCase(dir)) {
orderAsc = false; orderAsc = false;
} else { } else {
throw new SearchParseException(context, "Unknown terms order direction [" + dir + "] in terms aggregation [" + aggregationName + "]"); throw new SearchParseException(context, "Unknown terms order direction [" + dir + "] in terms aggregation ["
+ aggregationName + "]", parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unexpected token " + token + " for [order] in [" + aggregationName + "]."); throw new SearchParseException(context, "Unexpected token " + token + " for [order] in [" + aggregationName + "].",
parser.getTokenLocation());
} }
} }
if (orderKey == null) { if (orderKey == null) {
throw new SearchParseException(context, "Must specify at least one field for [order] in [" + aggregationName + "]."); throw new SearchParseException(context, "Must specify at least one field for [order] in [" + aggregationName + "].",
parser.getTokenLocation());
} else { } else {
orderParam = new OrderElement(orderKey, orderAsc); orderParam = new OrderElement(orderKey, orderAsc);
} }

View File

@ -58,7 +58,8 @@ public abstract class NumericValuesSourceMetricsAggregatorParser<S extends Inter
if (token == XContentParser.Token.FIELD_NAME) { if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName(); currentFieldName = parser.currentName();
} else if (!vsParser.token(currentFieldName, token, parser)) { } else if (!vsParser.token(currentFieldName, token, parser)) {
throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "]."); throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
parser.getTokenLocation());
} }
} }

View File

@ -62,10 +62,11 @@ public class CardinalityParser implements Aggregator.Parser {
} else if (PRECISION_THRESHOLD.match(currentFieldName)) { } else if (PRECISION_THRESHOLD.match(currentFieldName)) {
precisionThreshold = parser.longValue(); precisionThreshold = parser.longValue();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + name + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + name + "]: [" + currentFieldName
+ "].", parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unexpected token " + token + " in [" + name + "]."); throw new SearchParseException(context, "Unexpected token " + token + " in [" + name + "].", parser.getTokenLocation());
} }
} }

View File

@ -56,10 +56,12 @@ public class GeoBoundsParser implements Aggregator.Parser {
if ("wrap_longitude".equals(currentFieldName) || "wrapLongitude".equals(currentFieldName)) { if ("wrap_longitude".equals(currentFieldName) || "wrapLongitude".equals(currentFieldName)) {
wrapLongitude = parser.booleanValue(); wrapLongitude = parser.booleanValue();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} }
return new GeoBoundsAggregator.Factory(aggregationName, vsParser.config(), wrapLongitude); return new GeoBoundsAggregator.Factory(aggregationName, vsParser.config(), wrapLongitude);

View File

@ -69,22 +69,26 @@ public abstract class AbstractPercentilesParser implements Aggregator.Parser {
keys = values.toArray(); keys = values.toArray();
Arrays.sort(keys); Arrays.sort(keys);
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else if (token == XContentParser.Token.VALUE_BOOLEAN) { } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
if ("keyed".equals(currentFieldName)) { if ("keyed".equals(currentFieldName)) {
keyed = parser.booleanValue(); keyed = parser.booleanValue();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else if (token == XContentParser.Token.VALUE_NUMBER) { } else if (token == XContentParser.Token.VALUE_NUMBER) {
if ("compression".equals(currentFieldName)) { if ("compression".equals(currentFieldName)) {
compression = parser.doubleValue(); compression = parser.doubleValue();
} else { } else {
throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
+ currentFieldName + "].", parser.getTokenLocation());
} }
} else { } else {
throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "]."); throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
parser.getTokenLocation());
} }
} }
return buildFactory(context, aggregationName, vsParser.config(), keys, compression, keyed); return buildFactory(context, aggregationName, vsParser.config(), keys, compression, keyed);

View File

@ -46,7 +46,7 @@ public class PercentileRanksParser extends AbstractPercentilesParser {
@Override @Override
protected AggregatorFactory buildFactory(SearchContext context, String aggregationName, ValuesSourceConfig<Numeric> valuesSourceConfig, double[] keys, double compression, boolean keyed) { protected AggregatorFactory buildFactory(SearchContext context, String aggregationName, ValuesSourceConfig<Numeric> valuesSourceConfig, double[] keys, double compression, boolean keyed) {
if (keys == null) { if (keys == null) {
throw new SearchParseException(context, "Missing token values in [" + aggregationName + "]."); throw new SearchParseException(context, "Missing token values in [" + aggregationName + "].", null);
} }
return new PercentileRanksAggregator.Factory(aggregationName, valuesSourceConfig, keys, compression, keyed); return new PercentileRanksAggregator.Factory(aggregationName, valuesSourceConfig, keys, compression, keyed);
} }

Some files were not shown because too many files have changed in this diff Show More