Search in sources :

Example 6 with QueryParseContext

use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.

the class ScriptSortBuilderTests method testParseBadFieldNameExceptionsOnStartObject.

public void testParseBadFieldNameExceptionsOnStartObject() throws IOException {
    String scriptSort = "{\"_script\" : {" + "\"bad_field\" : { \"order\" : \"asc\" } } }";
    XContentParser parser = createParser(JsonXContent.jsonXContent, scriptSort);
    parser.nextToken();
    parser.nextToken();
    parser.nextToken();
    QueryParseContext context = new QueryParseContext(parser);
    Exception e = expectThrows(IllegalArgumentException.class, () -> ScriptSortBuilder.fromXContent(context, null));
    assertEquals("[_script] unknown field [bad_field], parser not found", e.getMessage());
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) XContentParser(org.elasticsearch.common.xcontent.XContentParser) IOException(java.io.IOException)

Example 7 with QueryParseContext

use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.

the class QueryContextTestCase method testToXContext.

public void testToXContext() throws IOException {
    for (int i = 0; i < NUMBER_OF_RUNS; i++) {
        QC toXContent = createTestModel();
        XContentBuilder builder = XContentFactory.jsonBuilder();
        toXContent.toXContent(builder, ToXContent.EMPTY_PARAMS);
        XContentParser parser = createParser(builder);
        parser.nextToken();
        QC fromXContext = fromXContent(new QueryParseContext(parser));
        assertEquals(toXContent, fromXContext);
        assertEquals(toXContent.hashCode(), fromXContext.hashCode());
    }
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 8 with QueryParseContext

use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.

the class AbstractQueryTestCase method parseQuery.

protected static QueryBuilder parseQuery(XContentParser parser) throws IOException {
    QueryParseContext context = createParseContext(parser);
    QueryBuilder parseInnerQueryBuilder = context.parseInnerQueryBuilder();
    assertNull(parser.nextToken());
    return parseInnerQueryBuilder;
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) AbstractQueryBuilder(org.elasticsearch.index.query.AbstractQueryBuilder)

Example 9 with QueryParseContext

use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.

the class BasePipelineAggregationTestCase method parse.

protected PipelineAggregationBuilder parse(XContentParser parser) throws IOException {
    QueryParseContext parseContext = new QueryParseContext(parser);
    assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
    AggregatorFactories.Builder parsed = AggregatorFactories.parseAggregators(parseContext);
    assertThat(parsed.getAggregatorFactories(), hasSize(0));
    assertThat(parsed.getPipelineAggregatorFactories(), hasSize(1));
    PipelineAggregationBuilder newAgg = parsed.getPipelineAggregatorFactories().get(0);
    assertNull(parser.nextToken());
    assertNotNull(newAgg);
    return newAgg;
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) AbstractPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder)

Example 10 with QueryParseContext

use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.

the class AggregationCollectorTests method needsScores.

private boolean needsScores(IndexService index, String agg) throws IOException {
    XContentParser aggParser = createParser(JsonXContent.jsonXContent, agg);
    QueryParseContext parseContext = new QueryParseContext(aggParser);
    aggParser.nextToken();
    SearchContext context = createSearchContext(index);
    final AggregatorFactories factories = AggregatorFactories.parseAggregators(parseContext).build(context, null);
    final Aggregator[] aggregators = factories.createTopLevelAggregators();
    assertEquals(1, aggregators.length);
    return aggregators[0].needsScores();
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) SearchContext(org.elasticsearch.search.internal.SearchContext) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Aggregations

QueryParseContext (org.elasticsearch.index.query.QueryParseContext)55 XContentParser (org.elasticsearch.common.xcontent.XContentParser)45 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)14 ParsingException (org.elasticsearch.common.ParsingException)12 IOException (java.io.IOException)7 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)5 ArrayList (java.util.ArrayList)2 Collections.unmodifiableMap (java.util.Collections.unmodifiableMap)2 List (java.util.List)2 Map (java.util.Map)2 Consumer (java.util.function.Consumer)2 SearchRequest (org.elasticsearch.action.search.SearchRequest)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 BytesReference (org.elasticsearch.common.bytes.BytesReference)2 NamedXContentRegistry (org.elasticsearch.common.xcontent.NamedXContentRegistry)2 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)2 SignificanceHeuristicParser (org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicParser)2 IncludeExclude (org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude)2 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)2 SearchContext (org.elasticsearch.search.internal.SearchContext)2