org.elasticsearch.common.xcontent.XContentLocation Java Examples

The following examples show how to use org.elasticsearch.common.xcontent.XContentLocation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryParsingException.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public QueryParsingException(QueryParseContext parseContext, String msg, Throwable cause, Object... args) {
    super(msg, cause, args);
    setIndex(parseContext.index());
    int lineNumber = UNKNOWN_POSITION;
    int columnNumber = UNKNOWN_POSITION;
    XContentParser parser = parseContext.parser();
    if (parser != null) {
        XContentLocation location = parser.getTokenLocation();
        if (location != null) {
            lineNumber = location.lineNumber;
            columnNumber = location.columnNumber;
        }
    }
    this.columnNumber = columnNumber;
    this.lineNumber = lineNumber;
}
 
Example #2
Source File: SearchParseException.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public SearchParseException(SearchContext context, String msg, @Nullable XContentLocation location, Throwable cause) {
    super(context, msg, cause);
    int lineNumber = UNKNOWN_POSITION;
    int columnNumber = UNKNOWN_POSITION;
    if (location != null) {
        if (location != null) {
            lineNumber = location.lineNumber;
            columnNumber = location.columnNumber;
        }
    }
    this.columnNumber = columnNumber;
    this.lineNumber = lineNumber;
}
 
Example #3
Source File: JsonXContentParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public XContentLocation getTokenLocation() {
    JsonLocation loc = parser.getTokenLocation();
    if (loc == null) {
        return null;
    }
    return new XContentLocation(loc.getLineNr(), loc.getColumnNr());
}
 
Example #4
Source File: JsonXContentParser.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public XContentLocation getTokenLocation() {
    JsonLocation loc = parser.getTokenLocation();
    if (loc == null) {
        return null;
    }
    return new XContentLocation(loc.getLineNr(), loc.getColumnNr());
}
 
Example #5
Source File: ParsingException.java    From crate with Apache License 2.0 5 votes vote down vote up
public ParsingException(XContentLocation contentLocation, String msg, Throwable cause, Object... args) {
    super(msg, cause, args);
    int lineNumber = UNKNOWN_POSITION;
    int columnNumber = UNKNOWN_POSITION;
    if (contentLocation != null) {
        lineNumber = contentLocation.lineNumber;
        columnNumber = contentLocation.columnNumber;
    }
    this.columnNumber = columnNumber;
    this.lineNumber = lineNumber;
}
 
Example #6
Source File: SearchParseException.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public SearchParseException(SearchContext context, String msg, @Nullable XContentLocation location) {
    this(context, msg, location, null);
}
 
Example #7
Source File: SearchService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
private void parseSource(SearchContext context, BytesReference source) throws SearchParseException {
    // nothing to parse...
    if (source == null || source.length() == 0) {
        return;
    }
    String abc = source.toUtf8();
    XContentParser parser = null;
    try {
        parser = XContentFactory.xContent(source).createParser(source);
        XContentParser.Token token;
        token = parser.nextToken();
        if (token != XContentParser.Token.START_OBJECT) {
            throw new ElasticsearchParseException("failed to parse search source. source must be an object, but found [{}] instead", token.name());
        }
        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (token == XContentParser.Token.FIELD_NAME) {
                String fieldName = parser.currentName();
                parser.nextToken();
                SearchParseElement element = elementParsers.get(fieldName);
                if (element == null) {
                    throw new SearchParseException(context, "failed to parse search source. unknown search element [" + fieldName + "]", parser.getTokenLocation());
                }
                element.parse(parser, context);
            } else {
                if (token == null) {
                    throw new ElasticsearchParseException("failed to parse search source. end of query source reached but query is not complete.");
                } else {
                    throw new ElasticsearchParseException("failed to parse search source. expected field name but got [{}]", token);
                }
            }
        }
    } catch (Throwable e) {
        String sSource = "_na_";
        try {
            sSource = XContentHelper.convertToJson(source, false);
        } catch (Throwable e1) {
            // ignore
        }
        XContentLocation location = parser != null ? parser.getTokenLocation() : null;
        throw new SearchParseException(context, "failed to parse search source [" + sSource + "]", location, e);
    } finally {
        if (parser != null) {
            parser.close();
        }
    }
}
 
Example #8
Source File: XmlXContentParser.java    From elasticsearch-xml with Apache License 2.0 4 votes vote down vote up
@Override
public XContentLocation getTokenLocation() {
    return null;
}
 
Example #9
Source File: ParsingException.java    From crate with Apache License 2.0 4 votes vote down vote up
public ParsingException(XContentLocation contentLocation, String msg, Object... args) {
    this(contentLocation, msg, null, args);
}