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


Java XContentBuilder類代碼示例

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


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

示例1: doXContentBody

import org.elasticsearch.common.xcontent.XContentBuilder; //導入依賴的package包/類
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
    if (keyed) {
        builder.startObject(CommonFields.BUCKETS);
    } else {
        builder.startArray(CommonFields.BUCKETS);
    }
    for (B bucket : buckets) {
        bucket.toXContent(builder, params);
    }
    if (keyed) {
        builder.endObject();
    } else {
        builder.endArray();
    }
    return builder;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:18,代碼來源:InternalHistogram.java

示例2: toXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //導入依賴的package包/類
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    if (tokens != null) {
        builder.startArray(Fields.TOKENS);
        for (AnalyzeToken token : tokens) {
            token.toXContent(builder, params);
        }
        builder.endArray();
    }

    if (detail != null) {
        builder.startObject(Fields.DETAIL);
        detail.toXContent(builder, params);
        builder.endObject();
    }
    builder.endObject();
    return builder;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:AnalyzeResponse.java

示例3: createMappinmgWithCopyToInMultiField

import org.elasticsearch.common.xcontent.XContentBuilder; //導入依賴的package包/類
private static XContentBuilder createMappinmgWithCopyToInMultiField() throws IOException {
    XContentBuilder mapping = jsonBuilder();
    mapping.startObject()
        .startObject("type")
        .startObject("properties")
        .startObject("a")
        .field("type", "text")
        .endObject()
        .startObject("b")
        .field("type", "text")
        .startObject("fields")
        .startObject("c")
        .field("type", "text")
        .field("copy_to", "a")
        .endObject()
        .endObject()
        .endObject()
        .endObject()
        .endObject()
        .endObject();
    return mapping;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:MultiFieldCopyToMapperTests.java

示例4: toXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //導入依賴的package包/類
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject(Fields.ROUTING)
            .field(Fields.STATE, shardRouting.state())
            .field(Fields.PRIMARY, shardRouting.primary())
            .field(Fields.NODE, shardRouting.currentNodeId())
            .field(Fields.RELOCATING_NODE, shardRouting.relocatingNodeId())
            .endObject();

    commonStats.toXContent(builder, params);
    if (commitStats != null) {
        commitStats.toXContent(builder, params);
    }
    builder.startObject(Fields.SHARD_PATH);
    builder.field(Fields.STATE_PATH, statePath);
    builder.field(Fields.DATA_PATH, dataPath);
    builder.field(Fields.IS_CUSTOM_DATA_PATH, isCustomDataPath);
    builder.endObject();
    return builder;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:21,代碼來源:ShardStats.java

示例5: testSerializeDefaults

import org.elasticsearch.common.xcontent.XContentBuilder; //導入依賴的package包/類
public void testSerializeDefaults() throws Exception {
    for (String type : TYPES) {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", type).endObject().endObject()
            .endObject().endObject().string();

        DocumentMapper docMapper = parser.parse("type", new CompressedXContent(mapping));
        RangeFieldMapper mapper = (RangeFieldMapper) docMapper.root().getMapper("field");
        XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
        mapper.doXContentBody(builder, true, ToXContent.EMPTY_PARAMS);
        String got = builder.endObject().string();

        // if type is date_range we check that the mapper contains the default format and locale
        // otherwise it should not contain a locale or format
        assertTrue(got, got.contains("\"format\":\"strict_date_optional_time||epoch_millis\"") == type.equals("date_range"));
        assertTrue(got, got.contains("\"locale\":" + "\"" + Locale.ROOT + "\"") == type.equals("date_range"));
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:RangeFieldMapperTests.java

示例6: doInternalXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //導入依賴的package包/類
@Override
protected XContentBuilder doInternalXContent(XContentBuilder builder, Params params) throws IOException {
    // builder.startObject();
    if (shardSize != SamplerParser.DEFAULT_SHARD_SAMPLE_SIZE) {
        builder.field(SamplerParser.SHARD_SIZE_FIELD.getPreferredName(), shardSize);
    }

    if (maxDocsPerValue != SamplerParser.MAX_DOCS_PER_VALUE_DEFAULT) {
        builder.field(SamplerParser.MAX_DOCS_PER_VALUE_FIELD.getPreferredName(), maxDocsPerValue);
    }
    if (executionHint != null) {
        builder.field(SamplerParser.EXECUTION_HINT_FIELD.getPreferredName(), executionHint);
    }

    return builder;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:17,代碼來源:SamplerAggregationBuilder.java

示例7: toXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //導入依賴的package包/類
@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
    builder.startObject(Fields.INDEXING);
    totalStats.toXContent(builder, params);
    if (typeStats != null && !typeStats.isEmpty()) {
        builder.startObject(Fields.TYPES);
        for (Map.Entry<String, Stats> entry : typeStats.entrySet()) {
            builder.startObject(entry.getKey(), XContentBuilder.FieldCaseConversion.NONE);
            entry.getValue().toXContent(builder, params);
            builder.endObject();
        }
        builder.endObject();
    }
    builder.endObject();
    return builder;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:17,代碼來源:IndexingStats.java

示例8: toXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //導入依賴的package包/類
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    builder.field("name", nodeName);
    builder.field("cluster_name", clusterName.value());
    builder.field("cluster_uuid", clusterUuid);
    builder.startObject("version")
        .field("number", version.toString())
        .field("build_hash", build.shortHash())
        .field("build_date", build.date())
        .field("build_snapshot", build.isSnapshot())
        .field("lucene_version", version.luceneVersion.toString())
        .endObject();
    builder.field("tagline", "You Know, for Search");
    builder.endObject();
    return builder;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:MainResponse.java

示例9: testTwoAggs

import org.elasticsearch.common.xcontent.XContentBuilder; //導入依賴的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

示例10: toXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //導入依賴的package包/類
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    builder.startArray(Fields.DOCS);
    for (MultiTermVectorsItemResponse response : responses) {
        if (response.isFailed()) {
            builder.startObject();
            Failure failure = response.getFailure();
            builder.field(Fields._INDEX, failure.getIndex());
            builder.field(Fields._TYPE, failure.getType());
            builder.field(Fields._ID, failure.getId());
            ElasticsearchException.generateFailureXContent(builder, params, failure.getCause(), true);
            builder.endObject();
        } else {
            TermVectorsResponse getResponse = response.getResponse();
            getResponse.toXContent(builder, params);
        }
    }
    builder.endArray();
    builder.endObject();
    return builder;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:MultiTermVectorsResponse.java

示例11: coordinatesToXcontent

import org.elasticsearch.common.xcontent.XContentBuilder; //導入依賴的package包/類
/**
 * builds an array of coordinates to a {@link XContentBuilder}
 * 
 * @param builder builder to use 
 * @param closed repeat the first point at the end of the array if it's not already defines as last element of the array  
 * @return the builder
 */
protected XContentBuilder coordinatesToXcontent(XContentBuilder builder, boolean closed) throws IOException {
    builder.startArray();
    for(Coordinate point : points) {
        toXContent(builder, point);
    }
    if(closed) {
        Coordinate start = points.get(0);
        Coordinate end = points.get(points.size()-1);
        if(start.x != end.x || start.y != end.y) {
            toXContent(builder, points.get(0));
        }
    }
    builder.endArray();
    return builder;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:23,代碼來源:PointCollection.java

示例12: createIndexMapping

import org.elasticsearch.common.xcontent.XContentBuilder; //導入依賴的package包/類
public XContentBuilder createIndexMapping() {

        try {
            XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject(CITY_TYPE)
                    .startObject("properties")

                    // city
                    .startObject("name")
                    .field("type", "string")
                    .endObject()

                    // country
                    .startObject("country")
                    .field("type", "string")
                    .field("index", "not_analyzed")
                    .endObject()

                    .endObject()
                    .endObject().endObject();

            return mapping;
        }
        catch(IOException ioe) {
            throw new TechnicalException(String.format("Error while getting mapping for index [%s/%s]: %s", INDEX, CITY_TYPE, ioe.getMessage()), ioe);
        }
    }
 
開發者ID:duniter-gchange,項目名稱:gchange-pod,代碼行數:27,代碼來源:CitiesLocationDaoImpl.java

示例13: testPipelineQueryParameterIsError

import org.elasticsearch.common.xcontent.XContentBuilder; //導入依賴的package包/類
public void testPipelineQueryParameterIsError() throws IOException {
    RestReindexAction action = new RestReindexAction(Settings.EMPTY, mock(RestController.class));

    FakeRestRequest.Builder request = new FakeRestRequest.Builder(xContentRegistry());
    try (XContentBuilder body = JsonXContent.contentBuilder().prettyPrint()) {
        body.startObject(); {
            body.startObject("source"); {
                body.field("index", "source");
            }
            body.endObject();
            body.startObject("dest"); {
                body.field("index", "dest");
            }
            body.endObject();
        }
        body.endObject();
        request.withContent(body.bytes(), body.contentType());
    }
    request.withParams(singletonMap("pipeline", "doesn't matter"));
    Exception e = expectThrows(IllegalArgumentException.class, () -> action.buildRequest(request.build()));

    assertEquals("_reindex doesn't support [pipeline] as a query parmaeter. Specify it in the [dest] object instead.", e.getMessage());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:RestReindexActionTests.java

示例14: prepareRequest

import org.elasticsearch.common.xcontent.XContentBuilder; //導入依賴的package包/類
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    ForceMergeRequest mergeRequest = new ForceMergeRequest(Strings.splitStringByCommaToArray(request.param("index")));
    mergeRequest.indicesOptions(IndicesOptions.fromRequest(request, mergeRequest.indicesOptions()));
    mergeRequest.maxNumSegments(request.paramAsInt("max_num_segments", mergeRequest.maxNumSegments()));
    mergeRequest.onlyExpungeDeletes(request.paramAsBoolean("only_expunge_deletes", mergeRequest.onlyExpungeDeletes()));
    mergeRequest.flush(request.paramAsBoolean("flush", mergeRequest.flush()));
    return channel -> client.admin().indices().forceMerge(mergeRequest, new RestBuilderListener<ForceMergeResponse>(channel) {
        @Override
        public RestResponse buildResponse(ForceMergeResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            buildBroadcastShardsHeader(builder, request, response);
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:RestForceMergeAction.java

示例15: testConditionsParsing

import org.elasticsearch.common.xcontent.XContentBuilder; //導入依賴的package包/類
public void testConditionsParsing() throws Exception {
    final RolloverRequest request = new RolloverRequest(randomAsciiOfLength(10), randomAsciiOfLength(10));
    final XContentBuilder builder = XContentFactory.jsonBuilder()
        .startObject()
            .startObject("conditions")
                .field("max_age", "10d")
                .field("max_docs", 100)
            .endObject()
        .endObject();
    RolloverRequest.PARSER.parse(createParser(builder), request, null);
    Set<Condition> conditions = request.getConditions();
    assertThat(conditions.size(), equalTo(2));
    for (Condition condition : conditions) {
        if (condition instanceof MaxAgeCondition) {
            MaxAgeCondition maxAgeCondition = (MaxAgeCondition) condition;
            assertThat(maxAgeCondition.value.getMillis(), equalTo(TimeValue.timeValueHours(24 * 10).getMillis()));
        } else if (condition instanceof MaxDocsCondition) {
            MaxDocsCondition maxDocsCondition = (MaxDocsCondition) condition;
            assertThat(maxDocsCondition.value, equalTo(100L));
        } else {
            fail("unexpected condition " + condition);
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:RolloverRequestTests.java


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