当前位置: 首页>>代码示例>>Java>>正文


Java XContentFactory.contentBuilder方法代码示例

本文整理汇总了Java中org.elasticsearch.common.xcontent.XContentFactory.contentBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java XContentFactory.contentBuilder方法的具体用法?Java XContentFactory.contentBuilder怎么用?Java XContentFactory.contentBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.common.xcontent.XContentFactory的用法示例。


在下文中一共展示了XContentFactory.contentBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testFromXContent

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
/**
 * Test that creates new smoothing model from a random test smoothing model and checks both for equality
 */
public void testFromXContent() throws IOException {
    SmoothingModel testModel = createTestModel();
    XContentBuilder contentBuilder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
    if (randomBoolean()) {
        contentBuilder.prettyPrint();
    }
    contentBuilder.startObject();
    testModel.innerToXContent(contentBuilder, ToXContent.EMPTY_PARAMS);
    contentBuilder.endObject();
    XContentParser parser = createParser(shuffleXContent(contentBuilder));
    parser.nextToken();  // go to start token, real parsing would do that in the outer element parser
    SmoothingModel parsedModel = fromXContent(parser);
    assertNotSame(testModel, parsedModel);
    assertEquals(testModel, parsedModel);
    assertEquals(testModel.hashCode(), parsedModel.hashCode());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:SmoothingModelTestCase.java

示例2: toXContent

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
/**
 * Renders the provided instance in XContent
 *
 * @param instance
 *            the instance to render
 * @param contentType
 *            the content type to render to
 */
protected XContentBuilder toXContent(T instance, XContentType contentType)
        throws IOException {
    XContentBuilder builder = XContentFactory.contentBuilder(contentType);
    if (randomBoolean()) {
        builder.prettyPrint();
    }
    if (instance.isFragment()) {
        builder.startObject();
    }
    instance.toXContent(builder, ToXContent.EMPTY_PARAMS);
    if (instance.isFragment()) {
        builder.endObject();
    }
    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:AbstractSerializingTestCase.java

示例3: testFromXContent

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
/**
 * Test that creates new shape from a random test shape and checks both for equality
 */
public void testFromXContent() throws IOException {
    for (int runs = 0; runs < NUMBER_OF_TESTBUILDERS; runs++) {
        SB testShape = createTestShapeBuilder();
        XContentBuilder contentBuilder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
        if (randomBoolean()) {
            contentBuilder.prettyPrint();
        }
        XContentBuilder builder = testShape.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS);
        XContentBuilder shuffled = shuffleXContent(builder);
        XContentParser shapeParser = createParser(shuffled);
        shapeParser.nextToken();
        ShapeBuilder parsedShape = ShapeBuilder.parse(shapeParser);
        assertNotSame(testShape, parsedShape);
        assertEquals(testShape, parsedShape);
        assertEquals(testShape.hashCode(), parsedShape.hashCode());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:AbstractShapeBuilderTestCase.java

示例4: testFromXContent

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
/**
 *  creates random suggestion builder, 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_RUNS; runs++) {
        SuggestBuilder suggestBuilder = randomSuggestBuilder();
        XContentBuilder xContentBuilder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
        if (randomBoolean()) {
            xContentBuilder.prettyPrint();
        }
        suggestBuilder.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS);
        XContentParser parser = createParser(xContentBuilder);
        SuggestBuilder secondSuggestBuilder = SuggestBuilder.fromXContent(parser);
        assertNotSame(suggestBuilder, secondSuggestBuilder);
        assertEquals(suggestBuilder, secondSuggestBuilder);
        assertEquals(suggestBuilder.hashCode(), secondSuggestBuilder.hashCode());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:SuggestBuilderTests.java

示例5: testFromXContent

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
/**
 *  creates random candidate generator, 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_RUNS; runs++) {
        DirectCandidateGeneratorBuilder generator = randomCandidateGenerator();
        XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
        if (randomBoolean()) {
            builder.prettyPrint();
        }
        generator.toXContent(builder, ToXContent.EMPTY_PARAMS);
        XContentParser parser = createParser(shuffleXContent(builder));
        parser.nextToken();
        DirectCandidateGeneratorBuilder secondGenerator = DirectCandidateGeneratorBuilder.PARSER.apply(parser, null);
        assertNotSame(generator, secondGenerator);
        assertEquals(generator, secondGenerator);
        assertEquals(generator.hashCode(), secondGenerator.hashCode());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:DirectCandidateGeneratorTests.java

示例6: testFromXContent

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的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

示例7: parsePercolatorDocument

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
Query parsePercolatorDocument(String id, BytesReference source) {
    String type = null;
    BytesReference querySource = null;
    try (XContentParser sourceParser = XContentHelper.createParser(source)) {
        String currentFieldName = null;
        XContentParser.Token token = sourceParser.nextToken(); // move the START_OBJECT
        if (token != XContentParser.Token.START_OBJECT) {
            throw new ElasticsearchException("failed to parse query [" + id + "], not starting with OBJECT");
        }
        while ((token = sourceParser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (token == XContentParser.Token.FIELD_NAME) {
                currentFieldName = sourceParser.currentName();
            } else if (token == XContentParser.Token.START_OBJECT) {
                if ("query".equals(currentFieldName)) {
                    if (type != null) {
                        return parseQuery(type, sourceParser);
                    } else {
                        XContentBuilder builder = XContentFactory.contentBuilder(sourceParser.contentType());
                        builder.copyCurrentStructure(sourceParser);
                        querySource = builder.bytes();
                        builder.close();
                    }
                } else {
                    sourceParser.skipChildren();
                }
            } else if (token == XContentParser.Token.START_ARRAY) {
                sourceParser.skipChildren();
            } else if (token.isValue()) {
                if ("type".equals(currentFieldName)) {
                    type = sourceParser.text();
                }
            }
        }
        try (XContentParser queryParser = XContentHelper.createParser(querySource)) {
            return parseQuery(type, queryParser);
        }
    } catch (Exception e) {
        throw new PercolatorException(shardId().index(), "failed to parse query [" + id + "]", e);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:41,代码来源:PercolatorQueriesRegistry.java

示例8: toXContent

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
protected static XContentBuilder toXContent(QueryBuilder query, XContentType contentType) throws IOException {
    XContentBuilder builder = XContentFactory.contentBuilder(contentType);
    if (randomBoolean()) {
        builder.prettyPrint();
    }
    query.toXContent(builder, ToXContent.EMPTY_PARAMS);
    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:AbstractQueryTestCase.java

示例9: shuffleXContent

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
/**
 * Randomly shuffles the fields inside objects parsed using the {@link XContentParser} passed in.
 * Recursively goes through inner objects and also shuffles them. Exceptions for this
 * recursive shuffling behavior can be made by passing in the names of fields which
 * internally should stay untouched.
 */
public XContentBuilder shuffleXContent(XContentParser parser, boolean prettyPrint, String... exceptFieldNames) throws IOException {
    // use ordered maps for reproducibility
    Map<String, Object> shuffledMap = shuffleMap(parser.mapOrdered(), new HashSet<>(Arrays.asList(exceptFieldNames)));
    XContentBuilder xContentBuilder = XContentFactory.contentBuilder(parser.contentType());
    if (prettyPrint) {
        xContentBuilder.prettyPrint();
    }
    return xContentBuilder.map(shuffledMap);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:ESTestCase.java

示例10: toRestRequest

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
private RestRequest toRestRequest(ClusterRerouteRequest original) throws IOException {
    Map<String, String> params = new HashMap<>();
    XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
    boolean hasBody = false;
    if (randomBoolean()) {
        builder.prettyPrint();
    }
    builder.startObject();
    if (randomBoolean()) {
        params.put("dry_run", Boolean.toString(original.dryRun()));
    } else {
        hasBody = true;
        builder.field("dry_run", original.dryRun());
    }
    params.put("explain", Boolean.toString(original.explain()));
    if (false == original.timeout().equals(AcknowledgedRequest.DEFAULT_ACK_TIMEOUT) || randomBoolean()) {
        params.put("timeout", original.timeout().toString());
    }
    if (original.isRetryFailed() || randomBoolean()) {
        params.put("retry_failed", Boolean.toString(original.isRetryFailed()));
    }
    if (false == original.masterNodeTimeout().equals(MasterNodeRequest.DEFAULT_MASTER_NODE_TIMEOUT) || randomBoolean()) {
        params.put("master_timeout", original.masterNodeTimeout().toString());
    }
    if (original.getCommands() != null) {
        hasBody = true;
        original.getCommands().toXContent(builder, ToXContent.EMPTY_PARAMS);
    }
    builder.endObject();

    FakeRestRequest.Builder requestBuilder = new FakeRestRequest.Builder(xContentRegistry());
    requestBuilder.withParams(params);
    if (hasBody) {
        requestBuilder.withContent(builder.bytes(), builder.contentType());
    }
    return requestBuilder.build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:ClusterRerouteRequestTests.java

示例11: transientSettings

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
/**
 * Sets the transient settings to be updated. They will not survive a full cluster restart
 */
@SuppressWarnings("unchecked")
public ClusterUpdateSettingsRequest transientSettings(Map source) {
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.map(source);
        transientSettings(builder.string());
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
    }
    return this;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:15,代码来源:ClusterUpdateSettingsRequest.java

示例12: serialize

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
private Map<String, Object> serialize(ListTasksResponse response, boolean byParents) throws IOException {
    XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
    builder.startObject();
    if (byParents) {
        DiscoveryNodes nodes = testNodes[0].clusterService.state().nodes();
        response.toXContentGroupedByNode(builder, ToXContent.EMPTY_PARAMS, nodes);
    } else {
        response.toXContentGroupedByParents(builder, ToXContent.EMPTY_PARAMS);
    }
    builder.endObject();
    builder.flush();
    logger.info(builder.string());
    return XContentHelper.convertToMap(builder.bytes(), false, builder.contentType()).v2();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:TransportTasksActionTests.java

示例13: settings

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
/**
 * Sets repository-specific restore settings
 * <p>
 * See repository documentation for more information.
 *
 * @param source repository-specific snapshot settings
 * @return this request
 */
public RestoreSnapshotRequest settings(Map<String, Object> source) {
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.map(source);
        settings(builder.string());
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
    }
    return this;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:19,代码来源:RestoreSnapshotRequest.java

示例14: testHandlingOfPath_StringName

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
public void testHandlingOfPath_StringName() throws IOException {
    Path path = PathUtils.get("path");
    String name = new String("file");

    XContentBuilder pathBuilder = XContentFactory.contentBuilder(XContentType.JSON);
    pathBuilder.startObject().field(name, path).endObject();

    XContentBuilder stringBuilder = XContentFactory.contentBuilder(XContentType.JSON);
    stringBuilder.startObject().field(name, path.toString()).endObject();

    assertThat(pathBuilder.string(), equalTo(stringBuilder.string()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:XContentBuilderTests.java

示例15: settings

import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
/**
 * The settings to create the index template with (either json or yaml format).
 */
public PutIndexTemplateRequest settings(Map<String, Object> source) {
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.map(source);
        settings(builder.string(), XContentType.JSON);
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
    }
    return this;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:PutIndexTemplateRequest.java


注:本文中的org.elasticsearch.common.xcontent.XContentFactory.contentBuilder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。