Java Code Examples for org.elasticsearch.index.query.QueryParseContext#reset()

The following examples show how to use org.elasticsearch.index.query.QueryParseContext#reset() . 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: InnerHitsParseElement.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void parse(XContentParser parser, SearchContext searchContext) throws Exception {
    QueryParseContext context = searchContext.queryParserService().getParseContext();
    context.reset(parser);
    Map<String, InnerHitsContext.BaseInnerHits> topLevelInnerHits = parseInnerHits(parser, context, searchContext);
    if (topLevelInnerHits != null) {
        InnerHitsContext innerHitsContext = searchContext.innerHits();
        innerHitsContext.addInnerHitDefinitions(topLevelInnerHits);
    }
}
 
Example 2
Source File: PercolatorQueriesRegistry.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private Query parseQuery(String type, XContentParser parser) {
    String[] previousTypes = null;
    if (type != null) {
        QueryParseContext.setTypesWithPrevious(new String[]{type});
    }
    QueryParseContext context = queryParserService.getParseContext();
    try {
        context.reset(parser);
        // This means that fields in the query need to exist in the mapping prior to registering this query
        // The reason that this is required, is that if a field doesn't exist then the query assumes defaults, which may be undesired.
        //
        // Even worse when fields mentioned in percolator queries do go added to map after the queries have been registered
        // then the percolator queries don't work as expected any more.
        //
        // Query parsing can't introduce new fields in mappings (which happens when registering a percolator query),
        // because field type can't be inferred from queries (like document do) so the best option here is to disallow
        // the usage of unmapped fields in percolator queries to avoid unexpected behaviour
        //
        // if index.percolator.map_unmapped_fields_as_string is set to true, query can contain unmapped fields which will be mapped
        // as an analyzed string.
        context.setAllowUnmappedFields(false);
        context.setMapUnmappedFieldAsString(mapUnmappedFieldsAsString ? true : false);
        return queryParserService.parseInnerQuery(context);
    } catch (IOException e) {
        throw new QueryParsingException(context, "Failed to parse", e);
    } finally {
        if (type != null) {
            QueryParseContext.setTypes(previousTypes);
        }
        context.reset(null);
    }
}
 
Example 3
Source File: AliasValidator.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private void validateAliasFilter(XContentParser parser, IndexQueryParserService indexQueryParserService) throws IOException {
    QueryParseContext context = indexQueryParserService.getParseContext();
    try {
        context.reset(parser);
        context.parseInnerFilter();
    } finally {
        context.reset(null);
        parser.close();
    }
}