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

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

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

MappingMetaData.<init>介绍

暂无

代码示例

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

public Builder putMapping(String type, String source) throws IOException {
  putMapping(new MappingMetaData(type, XContentHelper.convertToMap(XContentFactory.xContent(source), source, true)));
  return this;
}

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

public static GetMappingsResponse fromXContent(XContentParser parser) throws IOException {
  if (parser.currentToken() == null) {
    parser.nextToken();
  }
  assert parser.currentToken() == XContentParser.Token.START_OBJECT;
  Map<String, Object> parts = parser.map();
  ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> builder = new ImmutableOpenMap.Builder<>();
  for (Map.Entry<String, Object> entry : parts.entrySet()) {
    final String indexName = entry.getKey();
    assert entry.getValue() instanceof Map : "expected a map as type mapping, but got: " + entry.getValue().getClass();
    final Map<String, Object> mapping = (Map<String, Object>) ((Map) entry.getValue()).get(MAPPINGS.getPreferredName());
    ImmutableOpenMap.Builder<String, MappingMetaData> typeBuilder = new ImmutableOpenMap.Builder<>();
    for (Map.Entry<String, Object> typeEntry : mapping.entrySet()) {
      final String typeName = typeEntry.getKey();
      assert typeEntry.getValue() instanceof Map : "expected a map as inner type mapping, but got: " +
        typeEntry.getValue().getClass();
      final Map<String, Object> fieldMappings = (Map<String, Object>) typeEntry.getValue();
      MappingMetaData mmd = new MappingMetaData(typeName, fieldMappings);
      typeBuilder.put(typeName, mmd);
    }
    builder.put(indexName, typeBuilder.build());
  }
  return new GetMappingsResponse(builder.build());
}

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

@SuppressWarnings("unchecked")
private static MappingMetaData filterFields(MappingMetaData mappingMetaData, Predicate<String> fieldPredicate) throws IOException {
  if (fieldPredicate == MapperPlugin.NOOP_FIELD_PREDICATE) {
    return mappingMetaData;
  }
  Map<String, Object> sourceAsMap = XContentHelper.convertToMap(mappingMetaData.source().compressedReference(), true).v2();
  Map<String, Object> mapping;
  if (sourceAsMap.size() == 1 && sourceAsMap.containsKey(mappingMetaData.type())) {
    mapping = (Map<String, Object>) sourceAsMap.get(mappingMetaData.type());
  } else {
    mapping = sourceAsMap;
  }
  Map<String, Object> properties = (Map<String, Object>)mapping.get("properties");
  if (properties == null || properties.isEmpty()) {
    return mappingMetaData;
  }
  filterFields("", properties, fieldPredicate);
  return new MappingMetaData(mappingMetaData.type(), sourceAsMap);
}

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

private boolean refreshIndexMapping(IndexService indexService, IndexMetaData.Builder builder) {
  boolean dirty = false;
  String index = indexService.index().getName();
  try {
    List<String> updatedTypes = new ArrayList<>();
    for (DocumentMapper mapper : indexService.mapperService().docMappers(true)) {
      final String type = mapper.type();
      if (!mapper.mappingSource().equals(builder.mapping(type).source())) {
        updatedTypes.add(type);
      }
    }
    // if a single type is not up-to-date, re-send everything
    if (updatedTypes.isEmpty() == false) {
      logger.warn("[{}] re-syncing mappings with cluster state because of types [{}]", index, updatedTypes);
      dirty = true;
      for (DocumentMapper mapper : indexService.mapperService().docMappers(true)) {
        builder.putMapping(new MappingMetaData(mapper));
      }
    }
  } catch (Exception e) {
    logger.warn(() -> new ParameterizedMessage("[{}] failed to refresh-mapping in cluster state", index), e);
  }
  return dirty;
}

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

