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


Java JsonXContent.contentBuilder方法代碼示例

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


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

示例1: sendResponse

import org.elasticsearch.common.xcontent.json.JsonXContent; //導入方法依賴的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: testToQueryRegExpQueryMaxDeterminizedStatesParsing

import org.elasticsearch.common.xcontent.json.JsonXContent; //導入方法依賴的package包/類
/**
 * Validates that {@code max_determinized_states} can be parsed and lowers the allowed number of determinized states.
 */
public void testToQueryRegExpQueryMaxDeterminizedStatesParsing() throws Exception {
    assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
    XContentBuilder builder = JsonXContent.contentBuilder();
    builder.startObject(); {
        builder.startObject("query_string"); {
            builder.field("query", "/[ac]*a[ac]{1,10}/");
            builder.field("default_field", STRING_FIELD_NAME);
            builder.field("max_determinized_states", 10);
        }
        builder.endObject();
    }
    builder.endObject();

    QueryBuilder queryBuilder = new QueryParseContext(createParser(builder)).parseInnerQueryBuilder();
    TooComplexToDeterminizeException e = expectThrows(TooComplexToDeterminizeException.class,
            () -> queryBuilder.toQuery(createShardContext()));
    assertThat(e.getMessage(), containsString("Determinizing [ac]*"));
    assertThat(e.getMessage(), containsString("would result in more than 10 states"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:QueryStringQueryBuilderTests.java

示例3: testMatchTypeOnly

import org.elasticsearch.common.xcontent.json.JsonXContent; //導入方法依賴的package包/類
public void testMatchTypeOnly() throws Exception {
    XContentBuilder builder = JsonXContent.contentBuilder();
    builder.startObject().startObject("person").startArray("dynamic_templates").startObject().startObject("test")
            .field("match_mapping_type", "string")
            .startObject("mapping").field("index", false).endObject()
            .endObject().endObject().endArray().endObject().endObject();
    IndexService index = createIndex("test");
    client().admin().indices().preparePutMapping("test").setType("person").setSource(builder).get();
    DocumentMapper docMapper = index.mapperService().documentMapper("person");
    builder = JsonXContent.contentBuilder();
    builder.startObject().field("s", "hello").field("l", 1).endObject();
    ParsedDocument parsedDoc = docMapper.parse("test", "person", "1", builder.bytes());
    client().admin().indices().preparePutMapping("test").setType("person")
        .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();

    docMapper = index.mapperService().documentMapper("person");
    DocumentFieldMappers mappers = docMapper.mappers();

    assertThat(mappers.smartNameFieldMapper("s"), Matchers.notNullValue());
    assertEquals(IndexOptions.NONE, mappers.smartNameFieldMapper("s").fieldType().indexOptions());

    assertThat(mappers.smartNameFieldMapper("l"), Matchers.notNullValue());
    assertNotSame(IndexOptions.NONE, mappers.smartNameFieldMapper("l").fieldType().indexOptions());


}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:27,代碼來源:DynamicTemplatesTests.java

示例4: arrayLatLon

import org.elasticsearch.common.xcontent.json.JsonXContent; //導入方法依賴的package包/類
private XContentParser arrayLatLon(double lat, double lon) throws IOException {
    XContentBuilder content = JsonXContent.contentBuilder();
    content.startArray().value(lon).value(lat).endArray();
    XContentParser parser = createParser(JsonXContent.jsonXContent, content.bytes());
    parser.nextToken();
    return parser;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:8,代碼來源:GeoPointParsingTests.java

示例5: geohash

import org.elasticsearch.common.xcontent.json.JsonXContent; //導入方法依賴的package包/類
private XContentParser geohash(double lat, double lon) throws IOException {
    XContentBuilder content = JsonXContent.contentBuilder();
    content.value(stringEncode(lon, lat));
    XContentParser parser = createParser(JsonXContent.jsonXContent, content.bytes());
    parser.nextToken();
    return parser;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:8,代碼來源:GeoPointParsingTests.java

示例6: testReindexFromRemoteRequestParsing

import org.elasticsearch.common.xcontent.json.JsonXContent; //導入方法依賴的package包/類
public void testReindexFromRemoteRequestParsing() throws IOException {
    BytesReference request;
    try (XContentBuilder b = JsonXContent.contentBuilder()) {
        b.startObject(); {
            b.startObject("source"); {
                b.startObject("remote"); {
                    b.field("host", "http://localhost:9200");
                }
                b.endObject();
                b.field("index", "source");
            }
            b.endObject();
            b.startObject("dest"); {
                b.field("index", "dest");
            }
            b.endObject();
        }
        b.endObject();
        request = b.bytes();
    }
    try (XContentParser p = createParser(JsonXContent.jsonXContent, request)) {
        ReindexRequest r = new ReindexRequest(new SearchRequest(), new IndexRequest());
        RestReindexAction.PARSER.parse(p, r, null);
        assertEquals("localhost", r.getRemoteInfo().getHost());
        assertArrayEquals(new String[] {"source"}, r.getSearchRequest().indices());
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:28,代碼來源:RestReindexActionTests.java

示例7: testXContentRepresentationOfUnfinishedSlices

import org.elasticsearch.common.xcontent.json.JsonXContent; //導入方法依賴的package包/類
public void testXContentRepresentationOfUnfinishedSlices() throws IOException {
    XContentBuilder builder = JsonXContent.contentBuilder();
    BulkByScrollTask.Status completedStatus = new BulkByScrollTask.Status(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, timeValueMillis(0),
            Float.POSITIVE_INFINITY, null, timeValueMillis(0));
    BulkByScrollTask.Status status = new BulkByScrollTask.Status(
            Arrays.asList(null, null, new BulkByScrollTask.StatusOrException(completedStatus)), null);
    status.toXContent(builder, ToXContent.EMPTY_PARAMS);
    assertThat(builder.string(), containsString("\"slices\":[null,null,{\"slice_id\":2"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:10,代碼來源:BulkByScrollTaskTests.java

示例8: toString

import org.elasticsearch.common.xcontent.json.JsonXContent; //導入方法依賴的package包/類
@Override
public String toString() {
    try {
        XContentBuilder xcontent = JsonXContent.contentBuilder();
        return toXContent(xcontent, EMPTY_PARAMS).prettyPrint().string();
    } catch (IOException e) {
        return super.toString();
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:10,代碼來源:ShapeBuilder.java

示例9: declareRawObject

import org.elasticsearch.common.xcontent.json.JsonXContent; //導入方法依賴的package包/類
public void declareRawObject(BiConsumer<Value, BytesReference> consumer, ParseField field) {
    CheckedFunction<XContentParser, BytesReference, IOException> bytesParser = p -> {
        try (XContentBuilder builder = JsonXContent.contentBuilder()) {
            builder.prettyPrint();
            builder.copyCurrentStructure(p);
            return builder.bytes();
        }
    };
    declareField(consumer, bytesParser, field, ValueType.OBJECT);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:11,代碼來源:AbstractObjectParser.java

示例10: objectLatLon

import org.elasticsearch.common.xcontent.json.JsonXContent; //導入方法依賴的package包/類
private XContentParser objectLatLon(double lat, double lon) throws IOException {
    XContentBuilder content = JsonXContent.contentBuilder();
    content.startObject();
    content.field("lat", lat).field("lon", lon);
    content.endObject();
    XContentParser parser = createParser(JsonXContent.jsonXContent, content.bytes());
    parser.nextToken();
    return parser;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:10,代碼來源:GeoPointParsingTests.java

示例11: testXContent

import org.elasticsearch.common.xcontent.json.JsonXContent; //導入方法依賴的package包/類
public void testXContent() throws IOException {
    RepositoryData repositoryData = generateRandomRepoData();
    XContentBuilder builder = JsonXContent.contentBuilder();
    repositoryData.snapshotsToXContent(builder, ToXContent.EMPTY_PARAMS);
    XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
    long gen = (long) randomIntBetween(0, 500);
    RepositoryData fromXContent = RepositoryData.snapshotsFromXContent(parser, gen);
    assertEquals(repositoryData, fromXContent);
    assertEquals(gen, fromXContent.getGenId());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:11,代碼來源:RepositoryDataTests.java

示例12: toString

import org.elasticsearch.common.xcontent.json.JsonXContent; //導入方法依賴的package包/類
/**
 * Return a {@link String} that is the json representation of the provided
 * {@link ToXContent}.
 */
public static String toString(ToXContent toXContent) {
    try {
        XContentBuilder builder = JsonXContent.contentBuilder();
        toXContent.toXContent(builder, ToXContent.EMPTY_PARAMS);
        return builder.string();
    } catch (IOException e) {
        throw new AssertionError("Cannot happen", e);
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:14,代碼來源:Strings.java

示例13: testInvalidPointLonHashMix

import org.elasticsearch.common.xcontent.json.JsonXContent; //導入方法依賴的package包/類
public void testInvalidPointLonHashMix() throws IOException {
    XContentBuilder content = JsonXContent.contentBuilder();
    content.startObject();
    content.field("lon", 0).field("geohash", stringEncode(0d, 0d));
    content.endObject();

    XContentParser parser = createParser(JsonXContent.jsonXContent, content.bytes());
    parser.nextToken();

    Exception e = expectThrows(ElasticsearchParseException.class, () -> GeoUtils.parseGeoPoint(parser));
    assertThat(e.getMessage(), is("field must be either lat/lon or geohash"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:GeoPointParsingTests.java

示例14: testXContentRepresentationOfSliceFailures

import org.elasticsearch.common.xcontent.json.JsonXContent; //導入方法依賴的package包/類
public void testXContentRepresentationOfSliceFailures() throws IOException {
    XContentBuilder builder = JsonXContent.contentBuilder();
    Exception e = new Exception();
    BulkByScrollTask.Status status = new BulkByScrollTask.Status(Arrays.asList(null, null, new BulkByScrollTask.StatusOrException(e)),
            null);
    status.toXContent(builder, ToXContent.EMPTY_PARAMS);
    assertThat(builder.string(), containsString("\"slices\":[null,null,{\"type\":\"exception\""));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:9,代碼來源:BulkByScrollTaskTests.java

示例15: contentBuilder

import org.elasticsearch.common.xcontent.json.JsonXContent; //導入方法依賴的package包/類
/**
 * Returns a binary content builder for the provided content type.
 */
public static XContentBuilder contentBuilder(XContentType type) throws IOException {
    if (type == XContentType.JSON) {
        return JsonXContent.contentBuilder();
    } else if (type == XContentType.SMILE) {
        return SmileXContent.contentBuilder();
    } else if (type == XContentType.YAML) {
        return YamlXContent.contentBuilder();
    } else if (type == XContentType.CBOR) {
        return CborXContent.contentBuilder();
    }
    throw new IllegalArgumentException("No matching content type for " + type);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:16,代碼來源:XContentFactory.java


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