use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.
the class AggregatorFactoriesTests method testTwoAggs.
public void testTwoAggs() throws Exception {
assumeFalse("Test only makes sense if XContent parser doesn't have strict duplicate checks enabled", XContent.isStrictDuplicateDetectionEnabled());
XContentBuilder source = JsonXContent.contentBuilder().startObject().startObject("by_date").startObject("date_histogram").field("field", "timestamp").field("interval", "month").endObject().startObject("aggs").startObject("tag_count").startObject("cardinality").field("field", "tag").endObject().endObject().endObject().startObject(// 2nd "aggs": illegal
"aggs").startObject("tag_count2").startObject("cardinality").field("field", "tag").endObject().endObject().endObject().endObject().endObject();
XContentParser parser = createParser(source);
QueryParseContext parseContext = new QueryParseContext(parser);
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
Exception e = expectThrows(ParsingException.class, () -> AggregatorFactories.parseAggregators(parseContext));
assertThat(e.toString(), containsString("Found two sub aggregation definitions under [by_date]"));
}
use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.
the class AggregatorFactoriesTests method testInvalidAggregationName.
public void testInvalidAggregationName() throws Exception {
Matcher matcher = Pattern.compile("[^\\[\\]>]+").matcher("");
String name;
Random rand = random();
int len = randomIntBetween(1, 5);
char[] word = new char[len];
while (true) {
for (int i = 0; i < word.length; i++) {
word[i] = (char) rand.nextInt(127);
}
name = String.valueOf(word);
if (!matcher.reset(name).matches()) {
break;
}
}
XContentBuilder source = JsonXContent.contentBuilder().startObject().startObject(name).startObject("filter").startObject("range").startObject("stock").field("gt", 0).endObject().endObject().endObject().endObject().endObject();
XContentParser parser = createParser(source);
QueryParseContext parseContext = new QueryParseContext(parser);
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
Exception e = expectThrows(ParsingException.class, () -> AggregatorFactories.parseAggregators(parseContext));
assertThat(e.toString(), containsString("Invalid aggregation name [" + name + "]"));
}
use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.
the class SignificanceHeuristicTests method checkParseException.
protected void checkParseException(ParseFieldRegistry<SignificanceHeuristicParser> significanceHeuristicParserRegistry, String faultyHeuristicDefinition, String expectedError) throws IOException {
try {
XContentParser stParser = createParser(JsonXContent.jsonXContent, "{\"field\":\"text\", " + faultyHeuristicDefinition + ",\"min_doc_count\":200}");
QueryParseContext parseContext = new QueryParseContext(stParser);
stParser.nextToken();
SignificantTermsAggregationBuilder.getParser(significanceHeuristicParserRegistry).parse("testagg", parseContext);
fail();
} catch (ParsingException e) {
assertThat(e.getCause().getMessage(), containsString(expectedError));
}
}
use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.
the class GeoHashGridParserTests method testParseValidFromStrings.
public void testParseValidFromStrings() 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 GeoHashGridParserTests method testParseErrorOnBooleanPrecision.
public void testParseErrorOnBooleanPrecision() throws Exception {
XContentParser stParser = createParser(JsonXContent.jsonXContent, "{\"field\":\"my_loc\", \"precision\":false}");
QueryParseContext parseContext = new QueryParseContext(stParser);
XContentParser.Token token = stParser.nextToken();
assertSame(XContentParser.Token.START_OBJECT, token);
try {
GeoGridAggregationBuilder.parse("geohash_grid", parseContext);
fail();
} catch (IllegalArgumentException ex) {
assertEquals("[geohash_grid] precision doesn't support values of type: VALUE_BOOLEAN", ex.getMessage());
}
}
Aggregations