当前位置: 首页>>代码示例>>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;未经允许,请勿转载。