本文整理汇总了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;
}
示例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 + "\"}"));
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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;
}
示例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());
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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"));
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}