Search in sources :

Example 36 with QueryParseContext

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());
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) XContentParser(org.elasticsearch.common.xcontent.XContentParser) IOException(java.io.IOException)

Example 37 with QueryParseContext

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());
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 38 with QueryParseContext

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();
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext)

Example 39 with QueryParseContext

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());
    }
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) ParsingException(org.elasticsearch.common.ParsingException) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 40 with QueryParseContext

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());
    }
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) ParsingException(org.elasticsearch.common.ParsingException) 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