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


Java XContentBuilder.prettyPrint方法代码示例

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


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

示例1: sendResponse

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
protected void sendResponse(final RestChannel channel, final Map<String, Object> params, final boolean pretty) {
    try {
        final XContentBuilder builder = JsonXContent.contentBuilder();
        if (pretty) {
            builder.prettyPrint();
        }
        builder.startObject();
        builder.field("acknowledged", true);
        if (params != null) {
            for (final Map.Entry<String, Object> entry : params.entrySet()) {
                builder.field(entry.getKey(), entry.getValue());
            }
        }
        builder.endObject();
        channel.sendResponse(new BytesRestResponse(OK, builder));
    } catch (final IOException e) {
        throw new ElasticsearchException("Failed to create a resposne.", e);
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-indexing-proxy,代码行数:20,代码来源:RestIndexingProxyProcessAction.java

示例2: testFromXContent

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

示例3: testFromAndToXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
public void testFromAndToXContent() throws Exception {
    for (int runs = 0; runs < NUMBER_OF_TESTBUILDERS; runs++) {
        InnerHitBuilder innerHit = randomInnerHits(true, false);
        XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
        innerHit.toXContent(builder, ToXContent.EMPTY_PARAMS);
        XContentBuilder shuffled = shuffleXContent(builder);
        if (randomBoolean()) {
            shuffled.prettyPrint();
        }

        XContentParser parser = createParser(shuffled);
        QueryParseContext context = new QueryParseContext(parser);
        InnerHitBuilder secondInnerHits = InnerHitBuilder.fromXContent(context);
        assertThat(innerHit, not(sameInstance(secondInnerHits)));
        assertThat(innerHit, equalTo(secondInnerHits));
        assertThat(innerHit.hashCode(), equalTo(secondInnerHits.hashCode()));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:InnerHitBuilderTests.java

示例4: testFromXContent

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

示例5: testFromXContent

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

示例6: testFromXContent

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

示例7: testFromXContent

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

示例8: testFromXContent

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

示例9: restContentBuilder

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
public static XContentBuilder restContentBuilder(RestRequest request)  
        throws IOException {
    XContentType contentType = XContentType  
            .fromRestContentType(request.header("Content-Type"));  
    if (contentType == null) {  
        // try and guess it from the body, if exists  
        if (request.hasContent()) {  
            contentType = XContentFactory.xContentType(request.content());  
        }  
    }  
    if (contentType == null) {  
        // default to JSON  
        contentType = XContentType.JSON;  
    }  
    BytesStreamOutput out = new BytesStreamOutput();  
    XContentBuilder builder = new XContentBuilder(  
            XContentFactory.xContent(contentType), out);  
  
    if (request.paramAsBoolean("pretty", false)) {  
        builder.prettyPrint();  
    }  
    String casing = request.param("case");  
    if (casing != null && "camelCase".equals(casing)) {  
        builder.fieldCaseConversion(  
                XContentBuilder.FieldCaseConversion.CAMELCASE);  
    } else {  
        builder.fieldCaseConversion(  
                XContentBuilder.FieldCaseConversion.NONE);  
    }  
    return builder;  
}
 
开发者ID:ghostboyzone,项目名称:ESAuthPlugin,代码行数:32,代码来源:ContentBuilder.java

示例10: toXContent

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

示例11: testFromXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
public void testFromXContent() throws IOException {
    NestedIdentity nestedIdentity = createTestItem(randomInt(3));
    XContentType xcontentType = randomFrom(XContentType.values());
    XContentBuilder builder = XContentFactory.contentBuilder(xcontentType);
    if (randomBoolean()) {
        builder.prettyPrint();
    }
    builder = nestedIdentity.innerToXContent(builder, ToXContent.EMPTY_PARAMS);
    XContentParser parser = createParser(builder);
    NestedIdentity parsedNestedIdentity = NestedIdentity.fromXContent(parser);
    assertEquals(nestedIdentity, parsedNestedIdentity);
    assertNull(parser.nextToken());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:NestedIdentityTests.java

示例12: testFromXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
/**
 * Test that creates new sort from a random test sort and checks both for equality
 */
public void testFromXContent() throws IOException {
    for (int runs = 0; runs < NUMBER_OF_TESTBUILDERS; runs++) {
        T testItem = createTestItem();

        XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
        if (randomBoolean()) {
            builder.prettyPrint();
        }
        testItem.toXContent(builder, ToXContent.EMPTY_PARAMS);
        XContentBuilder shuffled = shuffleXContent(builder);
        XContentParser itemParser = createParser(shuffled);
        itemParser.nextToken();

        /*
         * filter out name of sort, or field name to sort on for element fieldSort
         */
        itemParser.nextToken();
        String elementName = itemParser.currentName();
        itemParser.nextToken();

        QueryParseContext context = new QueryParseContext(itemParser);
        T parsedItem = fromXContent(context, elementName);
        assertNotSame(testItem, parsedItem);
        assertEquals(testItem, parsedItem);
        assertEquals(testItem.hashCode(), parsedItem.hashCode());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:AbstractSortTestCase.java

示例13: toXContent

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

示例14: toString

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@Override
public String toString() {
    try {
        XContentBuilder builder = XContentFactory.jsonBuilder();
        builder.prettyPrint();
        toXContent(builder, EMPTY_PARAMS);
        return builder.string();
    } catch (Exception e) {
        throw new ElasticsearchException("Failed to build xcontent.", e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:SearchAfterBuilder.java

示例15: toString

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@Override
public String toString() {
    try {
        XContentBuilder builder = XContentFactory.jsonBuilder();
        builder.prettyPrint();
        toXContent(builder, EMPTY_PARAMS);
        return builder.string();
    } catch (Exception e) {
        throw new ElasticsearchException("Failed to build query", e);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:12,代码来源:SortBuilder.java


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