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


Java XContentBuilder.map方法代码示例

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


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

示例1: internalXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@Override
protected XContentBuilder internalXContent(XContentBuilder builder, Params builderParams) throws IOException {
    builder.startObject();
    if (initScript != null) {
        builder.field(INIT_SCRIPT_FIELD.getPreferredName(), initScript);
    }

    if (mapScript != null) {
        builder.field(MAP_SCRIPT_FIELD.getPreferredName(), mapScript);
    }

    if (combineScript != null) {
        builder.field(COMBINE_SCRIPT_FIELD.getPreferredName(), combineScript);
    }

    if (reduceScript != null) {
        builder.field(REDUCE_SCRIPT_FIELD.getPreferredName(), reduceScript);
    }
    if (params != null) {
        builder.field(PARAMS_FIELD.getPreferredName());
        builder.map(params);
    }
    builder.endObject();
    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:ScriptedMetricAggregationBuilder.java

示例2: testDateTypesConversion

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
public void testDateTypesConversion() throws Exception {
    Date date = new Date();
    String expectedDate = XContentBuilder.DEFAULT_DATE_PRINTER.print(date.getTime());
    Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"), Locale.ROOT);
    String expectedCalendar = XContentBuilder.DEFAULT_DATE_PRINTER.print(calendar.getTimeInMillis());
    XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
    builder.startObject().field("date", date).endObject();
    assertThat(builder.string(), equalTo("{\"date\":\"" + expectedDate + "\"}"));

    builder = XContentFactory.contentBuilder(XContentType.JSON);
    builder.startObject().field("calendar", calendar).endObject();
    assertThat(builder.string(), equalTo("{\"calendar\":\"" + expectedCalendar + "\"}"));

    builder = XContentFactory.contentBuilder(XContentType.JSON);
    Map<String, Object> map = new HashMap<>();
    map.put("date", date);
    builder.map(map);
    assertThat(builder.string(), equalTo("{\"date\":\"" + expectedDate + "\"}"));

    builder = XContentFactory.contentBuilder(XContentType.JSON);
    map = new HashMap<>();
    map.put("calendar", calendar);
    builder.map(map);
    assertThat(builder.string(), equalTo("{\"calendar\":\"" + expectedCalendar + "\"}"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:XContentBuilderTests.java

示例3: internalXContent

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

    if (initScript != null) {
        builder.field(ScriptedMetricParser.INIT_SCRIPT_FIELD.getPreferredName(), initScript);
    }

    if (mapScript != null) {
        builder.field(ScriptedMetricParser.MAP_SCRIPT_FIELD.getPreferredName(), mapScript);
    }

    if (combineScript != null) {
        builder.field(ScriptedMetricParser.COMBINE_SCRIPT_FIELD.getPreferredName(), combineScript);
    }

    if (reduceScript != null) {
        builder.field(ScriptedMetricParser.REDUCE_SCRIPT_FIELD.getPreferredName(), reduceScript);
    }
    if (params != null) {
        builder.field(ScriptedMetricParser.PARAMS_FIELD.getPreferredName());
        builder.map(params);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:ScriptedMetricBuilder.java

示例4: toXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
public static void toXContent(Entry entry, XContentBuilder builder, ToXContent.Params params) throws IOException {
    boolean binary = params.paramAsBoolean("binary", false);
    builder.startObject(entry.name(), XContentBuilder.FieldCaseConversion.NONE);
    builder.field("types", entry.types());
    if (entry.requestCache() != null) {
        builder.field("requestCache", entry.requestCache());
    }
    builder.field("source");
    if (binary) {
        builder.value(entry.source());
    } else {
        Map<String, Object> mapping;
        try (XContentParser parser = XContentFactory.xContent(entry.source()).createParser(entry.source())) {
            mapping = parser.mapOrdered();
        }
        builder.map(mapping);
    }
    builder.endObject();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:20,代码来源:IndexWarmersMetaData.java

示例5: 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

示例6: settings

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
/**
 * Sets the settings to be updated (either json/yaml/properties format)
 */
@SuppressWarnings("unchecked")
public UpdateSettingsRequest settings(Map source) {
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.map(source);
        settings(builder.string());
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
    }
    return this;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:15,代码来源:UpdateSettingsRequest.java

示例7: testShuffleXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
public void testShuffleXContent() throws IOException {
    Map<String, Object> randomStringObjectMap = randomStringObjectMap(5);
    XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
    builder.map(randomStringObjectMap);
    XContentBuilder shuffleXContent = shuffleXContent(builder);
    XContentParser parser = createParser(shuffleXContent);
    Map<String, Object> resultMap = parser.map();
    assertEquals("both maps should contain the same mappings", randomStringObjectMap, resultMap);
    assertNotEquals("Both builders string representations should be different", builder.bytes(), shuffleXContent.bytes());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:ESTestCaseTests.java

示例8: source

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
/**
 * The mapping source definition.
 */
@SuppressWarnings("unchecked")
public PutMappingRequest source(Map mappingSource) {
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.map(mappingSource);
        return source(builder.string());
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + mappingSource + "]", e);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:14,代码来源:PutMappingRequest.java

示例9: settings

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
/**
 * Sets repository-specific restore settings
 * <p>
 * See repository documentation for more information.
 *
 * @param source repository-specific snapshot settings
 * @return this request
 */
public RestoreSnapshotRequest settings(Map<String, Object> source) {
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.map(source);
        settings(builder.string());
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
    }
    return this;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:19,代码来源:RestoreSnapshotRequest.java

示例10: aliases

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
/**
 * Sets the aliases that will be associated with the index when it gets created
 */
@SuppressWarnings("unchecked")
public CreateIndexRequest aliases(Map source) {
    try {
        XContentBuilder builder = XContentFactory.jsonBuilder();
        builder.map(source);
        return aliases(builder.bytes());
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:CreateIndexRequest.java

示例11: testWriteMapValueWithNullKeys

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
public void testWriteMapValueWithNullKeys() throws IOException {
    XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
    try {
        builder.map(Collections.singletonMap(null, "test"));
        fail("write map should have failed");
    } catch(IllegalArgumentException e) {
        assertThat(e.getMessage(), equalTo("Field name cannot be null"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:XContentBuilderTests.java

示例12: source

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
/**
 * Raw version of {@link #source(PercolateSourceBuilder)}
 */
@SuppressWarnings("unchecked")
public PercolateRequest source(Map document, XContentType contentType) throws ElasticsearchGenerationException {
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(contentType);
        builder.map(document);
        return source(builder);
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + document + "]", e);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:14,代码来源:PercolateRequest.java

示例13: mapping

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
/**
 * Adds mapping that will be added when the index gets created.
 *
 * @param type   The mapping type
 * @param source The mapping source
 */
public PutIndexTemplateRequest mapping(String type, Map<String, Object> source) {
    // wrap it in a type map if its not
    if (source.size() != 1 || !source.containsKey(type)) {
        source = MapBuilder.<String, Object>newMapBuilder().put(type, source).map();
    }
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.map(source);
        return mapping(type, builder);
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:PutIndexTemplateRequest.java

示例14: aliases

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
/**
 * Sets the aliases that will be associated with the index when it gets created
 */
@SuppressWarnings("unchecked")
public PutIndexTemplateRequest aliases(Map source) {
    try {
        XContentBuilder builder = XContentFactory.jsonBuilder();
        builder.map(source);
        return aliases(builder.bytes());
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:PutIndexTemplateRequest.java

示例15: doXContent

import org.elasticsearch.common.xcontent.XContentBuilder; //导入方法依赖的package包/类
@Override
protected void doXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
    if (dynamicDateTimeFormatters != Defaults.DYNAMIC_DATE_TIME_FORMATTERS) {
        if (dynamicDateTimeFormatters.length > 0) {
            builder.startArray("dynamic_date_formats");
            for (FormatDateTimeFormatter dateTimeFormatter : dynamicDateTimeFormatters) {
                builder.value(dateTimeFormatter.format());
            }
            builder.endArray();
        }
    }

    if (dynamicTemplates != null && dynamicTemplates.length > 0) {
        builder.startArray("dynamic_templates");
        for (DynamicTemplate dynamicTemplate : dynamicTemplates) {
            builder.startObject();
            builder.field(dynamicTemplate.name());
            builder.map(dynamicTemplate.conf());
            builder.endObject();
        }
        builder.endArray();
    }

    if (dateDetection != Defaults.DATE_DETECTION) {
        builder.field("date_detection", dateDetection);
    }
    if (numericDetection != Defaults.NUMERIC_DETECTION) {
        builder.field("numeric_detection", numericDetection);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:31,代码来源:RootObjectMapper.java


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