use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.
the class ScriptSortBuilderTests method testParseBadFieldNameExceptions.
public void testParseBadFieldNameExceptions() throws IOException {
String scriptSort = "{\"_script\" : {" + "\"bad_field\" : \"number\"" + "} }";
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 GeoDistanceSortBuilderTests method testSortModeSumIsRejectedInJSON.
public void testSortModeSumIsRejectedInJSON() throws IOException {
String json = "{\n" + " \"testname\" : [ {\n" + " \"lat\" : -6.046997540714173,\n" + " \"lon\" : -51.94128329747579\n" + " } ],\n" + " \"unit\" : \"m\",\n" + " \"distance_type\" : \"arc\",\n" + " \"mode\" : \"SUM\"\n" + "}";
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
itemParser.nextToken();
QueryParseContext context = new QueryParseContext(itemParser);
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> GeoDistanceSortBuilder.fromXContent(context, ""));
assertEquals("sort_mode [sum] isn't supported for sorting by geo distance", e.getMessage());
}
use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.
the class SignificanceHeuristicTests method parseSignificanceHeuristic.
private SignificanceHeuristic parseSignificanceHeuristic(ParseFieldRegistry<SignificanceHeuristicParser> significanceHeuristicParserRegistry, XContentParser stParser) throws IOException {
QueryParseContext parseContext = new QueryParseContext(stParser);
stParser.nextToken();
SignificantTermsAggregationBuilder aggregatorFactory = (SignificantTermsAggregationBuilder) SignificantTermsAggregationBuilder.getParser(significanceHeuristicParserRegistry).parse("testagg", parseContext);
stParser.nextToken();
assertThat(aggregatorFactory.getBucketCountThresholds().getMinDocCount(), equalTo(200L));
assertThat(stParser.currentToken(), equalTo(null));
stParser.close();
return aggregatorFactory.significanceHeuristic();
}
use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.
the class GeoHashGridParserTests method testParseErrorOnPrecisionOutOfRange.
public void testParseErrorOnPrecisionOutOfRange() throws Exception {
XContentParser stParser = createParser(JsonXContent.jsonXContent, "{\"field\":\"my_loc\", \"precision\":\"13\"}");
QueryParseContext parseContext = new QueryParseContext(stParser);
XContentParser.Token token = stParser.nextToken();
assertSame(XContentParser.Token.START_OBJECT, token);
try {
GeoGridAggregationBuilder.parse("geohash_grid", parseContext);
fail();
} catch (ParsingException ex) {
assertThat(ex.getCause(), instanceOf(IllegalArgumentException.class));
assertEquals("Invalid geohash aggregation precision of 13. Must be between 1 and 12.", ex.getCause().getMessage());
}
}
use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.
the class GeoHashGridParserTests method testParseErrorOnNonIntPrecision.
public void testParseErrorOnNonIntPrecision() throws Exception {
XContentParser stParser = createParser(JsonXContent.jsonXContent, "{\"field\":\"my_loc\", \"precision\":\"2.0\"}");
QueryParseContext parseContext = new QueryParseContext(stParser);
XContentParser.Token token = stParser.nextToken();
assertSame(XContentParser.Token.START_OBJECT, token);
try {
GeoGridAggregationBuilder.parse("geohash_grid", parseContext);
fail();
} catch (ParsingException ex) {
assertThat(ex.getCause(), instanceOf(NumberFormatException.class));
assertEquals("For input string: \"2.0\"", ex.getCause().getMessage());
}
}
Aggregations