use of org.elasticsearch.common.xcontent.NamedXContentRegistry.UnknownNamedObjectException in project elasticsearch by elastic.
the class QueryParseContext method parseInnerQueryBuilder.
/**
* Parses a query excluding the query element that wraps it
*/
public QueryBuilder parseInnerQueryBuilder() throws IOException {
if (parser.currentToken() != XContentParser.Token.START_OBJECT) {
if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
throw new ParsingException(parser.getTokenLocation(), "[_na] query malformed, must start with start_object");
}
}
if (parser.nextToken() == XContentParser.Token.END_OBJECT) {
// we encountered '{}' for a query clause, it used to be supported, deprecated in 5.0 and removed in 6.0
throw new IllegalArgumentException("query malformed, empty clause found at [" + parser.getTokenLocation() + "]");
}
if (parser.currentToken() != XContentParser.Token.FIELD_NAME) {
throw new ParsingException(parser.getTokenLocation(), "[_na] query malformed, no field after start_object");
}
String queryName = parser.currentName();
// move to the next START_OBJECT
if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
throw new ParsingException(parser.getTokenLocation(), "[" + queryName + "] query malformed, no start_object after query name");
}
QueryBuilder result;
try {
result = parser.namedObject(QueryBuilder.class, queryName, this);
} catch (UnknownNamedObjectException e) {
// This intentionally doesn't include the causing exception because that'd change the "root_cause" of any unknown query errors
throw new ParsingException(new XContentLocation(e.getLineNumber(), e.getColumnNumber()), "no [query] registered for [" + e.getName() + "]");
}
//end_object of the specific query (e.g. match, multi_match etc.) element
if (parser.currentToken() != XContentParser.Token.END_OBJECT) {
throw new ParsingException(parser.getTokenLocation(), "[" + queryName + "] malformed query, expected [END_OBJECT] but found [" + parser.currentToken() + "]");
}
//end_object of the query object
if (parser.nextToken() != XContentParser.Token.END_OBJECT) {
throw new ParsingException(parser.getTokenLocation(), "[" + queryName + "] malformed query, expected [END_OBJECT] but found [" + parser.currentToken() + "]");
}
return result;
}
use of org.elasticsearch.common.xcontent.NamedXContentRegistry.UnknownNamedObjectException in project elasticsearch by elastic.
the class UnknownNamedObjectExceptionTests method testRoundTrip.
public void testRoundTrip() throws IOException {
XContentLocation location = new XContentLocation(between(1, 1000), between(1, 1000));
UnknownNamedObjectException created = new UnknownNamedObjectException(location, UnknownNamedObjectExceptionTests.class, randomAsciiOfLength(5));
UnknownNamedObjectException roundTripped;
try (BytesStreamOutput out = new BytesStreamOutput()) {
created.writeTo(out);
try (StreamInput in = out.bytes().streamInput()) {
roundTripped = new UnknownNamedObjectException(in);
}
}
assertEquals(created.getMessage(), roundTripped.getMessage());
assertEquals(created.getLineNumber(), roundTripped.getLineNumber());
assertEquals(created.getColumnNumber(), roundTripped.getColumnNumber());
assertEquals(created.getCategoryClass(), roundTripped.getCategoryClass());
assertEquals(created.getName(), roundTripped.getName());
}
use of org.elasticsearch.common.xcontent.NamedXContentRegistry.UnknownNamedObjectException in project elasticsearch by elastic.
the class UnknownNamedObjectExceptionTests method testStatusCode.
public void testStatusCode() {
XContentLocation location = new XContentLocation(between(1, 1000), between(1, 1000));
UnknownNamedObjectException e = new UnknownNamedObjectException(location, UnknownNamedObjectExceptionTests.class, randomAsciiOfLength(5));
assertEquals(RestStatus.BAD_REQUEST, e.status());
}
Aggregations