當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。