Пример #1
0
    public IndexMetaData build() {
      MapBuilder<String, AliasMetaData> tmpAliases = aliases;
      Settings tmpSettings = settings;

      // For backward compatibility
      String[] legacyAliases = settings.getAsArray("index.aliases");
      if (legacyAliases.length > 0) {
        tmpAliases = MapBuilder.newMapBuilder();
        for (String alias : legacyAliases) {
          AliasMetaData aliasMd = AliasMetaData.newAliasMetaDataBuilder(alias).build();
          tmpAliases.put(alias, aliasMd);
        }
        tmpAliases.putAll(aliases.immutableMap());
        // Remove index.aliases from settings once they are migrated to the new data structure
        tmpSettings =
            ImmutableSettings.settingsBuilder().put(settings).putArray("index.aliases").build();
      }

      // update default mapping on the MappingMetaData
      if (mappings.containsKey(MapperService.DEFAULT_MAPPING)) {
        MappingMetaData defaultMapping = mappings.get(MapperService.DEFAULT_MAPPING);
        for (MappingMetaData mappingMetaData : mappings.map().values()) {
          mappingMetaData.updateDefaultMapping(defaultMapping);
        }
      }

      return new IndexMetaData(
          index,
          version,
          state,
          tmpSettings,
          mappings.immutableMap(),
          tmpAliases.immutableMap(),
          customs.immutableMap());
    }
 /** Checks the mappings for compatibility with the current version */
 private void checkMappingsCompatibility(IndexMetaData indexMetaData) {
   Index index = new Index(indexMetaData.getIndex());
   Settings settings = indexMetaData.getSettings();
   try {
     SimilarityService similarityService = new SimilarityService(index, settings);
     // We cannot instantiate real analysis server at this point because the node might not have
     // been started yet. However, we don't really need real analyzers at this stage - so we can
     // fake it
     try (AnalysisService analysisService = new FakeAnalysisService(index, settings)) {
       try (MapperService mapperService =
           new MapperService(index, settings, analysisService, similarityService, scriptService)) {
         for (ObjectCursor<MappingMetaData> cursor : indexMetaData.getMappings().values()) {
           MappingMetaData mappingMetaData = cursor.value;
           mapperService.merge(mappingMetaData.type(), mappingMetaData.source(), false, false);
         }
       }
     }
   } catch (Exception ex) {
     // Wrap the inner exception so we have the index name in the exception message
     throw new IllegalStateException(
         "unable to upgrade the mappings for the index ["
             + indexMetaData.getIndex()
             + "], reason: ["
             + ex.getMessage()
             + "]",
         ex);
   }
 }
Пример #3
0
 /**
  * @param concreteIndex The concrete index to check if routing is required
  * @param type The type to check if routing is required
  * @return Whether routing is required according to the mapping for the specified index and type
  */
 public boolean routingRequired(String concreteIndex, String type) {
   IndexMetaData indexMetaData = indices.get(concreteIndex);
   if (indexMetaData != null) {
     MappingMetaData mappingMetaData = indexMetaData.getMappings().get(type);
     if (mappingMetaData != null) {
       return mappingMetaData.routing().required();
     }
   }
   return false;
 }
Пример #4
0
 public static void writeTo(IndexMetaData indexMetaData, StreamOutput out) throws IOException {
   out.writeUTF(indexMetaData.index());
   out.writeLong(indexMetaData.version());
   out.writeByte(indexMetaData.state().id());
   writeSettingsToStream(indexMetaData.settings(), out);
   out.writeVInt(indexMetaData.mappings().size());
   for (MappingMetaData mappingMd : indexMetaData.mappings().values()) {
     MappingMetaData.writeTo(mappingMd, out);
   }
   out.writeVInt(indexMetaData.aliases().size());
   for (AliasMetaData aliasMd : indexMetaData.aliases().values()) {
     AliasMetaData.Builder.writeTo(aliasMd, out);
   }
   out.writeVInt(indexMetaData.customs().size());
   for (Map.Entry<String, Custom> entry : indexMetaData.customs().entrySet()) {
     out.writeUTF(entry.getKey());
     lookupFactorySafe(entry.getKey()).writeTo(entry.getValue(), out);
   }
 }
Пример #5
0
 public static IndexMetaData readFrom(StreamInput in) throws IOException {
   Builder builder = new Builder(in.readUTF());
   builder.version(in.readLong());
   builder.state(State.fromId(in.readByte()));
   builder.settings(readSettingsFromStream(in));
   int mappingsSize = in.readVInt();
   for (int i = 0; i < mappingsSize; i++) {
     MappingMetaData mappingMd = MappingMetaData.readFrom(in);
     builder.putMapping(mappingMd);
   }
   int aliasesSize = in.readVInt();
   for (int i = 0; i < aliasesSize; i++) {
     AliasMetaData aliasMd = AliasMetaData.Builder.readFrom(in);
     builder.putAlias(aliasMd);
   }
   int customSize = in.readVInt();
   for (int i = 0; i < customSize; i++) {
     String type = in.readUTF();
     Custom customIndexMetaData = lookupFactorySafe(type).readFrom(in);
     builder.putCustom(type, customIndexMetaData);
   }
   return builder.build();
 }
Пример #6
0
 public Builder putMapping(MappingMetaData mappingMd) {
   mappings.put(mappingMd.type(), mappingMd);
   return this;
 }