org.elasticsearch.cluster.metadata.MappingMetaData.getSourceAsMap()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(118)

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

MappingMetaData.getSourceAsMap介绍

[英]Converts the serialized compressed form of the mappings into a parsed map.
[中]将映射的序列化压缩形式转换为已解析的映射。

代码示例

代码示例来源:origin: SonarSource/sonarqube

@CheckForNull
@SuppressWarnings("unchecked")
private Map<String, Object> field(MappingMetaData mapping, String field) {
 Map<String, Object> props = (Map<String, Object>) mapping.getSourceAsMap().get("properties");
 return (Map<String, Object>) props.get(field);
}

代码示例来源:origin: SonarSource/sonarqube

private int countMappingFields(MappingMetaData mapping) {
 return ((Map) mapping.getSourceAsMap().get("properties")).size();
}

代码示例来源:origin: alibaba/canal

Map<String, Object> sourceMap = mappingMetaData.getSourceAsMap();
Map<String, Object> esMapping = (Map<String, Object>) sourceMap.get("properties");
for (Map.Entry<String, Object> entry : esMapping.entrySet()) {

代码示例来源:origin: SonarSource/sonarqube

private void verifyFakeIndex() {
 ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = mappings();
 MappingMetaData mapping = mappings.get("fakes").get("fake");
 assertThat(mapping.type()).isEqualTo("fake");
 assertThat(mapping.getSourceAsMap()).isNotEmpty();
 assertThat(countMappingFields(mapping)).isEqualTo(2);
 assertThat(field(mapping, "updatedAt").get("type")).isEqualTo("date");
}

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

if (client.admin().indices().prepareDeleteMapping(index).setType(type).get().isAcknowledged()) {
  PutMappingResponse pmr = client.admin().indices().preparePutMapping(index).setType(type)
      .setSource(mapping.getSourceAsMap()).get();
  if (!pmr.isAcknowledged()) {
    logger.error("Failed to put mapping {} / {} / {}.", index, type, mapping.source());

代码示例来源:origin: fujitsu-pio/io

@Override
  public Map<String, Object> getSourceAsMap() throws IOException {
    return this.mappingMetaData.getSourceAsMap();
  }
}

代码示例来源:origin: org.vertexium/vertexium-elasticsearch2

@SuppressWarnings("unchecked")
private Map<String, Map<String, String>> getPropertiesFromTypeMapping(MappingMetaData typeMapping) throws IOException {
  return (Map<String, Map<String, String>>) typeMapping.getSourceAsMap().get("properties");
}

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

@SuppressWarnings("unchecked")
private Map<String, Map<String, String>> getPropertiesFromTypeMapping(MappingMetaData typeMapping) throws IOException {
  return (Map<String, Map<String, String>>) typeMapping.getSourceAsMap().get("properties");
}

代码示例来源:origin: org.vertexium/vertexium-elasticsearch5

@SuppressWarnings("unchecked")
private Map<String, Map<String, String>> getPropertiesFromTypeMapping(MappingMetaData typeMapping) throws IOException {
  return (Map<String, Map<String, String>>) typeMapping.getSourceAsMap().get("properties");
}

代码示例来源:origin: visallo/vertexium

@SuppressWarnings("unchecked")
private Map<String, Map<String, String>> getPropertiesFromTypeMapping(MappingMetaData typeMapping) throws IOException {
  return (Map<String, Map<String, String>>) typeMapping.getSourceAsMap().get("properties");
}

代码示例来源:origin: cheng-li/pyramid

public Set<String> listAllFields() throws Exception{
  GetMappingsResponse response = client.admin().indices().prepareGetMappings(this.indexName).
      execute().actionGet();
  MappingMetaData mappingMetaData = response.getMappings().get(this.indexName).get(this.documentType);
  Map map = (Map)mappingMetaData.getSourceAsMap().get("properties");
  Set<String> fields = new HashSet<>();
  for (Object field: map.keySet()){
    fields.add(field.toString());
  }
  return fields;
}

代码示例来源:origin: com.scireum/sirius-search

private void outputMapping(Output output, ImmutableOpenMap<String, MappingMetaData> c) throws IOException {
  Iterator<String> iter = c.keysIt();
  while (iter.hasNext()) {
    String property = iter.next();
    MappingMetaData md = c.get(property);
    output.line("routing: " + md.routing().toString());
    for (Map.Entry<String, Object> e : md.getSourceAsMap().entrySet()) {
      outputMappingRow(output, e);
    }
  }
}

代码示例来源:origin: dqeasycloud/easy-cloud

@Override
public Map<String, Object> getAllMapping(String indexName) throws Exception {
  Assert.notNull(indexName, "No index defined for putMapping()");
  Map<String, Object> map = new HashMap<>();
  try {
    ImmutableOpenMap<String, MappingMetaData> immutableOpenMap = getIndicesAdminClient().getMappings(new GetMappingsRequest().indices(indexName))
        .actionGet().getMappings().get(indexName);
    Iterator<ObjectObjectCursor<String, MappingMetaData>> iterator = immutableOpenMap.iterator();
    while (iterator.hasNext()) {
      ObjectObjectCursor<String, MappingMetaData> objectObjectCursor = iterator.next();
      map.put(objectObjectCursor.key, objectObjectCursor.value.getSourceAsMap());
    }
  } catch (Exception e) {
    throw new Exception("Error while getting mapping for indexName : " + indexName + e.getMessage());
  }
  return map;
}

代码示例来源:origin: dqeasycloud/easy-cloud

@Override
public Map<String, Object> getMapping(String indexName, String type) throws Exception {
  Assert.notNull(indexName, "No index defined for putMapping()");
  Assert.notNull(type, "No type defined for putMapping()");
  Map mappings = null;
  try {
    mappings = getIndicesAdminClient().getMappings(new GetMappingsRequest().indices(indexName).types(type))
        .actionGet().getMappings().get(indexName).get(type).getSourceAsMap();
  } catch (Exception e) {
    throw new Exception("Error while getting mapping for indexName : " + indexName + " type : " + type + " " + e.getMessage());
  }
  return mappings;
}

代码示例来源:origin: org.vertexium/vertexium-elasticsearch5-plugin

Map<String, Map<String, String>> meta = (Map<String, Map<String, String>>) elementMetadata.getSourceAsMap().get("_meta");
if (meta == null) {
  continue;

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

/**
 * Waits for the given mapping type to exists on the master node.
 */
public void assertMappingOnMaster(final String index, final String type, final String... fieldNames) throws Exception {
  GetMappingsResponse response = client().admin().indices().prepareGetMappings(index).setTypes(type).get();
  ImmutableOpenMap<String, MappingMetaData> mappings = response.getMappings().get(index);
  assertThat(mappings, notNullValue());
  MappingMetaData mappingMetaData = mappings.get(type);
  assertThat(mappingMetaData, notNullValue());
  Map<String, Object> mappingSource = mappingMetaData.getSourceAsMap();
  assertFalse(mappingSource.isEmpty());
  assertTrue(mappingSource.containsKey("properties"));
  for (String fieldName : fieldNames) {
    Map<String, Object> mappingProperties = (Map<String, Object>) mappingSource.get("properties");
    if (fieldName.indexOf('.') != -1) {
      fieldName = fieldName.replace(".", ".properties.");
    }
    assertThat("field " + fieldName + " doesn't exists in mapping " + mappingMetaData.source().string(), XContentMapValues.extractValue(fieldName, mappingProperties), notNullValue());
  }
}

代码示例来源:origin: flaxsearch/BioSolr

@Override
public List<String> getDynamicFieldNames() throws SearchEngineException {
  List<String> fieldNames = new LinkedList<>();
  try {
    GetMappingsRequest req =
        new GetMappingsRequestBuilder(client, GetMappingsAction.INSTANCE, configuration.getIndexName())
            .setTypes(configuration.getDocType())
            .request();
    GetMappingsResponse response = client.admin().indices().getMappings(req).actionGet();
    MappingMetaData metaData = response.getMappings()
        .get(configuration.getIndexName())
        .get(configuration.getDocType());
    Map<String, Object> sourceMap = metaData.getSourceAsMap();
    Object annotationField = ((Map)sourceMap.get("properties")).get(configuration.getAnnotationField());
    Map<String, Object> annotationProperties = (Map<String, Object>)((Map)annotationField).get("properties");
    if (annotationProperties != null) {
      for (String field : annotationProperties.keySet()) {
        if (field.matches(DYNAMIC_LABEL_FIELD_REGEX)) {
          fieldNames.add(field);
        }
      }
    }
  } catch (IOException e) {
    LOGGER.error("Caught IOException retrieving field source: {}", e.getMessage());
    throw new SearchEngineException(e);
  }
  return fieldNames;
}

代码示例来源:origin: org.uberfire/uberfire-metadata-backend-elasticsearch

public void updateMetaModel(KObject object,
              MetaObject metaObject) {
  List<MetaProperty> dirtyProperties = new ArrayList<>();
  Optional<MappingMetaData> mappingOptional = this.indexProvider.getMapping(object.getClusterId(),
                                       object.getType().getName());
  if (!mappingOptional.isPresent()) {
    this.indexProvider.putMapping(object.getClusterId(),
                   object.getType().getName(),
                   metaObject);
  } else {
    Map<String, Object> mapping = mappingOptional.get().getSourceAsMap();
    Optional.ofNullable(object.getProperties())
        .ifPresent(kProperties -> {
          for (final KProperty property : object.getProperties()) {
            Object config = mapping.get(property.getName());
            if (config == null) {
              Optional<MetaProperty> prop = metaObject.getProperty(property.getName());
              prop.ifPresent(metaProperty -> dirtyProperties.add(metaProperty));
            }
          }
        });
    this.indexProvider.putMapping(object.getClusterId(),
                   object.getType().getName(),
                   dirtyProperties);
  }
}

代码示例来源:origin: kiegroup/appformer

public void updateMetaModel(KObject object,
              MetaObject metaObject) {
  List<MetaProperty> dirtyProperties = new ArrayList<>();
  Optional<MappingMetaData> mappingOptional = this.indexProvider.getMapping(object.getClusterId(),
                                       object.getType().getName());
  if (!mappingOptional.isPresent()) {
    this.indexProvider.putMapping(object.getClusterId(),
                   object.getType().getName(),
                   metaObject);
  } else {
    Map<String, Object> mapping = mappingOptional.get().getSourceAsMap();
    Optional.ofNullable(object.getProperties())
        .ifPresent(kProperties -> {
          for (final KProperty property : object.getProperties()) {
            Object config = mapping.get(property.getName());
            if (config == null) {
              Optional<MetaProperty> prop = metaObject.getProperty(property.getName());
              prop.ifPresent(metaProperty -> dirtyProperties.add(metaProperty));
            }
          }
        });
    this.indexProvider.putMapping(object.getClusterId(),
                   object.getType().getName(),
                   dirtyProperties);
  }
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public ImmutableIndexInfo(String name, IndexService indexService, MappingMetaData mappingMetaData, MetaData metadata, boolean versionLessEngine) throws IOException {
  this.name = name;
  this.versionLessEngine = versionLessEngine;
  this.indexService = indexService;
  this.mapping = mappingMetaData.sourceAsMap();
  this.type = mappingMetaData.type();
  
  Map<String,Object> mappingMap = (Map<String,Object>)mappingMetaData.getSourceAsMap();
  Map<String,Object> metaMap = (mappingMap == null) ? null : (Map<String,Object>)mappingMap.get("_meta");
  
  this.refresh = getMetaSettings(metadata.settings(), indexService.getIndexSettings(), metaMap, IndexMetaData.INDEX_SYNCHRONOUS_REFRESH_SETTING);
  this.snapshot = getMetaSettings(metadata.settings(), indexService.getIndexSettings(), metaMap, IndexMetaData.INDEX_SNAPSHOT_WITH_SSTABLE_SETTING);
  this.includeNodeId = getMetaSettings(metadata.settings(), indexService.getIndexSettings(), metaMap, IndexMetaData.INDEX_INCLUDE_NODE_ID_SETTING);
  
  this.index_on_compaction = getMetaSettings(metadata.settings(), indexService.getIndexSettings(), metaMap, IndexMetaData.INDEX_INDEX_ON_COMPACTION_SETTING);
  this.index_static_columns = getMetaSettings(metadata.settings(), indexService.getIndexSettings(), metaMap, IndexMetaData.INDEX_INDEX_STATIC_COLUMNS_SETTING);
  this.index_static_only = getMetaSettings(metadata.settings(), indexService.getIndexSettings(), metaMap, IndexMetaData.INDEX_INDEX_STATIC_ONLY_SETTING);
}

相关文章