org.elasticsearch.common.xcontent.XContentBuilder.map()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(130)

本文整理了Java中org.elasticsearch.common.xcontent.XContentBuilder.map()方法的一些代码示例,展示了XContentBuilder.map()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XContentBuilder.map()方法的具体详情如下:
包路径:org.elasticsearch.common.xcontent.XContentBuilder
类名称:XContentBuilder
方法名:map

XContentBuilder.map介绍

暂无

代码示例

代码示例来源:origin: NLPchina/elasticsearch-sql

private void writeMappings(ImmutableOpenMap<String, MappingMetaData> mappings, XContentBuilder builder, ToXContent.Params params) throws IOException {
  builder.startObject(Fields.MAPPINGS);
  if (mappings != null) {
    for (ObjectObjectCursor<String, MappingMetaData> typeEntry : mappings) {
      builder.field(typeEntry.key);
      builder.map(typeEntry.value.sourceAsMap());
    }
  }
  builder.endObject();
}

代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb

private XContentBuilder build(final DBObject data, final String objectId) throws IOException {
  if (data instanceof GridFSDBFile) {
    logger.info("Add Attachment: {} to index {} / type {}", objectId, definition.getIndexName(), definition.getTypeName());
    return MongoDBHelper.serialize((GridFSDBFile) data);
  } else {
    Map<String, Object> mapData = this.createObjectMap(data);
    return XContentFactory.jsonBuilder().map(mapData);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public void merge(Map<String, Map<String, Object>> mappings, MergeReason reason, boolean updateAllTypes) {
  Map<String, CompressedXContent> mappingSourcesCompressed = new LinkedHashMap<>(mappings.size());
  for (Map.Entry<String, Map<String, Object>> entry : mappings.entrySet()) {
    try {
      mappingSourcesCompressed.put(entry.getKey(), new CompressedXContent(Strings.toString(
        XContentFactory.jsonBuilder().map(entry.getValue()))));
    } catch (Exception e) {
      throw new MapperParsingException("Failed to parse mapping [{}]: {}", e, entry.getKey(), e.getMessage());
    }
  }
  internalMerge(mappingSourcesCompressed, reason, updateAllTypes);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
  builder.field("since", sinceTime);
  if (restUsage != null) {
    builder.field("rest_actions");
    builder.map(restUsage);
  }
  return builder;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
  // Concatenates the type and the name of the aggregation (ex: top_hits#foo)
  builder.startObject(String.join(InternalAggregation.TYPED_KEYS_DELIMITER, getType(), name));
  if (this.metadata != null) {
    builder.field(InternalAggregation.CommonFields.META.getPreferredName());
    builder.map(this.metadata);
  }
  doXContentBody(builder, params);
  builder.endObject();
  return builder;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public MappingMetaData(String type, Map<String, Object> mapping) throws IOException {
  this.type = type;
  XContentBuilder mappingBuilder = XContentFactory.jsonBuilder().map(mapping);
  this.source = new CompressedXContent(BytesReference.bytes(mappingBuilder));
  Map<String, Object> withoutType = mapping;
  if (mapping.size() == 1 && mapping.containsKey(type)) {
    withoutType = (Map<String, Object>) mapping.get(type);
  }
  initMappers(withoutType);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public AliasActions filter(Map<String, Object> filter) {
  if (filter == null || filter.isEmpty()) {
    this.filter = null;
    return this;
  }
  try {
    XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
    builder.map(filter);
    this.filter = Strings.toString(builder);
    return this;
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to generate [" + filter + "]", e);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public Builder filter(Map<String, Object> filter) {
  if (filter == null || filter.isEmpty()) {
    this.filter = null;
    return this;
  }
  try {
    XContentBuilder builder = XContentFactory.jsonBuilder().map(filter);
    this.filter = new CompressedXContent(BytesReference.bytes(builder));
    return this;
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to build json for alias request", e);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Index the Map as the provided content type.
 *
 * @param source The map to index
 */
public IndexRequest source(Map source, XContentType contentType) throws ElasticsearchGenerationException {
  try {
    XContentBuilder builder = XContentFactory.contentBuilder(contentType);
    builder.map(source);
    return source(builder);
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

NameOrDefinition(Map<String, ?> definition) {
  this.name = null;
  Objects.requireNonNull(definition);
  try {
    XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
    builder.map(definition);
    this.definition = Settings.builder().loadFromSource(Strings.toString(builder), builder.contentType()).build();
  } catch (IOException e) {
    throw new IllegalArgumentException("Failed to parse [" + definition + "]", e);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * The mapping source definition.
 */
@SuppressWarnings("unchecked")
public PutMappingRequest source(Map mappingSource) {
  try {
    XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
    builder.map(mappingSource);
    return source(Strings.toString(builder), XContentType.JSON);
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to generate [" + mappingSource + "]", e);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * The settings to create the index template with (either json or yaml format).
 */
public PutIndexTemplateRequest settings(Map<String, Object> source) {
  try {
    XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
    builder.map(source);
    settings(Strings.toString(builder), XContentType.JSON);
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
  }
  return this;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * 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(BytesReference.bytes(builder));
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * 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(BytesReference.bytes(builder));
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * The settings to create the index with (either json/yaml/properties format)
 */
@SuppressWarnings("unchecked")
public CreateIndexRequest settings(Map source) {
  try {
    XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
    builder.map(source);
    settings(Strings.toString(builder), XContentType.JSON);
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
  }
  return this;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private static Script extractConditional(Map<String, Object> config) throws IOException {
  Object scriptSource = config.remove("if");
  if (scriptSource != null) {
    try (XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent)
      .map(normalizeScript(scriptSource));
       InputStream stream = BytesReference.bytes(builder).streamInput();
       XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY,
         LoggingDeprecationHandler.INSTANCE, stream)) {
      return Script.parse(parser);
    }
  }
  return null;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Sets settings that should be added/changed in all restored indices
 */
public RestoreSnapshotRequest indexSettings(Map<String, Object> source) {
  try {
    XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
    builder.map(source);
    indexSettings(Strings.toString(builder), builder.contentType());
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
  }
  return this;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Sets the transient settings to be updated. They will not survive a full cluster restart
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public ClusterUpdateSettingsRequest transientSettings(Map source) {
  try {
    XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
    builder.map(source);
    transientSettings(Strings.toString(builder), builder.contentType());
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
  }
  return this;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Sets the settings to be updated (either json or yaml format)
 */
@SuppressWarnings("unchecked")
public UpdateSettingsRequest settings(Map source) {
  try {
    XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
    builder.map(source);
    settings(Strings.toString(builder), builder.contentType());
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
  }
  return this;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Sets the persistent settings to be updated. They will get applied cross restarts
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public ClusterUpdateSettingsRequest persistentSettings(Map source) {
  try {
    XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
    builder.map(source);
    persistentSettings(Strings.toString(builder), builder.contentType());
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
  }
  return this;
}

相关文章

微信公众号

最新文章

更多