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());
}
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());
}
}
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;
}
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;
}
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();
}
Aggregations