Example #1
0
 protected DocIndexMetaData merge(
     DocIndexMetaData other,
     TransportPutIndexTemplateAction transportPutIndexTemplateAction,
     boolean thisIsCreatedFromTemplate)
     throws IOException {
   if (schemaEquals(other)) {
     return this;
   } else if (thisIsCreatedFromTemplate) {
     if (this.references.size() < other.references.size()) {
       // this is older, update template and return other
       // settings in template are always authoritative for table information about
       // number_of_shards and number_of_replicas
       updateTemplate(other, transportPutIndexTemplateAction, this.metaData.settings());
       // merge the new mapping with the template settings
       return new DocIndexMetaData(
               IndexMetaData.builder(other.metaData).settings(this.metaData.settings()).build(),
               other.ident)
           .build();
     } else if (references().size() == other.references().size()
         && !references().keySet().equals(other.references().keySet())) {
       XContentHelper.update(defaultMappingMap, other.defaultMappingMap, false);
       // update the template with new information
       updateTemplate(this, transportPutIndexTemplateAction, this.metaData.settings());
       return this;
     }
     // other is older, just return this
     return this;
   } else {
     throw new TableAliasSchemaException(other.ident.name());
   }
 }
Example #2
0
 private void updateTemplate(
     DocIndexMetaData md,
     TransportPutIndexTemplateAction transportPutIndexTemplateAction,
     Settings updateSettings) {
   String templateName = PartitionName.templateName(ident.schema(), ident.name());
   PutIndexTemplateRequest request =
       new PutIndexTemplateRequest(templateName)
           .mapping(Constants.DEFAULT_MAPPING_TYPE, md.defaultMappingMap)
           .create(false)
           .settings(updateSettings)
           .template(templateName + "*");
   for (String alias : md.aliases()) {
     request = request.alias(new Alias(alias));
   }
   transportPutIndexTemplateAction.execute(request);
 }