/** 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);
   }
 }
Пример #2
0
 public Builder putMapping(MappingMetaData mappingMd) {
   mappings.put(mappingMd.type(), mappingMd);
   return this;
 }