當前位置: 首頁>>代碼示例>>Java>>正文


Java QueryParseContext類代碼示例

本文整理匯總了Java中org.elasticsearch.index.query.QueryParseContext的典型用法代碼示例。如果您正苦於以下問題:Java QueryParseContext類的具體用法?Java QueryParseContext怎麽用?Java QueryParseContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


QueryParseContext類屬於org.elasticsearch.index.query包,在下文中一共展示了QueryParseContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testFromXContent

import org.elasticsearch.index.query.QueryParseContext; //導入依賴的package包/類
/**
 *  creates random highlighter, renders it to xContent and back to new instance that should be equal to original
 */
public void testFromXContent() throws IOException {
    for (int runs = 0; runs < NUMBER_OF_TESTBUILDERS; runs++) {
        HighlightBuilder highlightBuilder = randomHighlighterBuilder();
        XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
        if (randomBoolean()) {
            builder.prettyPrint();
        }
        highlightBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
        XContentBuilder shuffled = shuffleXContent(builder);

        XContentParser parser = createParser(shuffled);
        QueryParseContext context = new QueryParseContext(parser);
        parser.nextToken();
        HighlightBuilder secondHighlightBuilder;
        try {
            secondHighlightBuilder = HighlightBuilder.fromXContent(context);
        } catch (RuntimeException e) {
            throw new RuntimeException("Error parsing " + highlightBuilder, e);
        }
        assertNotSame(highlightBuilder, secondHighlightBuilder);
        assertEquals(highlightBuilder, secondHighlightBuilder);
        assertEquals(highlightBuilder.hashCode(), secondHighlightBuilder.hashCode());
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:28,代碼來源:HighlightBuilderTests.java

示例2: testFromXContent

import org.elasticsearch.index.query.QueryParseContext; //導入依賴的package包/類
public void testFromXContent() throws Exception {
    SliceBuilder sliceBuilder = randomSliceBuilder();
    XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
    if (randomBoolean()) {
        builder.prettyPrint();
    }
    builder.startObject();
    sliceBuilder.innerToXContent(builder);
    builder.endObject();
    XContentParser parser = createParser(shuffleXContent(builder));
    QueryParseContext context = new QueryParseContext(parser);
    SliceBuilder secondSliceBuilder = SliceBuilder.fromXContent(context);
    assertNotSame(sliceBuilder, secondSliceBuilder);
    assertEquals(sliceBuilder, secondSliceBuilder);
    assertEquals(sliceBuilder.hashCode(), secondSliceBuilder.hashCode());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:SliceBuilderTests.java

示例3: testFromXContent

import org.elasticsearch.index.query.QueryParseContext; //導入依賴的package包/類
/**
 *  creates random rescorer, renders it to xContent and back to new instance that should be equal to original
 */
public void testFromXContent() throws IOException {
    for (int runs = 0; runs < NUMBER_OF_TESTBUILDERS; runs++) {
        RescoreBuilder<?> rescoreBuilder = randomRescoreBuilder();
        XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
        if (randomBoolean()) {
            builder.prettyPrint();
        }
        rescoreBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
        XContentBuilder shuffled = shuffleXContent(builder);


        XContentParser parser = createParser(shuffled);
        QueryParseContext context = new QueryParseContext(parser);
        parser.nextToken();
        RescoreBuilder<?> secondRescoreBuilder = RescoreBuilder.parseFromXContent(context);
        assertNotSame(rescoreBuilder, secondRescoreBuilder);
        assertEquals(rescoreBuilder, secondRescoreBuilder);
        assertEquals(rescoreBuilder.hashCode(), secondRescoreBuilder.hashCode());
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:QueryRescoreBuilderTests.java

示例4: parse

import org.elasticsearch.index.query.QueryParseContext; //導入依賴的package包/類
public InnerHitsSubSearchContext parse(QueryParseContext parserContext) throws IOException, QueryParsingException {
    String fieldName = null;
    XContentParser.Token token;
    String innerHitName = null;
    SubSearchContext subSearchContext = new SubSearchContext(SearchContext.current());
    try {
        XContentParser parser = parserContext.parser();
        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (token == XContentParser.Token.FIELD_NAME) {
                fieldName = parser.currentName();
            } else if (token.isValue()) {
                if ("name".equals(fieldName)) {
                    innerHitName = parser.textOrNull();
                } else {
                    parseCommonInnerHitOptions(parser, token, fieldName, subSearchContext, sortParseElement, sourceParseElement, highlighterParseElement, scriptFieldsParseElement, fieldDataFieldsParseElement);
                }
            } else {
                parseCommonInnerHitOptions(parser, token, fieldName, subSearchContext, sortParseElement, sourceParseElement, highlighterParseElement, scriptFieldsParseElement, fieldDataFieldsParseElement);
            }
        }
    } catch (Exception e) {
        throw new QueryParsingException(parserContext, "Failed to parse [_inner_hits]", e);
    }
    return new InnerHitsSubSearchContext(innerHitName, subSearchContext);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:26,代碼來源:InnerHitsQueryParserHelper.java

示例5: testFailWithSubAgg

import org.elasticsearch.index.query.QueryParseContext; //導入依賴的package包/類
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"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:27,代碼來源:TopHitsTests.java

示例6: testTwoAggs

import org.elasticsearch.index.query.QueryParseContext; //導入依賴的package包/類
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("aggs") // 2nd "aggs": illegal
                        .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]"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:33,代碼來源:AggregatorFactoriesTests.java

示例7: testParseJson_simple

import org.elasticsearch.index.query.QueryParseContext; //導入依賴的package包/類
public void testParseJson_simple() throws IOException {
    String scriptSort = "{\n" +
            "\"_script\" : {\n" +
            "\"type\" : \"number\",\n" +
            "\"script\" : \"doc['field_name'].value\",\n" +
            "\"mode\" : \"max\",\n" +
            "\"order\" : \"asc\"\n" +
            "} }\n";
    XContentParser parser = createParser(JsonXContent.jsonXContent, scriptSort);
    parser.nextToken();
    parser.nextToken();
    parser.nextToken();

    QueryParseContext context = new QueryParseContext(parser);
    ScriptSortBuilder builder = ScriptSortBuilder.fromXContent(context, null);
    assertEquals("doc['field_name'].value", builder.script().getIdOrCode());
    assertEquals(Script.DEFAULT_SCRIPT_LANG, builder.script().getLang());
    assertEquals(builder.script().getParams(), Collections.emptyMap());
    assertEquals(ScriptType.INLINE, builder.script().getType());
    assertEquals(ScriptSortType.NUMBER, builder.type());
    assertEquals(SortOrder.ASC, builder.order());
    assertEquals(SortMode.MAX, builder.sortMode());
    assertNull(builder.getNestedFilter());
    assertNull(builder.getNestedPath());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:26,代碼來源:ScriptSortBuilderTests.java

示例8: testMissingType

import org.elasticsearch.index.query.QueryParseContext; //導入依賴的package包/類
public void testMissingType() throws Exception {
    XContentBuilder source = JsonXContent.contentBuilder()
            .startObject()
                .startObject("by_date")
                    .startObject("date_histogram")
                        .field("field", "timestamp")
                        .field("interval", "month")
                    .endObject()
                    .startObject("aggs")
                        .startObject("tag_count")
                            // the aggregation type is missing
                            //.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("Expected [START_OBJECT] under [field], but got a [VALUE_STRING] in [tag_count]"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:AggregatorFactoriesTests.java

示例9: testMissingName

import org.elasticsearch.index.query.QueryParseContext; //導入依賴的package包/類
public void testMissingName() throws Exception {
    XContentBuilder source = JsonXContent.contentBuilder()
            .startObject()
                .startObject("by_date")
                    .startObject("date_histogram")
                        .field("field", "timestamp")
                        .field("interval", "month")
                    .endObject()
                    .startObject("aggs")
                        // the aggregation name is missing
                        //.startObject("tag_count")
                        .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("Expected [START_OBJECT] under [field], but got a [VALUE_STRING] in [cardinality]"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:AggregatorFactoriesTests.java

示例10: testSameAggregationName

import org.elasticsearch.index.query.QueryParseContext; //導入依賴的package包/類
public void testSameAggregationName() throws Exception {
    assumeFalse("Test only makes sense if XContent parser doesn't have strict duplicate checks enabled",
        XContent.isStrictDuplicateDetectionEnabled());
    final String name = randomAsciiOfLengthBetween(1, 10);
    XContentBuilder source = JsonXContent.contentBuilder()
            .startObject()
                .startObject(name)
                    .startObject("terms")
                        .field("field", "a")
                    .endObject()
                .endObject()
                .startObject(name)
                    .startObject("terms")
                        .field("field", "b")
                    .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("Two sibling aggregations cannot have the same name: [" + name + "]"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:AggregatorFactoriesTests.java

示例11: parseOrder

import org.elasticsearch.index.query.QueryParseContext; //導入依賴的package包/類
private static InternalOrder parseOrder(XContentParser parser, QueryParseContext context) throws IOException {
    InternalOrder order = null;
    Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_STRING) {
            String dir = parser.text();
            boolean asc = "asc".equals(dir);
            if (!asc && !"desc".equals(dir)) {
                throw new ParsingException(parser.getTokenLocation(), "Unknown order direction: [" + dir
                        + "]. Should be either [asc] or [desc]");
            }
            order = resolveOrder(currentFieldName, asc);
        }
    }
    return order;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:HistogramAggregationBuilder.java

示例12: testSortModeSumIsRejectedInJSON

import org.elasticsearch.index.query.QueryParseContext; //導入依賴的package包/類
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());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:GeoDistanceSortBuilderTests.java

示例13: fromXContent

import org.elasticsearch.index.query.QueryParseContext; //導入依賴的package包/類
public static StoredFieldsContext fromXContent(String fieldName, QueryParseContext context) throws IOException {
    XContentParser parser = context.parser();
    XContentParser.Token token = parser.currentToken();

    if (token == XContentParser.Token.VALUE_STRING) {
        return fromList(Collections.singletonList(parser.text()));
    } else if (token == XContentParser.Token.START_ARRAY) {
        ArrayList<String> list = new ArrayList<>();
        while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
            list.add(parser.text());
        }
        return fromList(list);
    } else {
        throw new ParsingException(parser.getTokenLocation(),
            "Expected [" + XContentParser.Token.VALUE_STRING + "] or ["
                + XContentParser.Token.START_ARRAY + "] in [" + fieldName + "] but found [" + token + "]",
            parser.getTokenLocation());
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:StoredFieldsContext.java

示例14: parseCompoundSortField

import org.elasticsearch.index.query.QueryParseContext; //導入依賴的package包/類
private static void parseCompoundSortField(QueryParseContext context, List<SortBuilder<?>> sortFields)
        throws IOException {
    XContentParser.Token token;
    XContentParser parser = context.parser();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            String fieldName = parser.currentName();
            token = parser.nextToken();
            if (token == XContentParser.Token.VALUE_STRING) {
                SortOrder order = SortOrder.fromString(parser.text());
                sortFields.add(fieldOrScoreSort(fieldName).order(order));
            } else {
                if (PARSERS.containsKey(fieldName)) {
                    sortFields.add(PARSERS.get(fieldName).fromXContent(context, fieldName));
                } else {
                    sortFields.add(FieldSortBuilder.fromXContent(context, fieldName));
                }
            }
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:SortBuilder.java

示例15: testTwoTypes

import org.elasticsearch.index.query.QueryParseContext; //導入依賴的package包/類
public void testTwoTypes() throws Exception {
    XContentBuilder source = JsonXContent.contentBuilder()
            .startObject()
                .startObject("in_stock")
                    .startObject("filter")
                        .startObject("range")
                            .startObject("stock")
                                .field("gt", 0)
                            .endObject()
                        .endObject()
                    .endObject()
                    .startObject("terms")
                        .field("field", "stock")
                    .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 aggregation type definitions in [in_stock]: [filter] and [terms]"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:AggregatorFactoriesTests.java


注:本文中的org.elasticsearch.index.query.QueryParseContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。