Map<String, Object> mappingSource =
      MapBuilder.<String, Object>newMapBuilder().put(mappingType, parser.mapOrdered()).map();
    builder.putMapping(new MappingMetaData(mappingType, mappingSource));
  } else {
    throw new IllegalArgumentException("Unexpected token: " + token);
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
  if (token == XContentParser.Token.VALUE_EMBEDDED_OBJECT) {
    builder.putMapping(new MappingMetaData(new CompressedXContent(parser.binaryValue())));
  } else {
    Map<String, Object> mapping = parser.mapOrdered();
    if (mapping.size() == 1) {
      String mappingType = mapping.keySet().iterator().next();
      builder.putMapping(new MappingMetaData(mappingType, mapping));

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

@Override
public void readFrom(StreamInput in) throws IOException {
  super.readFrom(in);
  int size = in.readVInt();
  ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> indexMapBuilder = ImmutableOpenMap.builder();
  for (int i = 0; i < size; i++) {
    String key = in.readString();
    int valueSize = in.readVInt();
    ImmutableOpenMap.Builder<String, MappingMetaData> typeMapBuilder = ImmutableOpenMap.builder();
    for (int j = 0; j < valueSize; j++) {
      typeMapBuilder.put(in.readString(), new MappingMetaData(in));
    }
    indexMapBuilder.put(key, typeMapBuilder.build());
  }
  mappings = indexMapBuilder.build();
}

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

indexMetaDataBuilder.putMapping(new MappingMetaData(mapper.mappingSource()));

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

private static ImmutableOpenMap<String, MappingMetaData> parseMappings(XContentParser parser) throws IOException {
  ImmutableOpenMap.Builder<String, MappingMetaData> indexMappings = ImmutableOpenMap.builder();
  // We start at START_OBJECT since parseIndexEntry ensures that
  while (parser.nextToken() != Token.END_OBJECT) {
    ensureExpectedToken(Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation);
    parser.nextToken();
    if (parser.currentToken() == Token.START_OBJECT) {
      String mappingType = parser.currentName();
      indexMappings.put(mappingType, new MappingMetaData(mappingType, parser.map()));
    } else if (parser.currentToken() == Token.START_ARRAY) {
      parser.skipChildren();
    }
  }
  return indexMappings.build();
}

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

MappingMetaData mappingMd = new MappingMetaData(mapper);
mappingsMetaData.put(mapper.type(), mappingMd);

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

ImmutableOpenMap.Builder<String, MappingMetaData> mappingEntryBuilder = ImmutableOpenMap.builder();
for (int j = 0; j < valueSize; j++) {
  mappingEntryBuilder.put(in.readString(), new MappingMetaData(in));

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

public Builder putMapping(String type, String source) throws IOException {
  putMapping(new MappingMetaData(type, XContentHelper.convertToMap(XContentFactory.xContent(source), source, true)));
  return this;
}

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

public Builder putMapping(String type, String source) throws IOException {
  putMapping(new MappingMetaData(type, XContentHelper.convertToMap(XContentFactory.xContent(source), source, true)));
  return this;
}

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

@SuppressWarnings("unchecked")
private static MappingMetaData filterFields(MappingMetaData mappingMetaData, Predicate<String> fieldPredicate) throws IOException {
  if (fieldPredicate == MapperPlugin.NOOP_FIELD_PREDICATE) {
    return mappingMetaData;
  }
  Map<String, Object> sourceAsMap = XContentHelper.convertToMap(mappingMetaData.source().compressedReference(), true).v2();
  Map<String, Object> mapping;
  if (sourceAsMap.size() == 1 && sourceAsMap.containsKey(mappingMetaData.type())) {
    mapping = (Map<String, Object>) sourceAsMap.get(mappingMetaData.type());
  } else {
    mapping = sourceAsMap;
  }
  Map<String, Object> properties = (Map<String, Object>)mapping.get("properties");
  if (properties == null || properties.isEmpty()) {
    return mappingMetaData;
  }
  filterFields("", properties, fieldPredicate);
  return new MappingMetaData(mappingMetaData.type(), sourceAsMap);
}

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

int mappingsSize = in.readVInt();
for (int i = 0; i < mappingsSize; i++) {
  MappingMetaData mappingMd = new MappingMetaData(in);
  builder.putMapping(mappingMd);

代码示例来源:origin: harbby/presto-connectors

public Builder putMapping(String type, String source) throws IOException {
  try (XContentParser parser = XContentFactory.xContent(source).createParser(source)) {
    putMapping(new MappingMetaData(type, parser.mapOrdered()));
  }
  return this;
}

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

@Override
public void readFrom(StreamInput in) throws IOException {
  super.readFrom(in);
  int size = in.readVInt();
  ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> indexMapBuilder = ImmutableOpenMap.builder();
  for (int i = 0; i < size; i++) {
    String key = in.readString();
    int valueSize = in.readVInt();
    ImmutableOpenMap.Builder<String, MappingMetaData> typeMapBuilder = ImmutableOpenMap.builder();
    for (int j = 0; j < valueSize; j++) {
      typeMapBuilder.put(in.readString(), new MappingMetaData(in));
    }
    indexMapBuilder.put(key, typeMapBuilder.build());
  }
  mappings = indexMapBuilder.build();
}

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

@Override
public void readFrom(StreamInput in) throws IOException {
  super.readFrom(in);
  int size = in.readVInt();
  ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> indexMapBuilder = ImmutableOpenMap.builder();
  for (int i = 0; i < size; i++) {
    String key = in.readString();
    int valueSize = in.readVInt();
    ImmutableOpenMap.Builder<String, MappingMetaData> typeMapBuilder = ImmutableOpenMap.builder();
    for (int j = 0; j < valueSize; j++) {
      typeMapBuilder.put(in.readString(), new MappingMetaData(in));
    }
    indexMapBuilder.put(key, typeMapBuilder.build());
  }
  mappings = indexMapBuilder.build();
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public void readFrom(StreamInput in) throws IOException {
  super.readFrom(in);
  int size = in.readVInt();
  ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> indexMapBuilder = ImmutableOpenMap.builder();
  for (int i = 0; i < size; i++) {
    String key = in.readString();
    int valueSize = in.readVInt();
    ImmutableOpenMap.Builder<String, MappingMetaData> typeMapBuilder = ImmutableOpenMap.builder();
    for (int j = 0; j < valueSize; j++) {
      typeMapBuilder.put(in.readString(), new MappingMetaData(in));
    }
    indexMapBuilder.put(key, typeMapBuilder.build());
  }
  mappings = indexMapBuilder.build();
}

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

private static ImmutableOpenMap<String, MappingMetaData> parseMappings(XContentParser parser) throws IOException {
  ImmutableOpenMap.Builder<String, MappingMetaData> indexMappings = ImmutableOpenMap.builder();
  // We start at START_OBJECT since parseIndexEntry ensures that
  while (parser.nextToken() != Token.END_OBJECT) {
    ensureExpectedToken(Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation);
    parser.nextToken();
    if (parser.currentToken() == Token.START_OBJECT) {
      String mappingType = parser.currentName();
      indexMappings.put(mappingType, new MappingMetaData(mappingType, parser.map()));
    } else if (parser.currentToken() == Token.START_ARRAY) {
      parser.skipChildren();
    }
  }
  return indexMappings.build();
}

代码示例来源:origin: apache/servicemix-bundles

private static ImmutableOpenMap<String, MappingMetaData> parseMappings(XContentParser parser) throws IOException {
  ImmutableOpenMap.Builder<String, MappingMetaData> indexMappings = ImmutableOpenMap.builder();
  // We start at START_OBJECT since parseIndexEntry ensures that
  while (parser.nextToken() != Token.END_OBJECT) {
    ensureExpectedToken(Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation);
    parser.nextToken();
    if (parser.currentToken() == Token.START_OBJECT) {
      String mappingType = parser.currentName();
      indexMappings.put(mappingType, new MappingMetaData(mappingType, parser.map()));
    } else if (parser.currentToken() == Token.START_ARRAY) {
      parser.skipChildren();
    }
  }
  return indexMappings.build();
}

相关文章