当前位置: 首页>>代码示例>>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;未经允许,请勿转载。