use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.
the class GeoHashGridParserTests method testParseValidFromInts.
public void testParseValidFromInts() throws Exception {
int precision = randomIntBetween(1, 12);
XContentParser stParser = createParser(JsonXContent.jsonXContent, "{\"field\":\"my_loc\", \"precision\":" + precision + ", \"size\": 500, \"shard_size\": 550}");
QueryParseContext parseContext = new QueryParseContext(stParser);
XContentParser.Token token = stParser.nextToken();
assertSame(XContentParser.Token.START_OBJECT, token);
// can create a factory
assertNotNull(GeoGridAggregationBuilder.parse("geohash_grid", parseContext));
}
use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.
the class FiltersTests method testOtherBucket.
public void testOtherBucket() throws IOException {
XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
builder.startObject();
builder.startArray("filters").endArray();
builder.endObject();
XContentParser parser = createParser(shuffleXContent(builder));
parser.nextToken();
QueryParseContext context = new QueryParseContext(parser);
FiltersAggregationBuilder filters = FiltersAggregationBuilder.parse("agg_name", context);
// The other bucket is disabled by default
assertFalse(filters.otherBucket());
builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
builder.startObject();
builder.startArray("filters").endArray();
builder.field("other_bucket_key", "some_key");
builder.endObject();
parser = createParser(shuffleXContent(builder));
parser.nextToken();
context = new QueryParseContext(parser);
filters = FiltersAggregationBuilder.parse("agg_name", context);
// but setting a key enables it automatically
assertTrue(filters.otherBucket());
builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
builder.startObject();
builder.startArray("filters").endArray();
builder.field("other_bucket", false);
builder.field("other_bucket_key", "some_key");
builder.endObject();
parser = createParser(shuffleXContent(builder));
parser.nextToken();
context = new QueryParseContext(parser);
filters = FiltersAggregationBuilder.parse("agg_name", context);
// unless the other bucket is explicitly disabled
assertFalse(filters.otherBucket());
}
use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.
the class TopHitsTests method testFailWithSubAgg.
public void testFailWithSubAgg() throws Exception {
String source = "{\n" + " \"top-tags\": {\n" + " \"terms\": {\n" + " \"field\": \"tags\"\n" + " },\n" + " \"aggs\": {\n" + " \"top_tags_hits\": {\n" + " \"top_hits\": {},\n" + " \"aggs\": {\n" + " \"max\": {\n" + " \"max\": {\n" + " \"field\": \"age\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}";
XContentParser parser = createParser(JsonXContent.jsonXContent, source);
QueryParseContext parseContext = new QueryParseContext(parser);
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
Exception e = expectThrows(AggregationInitializationException.class, () -> AggregatorFactories.parseAggregators(parseContext));
assertThat(e.toString(), containsString("Aggregator [top_tags_hits] of type [top_hits] cannot accept sub-aggregations"));
}
use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.
the class IncludeExcludeTests method serialize.
// Serializes/deserializes an IncludeExclude statement with a single clause
private IncludeExclude serialize(IncludeExclude incExc, ParseField field) throws IOException {
XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
if (randomBoolean()) {
builder.prettyPrint();
}
builder.startObject();
incExc.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
XContentParser parser = createParser(builder);
XContentParser.Token token = parser.nextToken();
assertEquals(token, XContentParser.Token.START_OBJECT);
token = parser.nextToken();
assertEquals(token, XContentParser.Token.FIELD_NAME);
assertEquals(field.getPreferredName(), parser.currentName());
token = parser.nextToken();
QueryParseContext parseContext = new QueryParseContext(parser);
if (field.getPreferredName().equalsIgnoreCase("include")) {
return IncludeExclude.parseInclude(parser, parseContext);
} else if (field.getPreferredName().equalsIgnoreCase("exclude")) {
return IncludeExclude.parseExclude(parser, parseContext);
} else {
throw new IllegalArgumentException("Unexpected field name serialized in test: " + field.getPreferredName());
}
}
use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.
the class HighlightBuilderTests method expectParseThrows.
private <T extends Throwable> T expectParseThrows(Class<T> exceptionClass, String highlightElement) throws IOException {
XContentParser parser = createParser(JsonXContent.jsonXContent, highlightElement);
QueryParseContext context = new QueryParseContext(parser);
return expectThrows(exceptionClass, () -> HighlightBuilder.fromXContent(context));
}
Aggregations