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


Java XContentBuilder.bytes方法代码示例

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


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

示例1: randomSource

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
private static BytesReference randomSource() {
    try {
        XContentBuilder xContent = XContentFactory.jsonBuilder();
        xContent.map(RandomDocumentPicks.randomSource(random()));
        return xContent.bytes();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:PercolateQueryBuilderTests.java

示例2: fromXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
/**
 * Parses bodies of the kind
 *
 * <pre>
 * <code>
 * {
 *      "fieldname1" : {
 *          "origin" : "someValue",
 *          "scale" : "someValue"
 *      },
 *      "multi_value_mode" : "min"
 * }
 * </code>
 * </pre>
 */
@Override
public DFB fromXContent(QueryParseContext context) throws IOException, ParsingException {
    XContentParser parser = context.parser();
    String currentFieldName;
    XContentParser.Token token;
    MultiValueMode multiValueMode = DecayFunctionBuilder.DEFAULT_MULTI_VALUE_MODE;
    String fieldName = null;
    BytesReference functionBytes = null;
    while ((token = parser.nextToken()) == XContentParser.Token.FIELD_NAME) {
        currentFieldName = parser.currentName();
        token = parser.nextToken();
        if (token == XContentParser.Token.START_OBJECT) {
            fieldName = currentFieldName;
            XContentBuilder builder = XContentFactory.jsonBuilder();
            builder.copyCurrentStructure(parser);
            functionBytes = builder.bytes();
        } else if (MULTI_VALUE_MODE.match(currentFieldName)) {
            multiValueMode = MultiValueMode.fromString(parser.text());
        } else {
            throw new ParsingException(parser.getTokenLocation(), "malformed score function score parameters.");
        }
    }
    if (fieldName == null || functionBytes == null) {
        throw new ParsingException(parser.getTokenLocation(), "malformed score function score parameters.");
    }
    DFB functionBuilder = createFromBytes.apply(fieldName, functionBytes);
    functionBuilder.setMultiValueMode(multiValueMode);
    return functionBuilder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:45,代码来源:DecayFunctionParser.java

示例3: DecayFunctionBuilder

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
/**
 * Convenience constructor that converts its parameters into json to parse on the data nodes.
 */
protected DecayFunctionBuilder(String fieldName, Object origin, Object scale, Object offset, double decay) {
    if (fieldName == null) {
        throw new IllegalArgumentException("decay function: field name must not be null");
    }
    if (scale == null) {
        throw new IllegalArgumentException("decay function: scale must not be null");
    }
    if (decay <= 0 || decay >= 1.0) {
        throw new IllegalStateException("decay function: decay must be in range 0..1!");
    }
    this.fieldName = fieldName;
    try {
        XContentBuilder builder = XContentFactory.jsonBuilder();
        builder.startObject();
        if (origin != null) {
            builder.field(ORIGIN, origin);
        }
        builder.field(SCALE, scale);
        if (offset != null) {
            builder.field(OFFSET, offset);
        }
        builder.field(DECAY, decay);
        builder.endObject();
        this.functionBytes = builder.bytes();
    } catch (IOException e) {
        throw new IllegalArgumentException("unable to build inner function object",e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:DecayFunctionBuilder.java

示例4: Item

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
/**
 * Constructor for an artificial document request, that is not present in the index.
 *
 * @param index the index to be used for parsing the doc
 * @param type the type to be used for parsing the doc
 * @param doc the document specification
 */
public Item(@Nullable String index, @Nullable String type, XContentBuilder doc) {
    if (doc == null) {
        throw new IllegalArgumentException("Item requires doc to be non-null");
    }
    this.index = index;
    this.type = type;
    this.doc = doc.bytes();
    this.xContentType = doc.contentType();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:MoreLikeThisQueryBuilder.java

示例5: MappingMetaData

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
public MappingMetaData(String type, Map<String, Object> mapping) throws IOException {
    this.type = type;
    XContentBuilder mappingBuilder = XContentFactory.jsonBuilder().map(mapping);
    this.source = new CompressedXContent(mappingBuilder.bytes());
    Map<String, Object> withoutType = mapping;
    if (mapping.size() == 1 && mapping.containsKey(type)) {
        withoutType = (Map<String, Object>) mapping.get(type);
    }
    initMappers(withoutType);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:MappingMetaData.java

示例6: hitExecuteMultiple

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
private FetchSubPhase.HitContext hitExecuteMultiple(XContentBuilder source, boolean fetchSource, String[] includes, String[] excludes) {
    FetchSourceContext fetchSourceContext = new FetchSourceContext(fetchSource, includes, excludes);
    SearchContext searchContext = new FetchSourceSubPhaseTestSearchContext(fetchSourceContext, source == null ? null : source.bytes());
    FetchSubPhase.HitContext hitContext = new FetchSubPhase.HitContext();
    hitContext.reset(new SearchHit(1, null, null, null), null, 1, null);
    FetchSourceSubPhase phase = new FetchSourceSubPhase();
    phase.hitExecute(searchContext, hitContext);
    return hitContext;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:FetchSourceSubPhaseTests.java

示例7: testGetResponse

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
public void testGetResponse() throws Exception {
    final String nodeName = "node1";
    final ClusterName clusterName = new ClusterName("cluster1");
    final String clusterUUID = randomAsciiOfLengthBetween(10, 20);
    final boolean available = randomBoolean();
    final RestStatus expectedStatus = available ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE;
    final Version version = Version.CURRENT;
    final Build build = Build.CURRENT;
    final boolean prettyPrint = randomBoolean();

    final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build, available);
    XContentBuilder builder = JsonXContent.contentBuilder();

    Map<String, String> params = new HashMap<>();
    if (prettyPrint == false) {
        params.put("pretty", String.valueOf(prettyPrint));
    }
    RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withParams(params).build();

    BytesRestResponse response = RestMainAction.convertMainResponse(mainResponse, restRequest, builder);
    assertNotNull(response);
    assertEquals(expectedStatus, response.status());
    assertThat(response.content().length(), greaterThan(0));

    XContentBuilder responseBuilder = JsonXContent.contentBuilder();
    if (prettyPrint) {
        // do this to mimic what the rest layer does
        responseBuilder.prettyPrint().lfAtEnd();
    }
    mainResponse.toXContent(responseBuilder, ToXContent.EMPTY_PARAMS);
    BytesReference xcontentBytes = responseBuilder.bytes();
    assertEquals(xcontentBytes, response.content());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:RestMainActionTests.java

示例8: CrateThrowableRestResponse

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
public CrateThrowableRestResponse(RestChannel channel, Throwable t) throws IOException {
    status = (t instanceof ElasticsearchException) ?
            ((ElasticsearchException) t).status() :
            RestStatus.INTERNAL_SERVER_ERROR;
    if (channel.request().method() == RestRequest.Method.HEAD) {
        this.content = BytesArray.EMPTY;
        this.contentType = BytesRestResponse.TEXT_CONTENT_TYPE;
    } else {
        XContentBuilder builder = convert(channel, t);
        this.content = builder.bytes();
        this.contentType = builder.contentType().restContentType();
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:14,代码来源:CrateThrowableRestResponse.java

示例9: BytesRestResponse

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
public BytesRestResponse(RestChannel channel, RestStatus status, Throwable t) throws IOException {
    this.status = status;
    if (channel.request().method() == RestRequest.Method.HEAD) {
        this.content = BytesArray.EMPTY;
        this.contentType = TEXT_CONTENT_TYPE;
    } else {
        XContentBuilder builder = convert(channel, status, t);
        this.content = builder.bytes();
        this.contentType = builder.contentType().restContentType();
    }
    if (t instanceof ElasticsearchException) {
        copyHeaders(((ElasticsearchException) t));
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:15,代码来源:BytesRestResponse.java

示例10: MappingMetaData

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
public MappingMetaData(String type, Map<String, Object> mapping, long mappingVersion) throws IOException {
    this.type = type;
    this.mappingVersion = mappingVersion;
    XContentBuilder mappingBuilder = XContentFactory.jsonBuilder().map(mapping);
    this.source = new CompressedXContent(mappingBuilder.bytes());
    Map<String, Object> withoutType = mapping;
    if (mapping.size() == 1 && mapping.containsKey(type)) {
        withoutType = (Map<String, Object>) mapping.get(type);
    }
    initMappers(withoutType);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:12,代码来源:MappingMetaData.java

示例11: buildAsBytes

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
/**
 * Returns a {@link org.elasticsearch.common.bytes.BytesReference}
 * containing the {@link ToXContent} output in binary format.
 * Builds the request as the provided <code>contentType</code>
 */
public final BytesReference buildAsBytes(XContentType contentType) {
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(contentType);
        toXContent(builder, ToXContent.EMPTY_PARAMS);
        return builder.bytes();
    } catch (Exception e) {
        throw new ElasticsearchException("Failed to build ToXContent", e);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:15,代码来源:ToXContentToBytes.java

示例12: contexts

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
private CompletionSuggestionBuilder contexts(XContentBuilder contextBuilder) {
    contextBytes = contextBuilder.bytes();
    return this;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:CompletionSuggestionBuilder.java

示例13: setDoc

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
/**
 * Sets the document to be percolated.
 */
public DocBuilder setDoc(XContentBuilder doc) {
    this.doc = doc.bytes();
    return this;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:8,代码来源:PercolateSourceBuilder.java

示例14: source

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
public ValidateQueryRequest source(XContentBuilder builder) {
    this.source = builder.bytes();
    return this;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:5,代码来源:ValidateQueryRequest.java

示例15: testBasicSerialization

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
public void testBasicSerialization() throws Exception {
    ImmutableOpenMap.Builder<String, ImmutableOpenIntMap<List<IndicesShardStoresResponse.StoreStatus>>> indexStoreStatuses = ImmutableOpenMap.builder();
    List<IndicesShardStoresResponse.Failure> failures = new ArrayList<>();
    ImmutableOpenIntMap.Builder<List<IndicesShardStoresResponse.StoreStatus>> storeStatuses = ImmutableOpenIntMap.builder();

    DiscoveryNode node1 = new DiscoveryNode("node1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    DiscoveryNode node2 = new DiscoveryNode("node2", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    List<IndicesShardStoresResponse.StoreStatus> storeStatusList = new ArrayList<>();
    storeStatusList.add(new IndicesShardStoresResponse.StoreStatus(node1, null, IndicesShardStoresResponse.StoreStatus.AllocationStatus.PRIMARY, null));
    storeStatusList.add(new IndicesShardStoresResponse.StoreStatus(node2, UUIDs.randomBase64UUID(), IndicesShardStoresResponse.StoreStatus.AllocationStatus.REPLICA, null));
    storeStatusList.add(new IndicesShardStoresResponse.StoreStatus(node1, UUIDs.randomBase64UUID(), IndicesShardStoresResponse.StoreStatus.AllocationStatus.UNUSED, new IOException("corrupted")));
    storeStatuses.put(0, storeStatusList);
    storeStatuses.put(1, storeStatusList);
    ImmutableOpenIntMap<List<IndicesShardStoresResponse.StoreStatus>> storesMap = storeStatuses.build();
    indexStoreStatuses.put("test", storesMap);
    indexStoreStatuses.put("test2", storesMap);

    failures.add(new IndicesShardStoresResponse.Failure("node1", "test", 3, new NodeDisconnectedException(node1, "")));

    IndicesShardStoresResponse storesResponse = new IndicesShardStoresResponse(indexStoreStatuses.build(), Collections.unmodifiableList(failures));
    XContentBuilder contentBuilder = XContentFactory.jsonBuilder();
    contentBuilder.startObject();
    storesResponse.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS);
    contentBuilder.endObject();
    BytesReference bytes = contentBuilder.bytes();

    try (XContentParser parser = createParser(JsonXContent.jsonXContent, bytes)) {
        Map<String, Object> map = parser.map();
        List failureList = (List) map.get("failures");
        assertThat(failureList.size(), equalTo(1));
        HashMap failureMap = (HashMap) failureList.get(0);
        assertThat(failureMap.containsKey("index"), equalTo(true));
        assertThat(((String) failureMap.get("index")), equalTo("test"));
        assertThat(failureMap.containsKey("shard"), equalTo(true));
        assertThat(((int) failureMap.get("shard")), equalTo(3));
        assertThat(failureMap.containsKey("node"), equalTo(true));
        assertThat(((String) failureMap.get("node")), equalTo("node1"));

        Map<String, Object> indices = (Map<String, Object>) map.get("indices");
        for (String index : new String[] {"test", "test2"}) {
            assertThat(indices.containsKey(index), equalTo(true));
            Map<String, Object> shards = ((Map<String, Object>) ((Map<String, Object>) indices.get(index)).get("shards"));
            assertThat(shards.size(), equalTo(2));
            for (String shardId : shards.keySet()) {
                HashMap shardStoresStatus = (HashMap) shards.get(shardId);
                assertThat(shardStoresStatus.containsKey("stores"), equalTo(true));
                List stores = (ArrayList) shardStoresStatus.get("stores");
                assertThat(stores.size(), equalTo(storeStatusList.size()));
                for (int i = 0; i < stores.size(); i++) {
                    HashMap storeInfo = ((HashMap) stores.get(i));
                    IndicesShardStoresResponse.StoreStatus storeStatus = storeStatusList.get(i);
                    assertThat(((String) storeInfo.get("allocation_id")), equalTo((storeStatus.getAllocationId())));
                    assertThat(storeInfo.containsKey("allocation"), equalTo(true));
                    assertThat(((String) storeInfo.get("allocation")), equalTo(storeStatus.getAllocationStatus().value()));
                    assertThat(storeInfo.containsKey(storeStatus.getNode().getId()), equalTo(true));
                    if (storeStatus.getStoreException() != null) {
                        assertThat(storeInfo.containsKey("store_exception"), equalTo(true));
                    }
                }
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:64,代码来源:IndicesShardStoreResponseTests.java


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