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


Java XContentBuilder.field方法代码示例

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


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

示例1: testEvaluateArrayElementObject

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void testEvaluateArrayElementObject() throws Exception {
    XContentBuilder xContentBuilder = randomXContentBuilder();
    xContentBuilder.startObject();
    xContentBuilder.startObject("field1");
    xContentBuilder.startArray("array1");
    xContentBuilder.startObject();
    xContentBuilder.field("element", "value1");
    xContentBuilder.endObject();
    xContentBuilder.startObject();
    xContentBuilder.field("element", "value2");
    xContentBuilder.endObject();
    xContentBuilder.endArray();
    xContentBuilder.endObject();
    xContentBuilder.endObject();
    ObjectPath objectPath = ObjectPath.createFromXContent(xContentBuilder.contentType().xContent(), xContentBuilder.bytes());
    Object object = objectPath.evaluate("field1.array1.1.element");
    assertThat(object, instanceOf(String.class));
    assertThat(object, equalTo("value2"));
    object = objectPath.evaluate("");
    assertThat(object, notNullValue());
    assertThat(object, instanceOf(Map.class));
    assertThat(((Map<String, Object>)object).containsKey("field1"), equalTo(true));
    object = objectPath.evaluate("field1.array2.1.element");
    assertThat(object, nullValue());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:ObjectPathTests.java

示例2: internalXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@Override
protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {
    if (format != null) {
        builder.field(FORMAT.getPreferredName(), format);
    }
    builder.field(GAP_POLICY.getPreferredName(), gapPolicy.getName());
    model.toXContent(builder, params);
    builder.field(WINDOW.getPreferredName(), window);
    if (predict > 0) {
        builder.field(PREDICT.getPreferredName(), predict);
    }
    if (minimize != null) {
        builder.field(MINIMIZE.getPreferredName(), minimize);
    }
    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:MovAvgPipelineAggregationBuilder.java

示例3: toXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject(getId());
    builder.field("name", getName());
    builder.field("ephemeral_id", getEphemeralId());
    builder.field("transport_address", getAddress().toString());

    builder.startObject("attributes");
    for (Map.Entry<String, String> entry : attributes.entrySet()) {
        builder.field(entry.getKey(), entry.getValue());
    }
    builder.endObject();

    builder.endObject();
    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:DiscoveryNode.java

示例4: internalXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@Override
protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    if (keyedFilters == null && nonKeyedFilters == null) {
        throw new SearchSourceBuilderException("At least one filter must be set on filter aggregation [" + getName() + "]");
    }
    if (keyedFilters != null && nonKeyedFilters != null) {
        throw new SearchSourceBuilderException("Cannot add both keyed and non-keyed filters to filters aggregation");
    }

    if (keyedFilters != null) {
        builder.startObject(FiltersParser.FILTERS_FIELD.getPreferredName());
        for (Map.Entry<String, QueryBuilder> entry : keyedFilters.entrySet()) {
            builder.field(entry.getKey());
            entry.getValue().toXContent(builder, params);
        }
        builder.endObject();
    }
    if (nonKeyedFilters != null) {
        builder.startArray(FiltersParser.FILTERS_FIELD.getPreferredName());
        for (QueryBuilder filterBuilder : nonKeyedFilters) {
            filterBuilder.toXContent(builder, params);
        }
        builder.endArray();

    }
    if (otherBucketKey != null) {
        builder.field(FiltersParser.OTHER_BUCKET_KEY_FIELD.getPreferredName(), otherBucketKey);
    }
    if (otherBucket != null) {
        builder.field(FiltersParser.OTHER_BUCKET_FIELD.getPreferredName(), otherBucket);
    }
    return builder.endObject();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:35,代码来源:FiltersAggregationBuilder.java

示例5: internalXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@Override
protected void internalXContent(XContentBuilder builder, Params params) throws IOException {
    super.internalXContent(builder, params);

    doInternalXContent(builder, params);

    if (method != null) {
        builder.startObject(method.getName());

        if (compression != null) {
            builder.field(AbstractPercentilesParser.COMPRESSION_FIELD.getPreferredName(), compression);
        }

        if (numberOfSignificantValueDigits != null) {
            builder.field(AbstractPercentilesParser.NUMBER_SIGNIFICANT_DIGITS_FIELD.getPreferredName(), numberOfSignificantValueDigits);
        }

        builder.endObject();
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:21,代码来源:AbstractPercentilesBuilder.java

示例6: toXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    builder.field(TOOK, tookInMillis);
    if (ingestTookInMillis != BulkResponse.NO_INGEST_TOOK) {
        builder.field(INGEST_TOOK, ingestTookInMillis);
    }
    builder.field(ERRORS, hasFailures());
    builder.startArray(ITEMS);
    for (BulkItemResponse item : this) {
        item.toXContent(builder, params);
    }
    builder.endArray();
    builder.endObject();
    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:BulkResponse.java

示例7: toXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject()
        .field("state", state())
        .field("primary", primary())
        .field("node", currentNodeId())
        .field("relocating_node", relocatingNodeId())
        .field("shard", id())
        .field("index", getIndexName());
    if (expectedShardSize != UNAVAILABLE_EXPECTED_SHARD_SIZE) {
        builder.field("expected_shard_size_in_bytes", expectedShardSize);
    }
    if (recoverySource != null) {
        builder.field("recovery_source", recoverySource);
    }
    if (allocationId != null) {
        builder.field("allocation_id");
        allocationId.toXContent(builder, params);
    }
    if (unassignedInfo != null) {
        unassignedInfo.toXContent(builder, params);
    }
    return builder.endObject();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:ShardRouting.java

示例8: toXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    if (path != Defaults.PATH) {
        builder.startObject(CONTENT_TYPE);
        builder.field("path", path);
        builder.field("version_type", versionType);
        builder.endObject();
    }
    return builder;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:11,代码来源:VersionFieldMapper.java

示例9: testContextPrefix

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
public void testContextPrefix() throws Exception {
    LinkedHashMap<String, ContextMapping> map = new LinkedHashMap<>();
    map.put("cat", ContextBuilder.category("cat").field("cat").build());
    boolean addAnotherContext = randomBoolean();
    if (addAnotherContext) {
        map.put("type", ContextBuilder.category("type").field("type").build());
    }
    final CompletionMappingBuilder mapping = new CompletionMappingBuilder().context(map);
    createIndexAndMapping(mapping);
    int numDocs = 10;
    List<IndexRequestBuilder> indexRequestBuilders = new ArrayList<>();
    for (int i = 0; i < numDocs; i++) {
        XContentBuilder source = jsonBuilder()
                .startObject()
                .startObject(FIELD)
                .field("input", "suggestion" + i)
                .field("weight", i + 1)
                .endObject()
                .field("cat", "cat" + i % 2);
                if (addAnotherContext) {
                    source.field("type", "type" + i % 3);
                }
                source.endObject();
        indexRequestBuilders.add(client().prepareIndex(INDEX, TYPE, "" + i)
                .setSource(source));
    }
    indexRandom(true, indexRequestBuilders);
    CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
    assertSuggestions("foo", prefix, "suggestion9", "suggestion8", "suggestion7", "suggestion6", "suggestion5");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:ContextCompletionSuggestSearchIT.java

示例10: toXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    if (from != null) {
        builder.field("from", from.doubleValue());
    }
    if (to != null) {
        builder.field("to", to.doubleValue());
    }
    if (key != null) {
        builder.field("key", key);
    }
    return builder.endObject();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:15,代码来源:GeoDistanceBuilder.java

示例11: toXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject(Fields.FS);
    builder.field(Fields.TIMESTAMP, timestamp);
    builder.field(Fields.TOTAL);
    total().toXContent(builder, params);
    builder.startArray(Fields.DATA);
    for (Path path : paths) {
        path.toXContent(builder, params);
    }
    builder.endArray();
    builder.endObject();
    return builder;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:15,代码来源:FsInfo.java

示例12: doXContentBody

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
    builder.field(CommonFields.VALUE, count != 0 ? getValue() : null);
    if (count != 0 && format != DocValueFormat.RAW) {
        builder.field(CommonFields.VALUE_AS_STRING, format.format(getValue()));
    }
    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:InternalAvg.java

示例13: testParseRemove

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
public void testParseRemove() throws IOException {
    String[] indices = generateRandomStringArray(10, 5, false, false);
    String[] aliases = generateRandomStringArray(10, 5, false, false);
    XContentBuilder b = XContentBuilder.builder(randomFrom(XContentType.values()).xContent());
    b.startObject(); {
        b.startObject("remove"); {
            if (indices.length > 1 || randomBoolean()) {
                b.array("indices", indices);
            } else {
                b.field("index", indices[0]);
            }
            if (aliases.length > 1 || randomBoolean()) {
                b.array("aliases", aliases);
            } else {
                b.field("alias", aliases[0]);
            }
        }
        b.endObject();
    }
    b.endObject();
    b = shuffleXContent(b);
    try (XContentParser parser = createParser(b)) {
        AliasActions action = AliasActions.PARSER.apply(parser, null);
        assertEquals(AliasActions.Type.REMOVE, action.actionType());
        assertThat(action.indices(), equalTo(indices));
        assertThat(action.aliases(), equalTo(aliases));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:AliasActionsTests.java

示例14: toXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject(Fields.FS);
    builder.field(Fields.TIMESTAMP, timestamp);
    builder.field(Fields.TOTAL);
    total().toXContent(builder, params);
    if (leastDiskEstimate != null) {
        builder.startObject(Fields.LEAST_ESTIMATE);
        {
            builder.field(Fields.PATH, leastDiskEstimate.getPath());
            builder.byteSizeField(Fields.TOTAL_IN_BYTES, Fields.TOTAL, leastDiskEstimate.getTotalBytes());
            builder.byteSizeField(Fields.AVAILABLE_IN_BYTES, Fields.AVAILABLE, leastDiskEstimate.getFreeBytes());
            builder.field(Fields.USAGE_PERCENTAGE, leastDiskEstimate.getUsedDiskAsPercentage());
        }
        builder.endObject();
    }

    if (mostDiskEstimate != null) {
        builder.startObject(Fields.MOST_ESTIMATE);
        {
            builder.field(Fields.PATH, mostDiskEstimate.getPath());
            builder.byteSizeField(Fields.TOTAL_IN_BYTES, Fields.TOTAL, mostDiskEstimate.getTotalBytes());
            builder.byteSizeField(Fields.AVAILABLE_IN_BYTES, Fields.AVAILABLE, mostDiskEstimate.getFreeBytes());
            builder.field(Fields.USAGE_PERCENTAGE, mostDiskEstimate.getUsedDiskAsPercentage());
        }
        builder.endObject();
    }
    builder.startArray(Fields.DATA);
    for (Path path : paths) {
        path.toXContent(builder, params);
    }
    builder.endArray();
    if (ioStats != null) {
        builder.startObject(Fields.IO_STATS);
        ioStats.toXContent(builder, params);
        builder.endObject();
    }
    builder.endObject();
    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:FsInfo.java

示例15: toXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.field(SHARD_FIELD, shardId());
    builder.field(INDEX_FIELD, index());
    if (shardTarget != null) {
        builder.field(NODE_FIELD, shardTarget.getNodeId());
    }
    if (cause != null) {
        builder.field(REASON_FIELD);
        builder.startObject();
        ElasticsearchException.generateThrowableXContent(builder, params, cause);
        builder.endObject();
    }
    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:ShardSearchFailure.java


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