當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。