Пример #1
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);
 }
Пример #2
0
  private DocIndexMetaData docIndexMetaData() {
    DocIndexMetaData docIndexMetaData;
    String templateName = PartitionName.templateName(ident.schema(), ident.name());
    boolean createdFromTemplate = false;
    if (metaData.getTemplates().containsKey(templateName)) {
      docIndexMetaData = buildDocIndexMetaDataFromTemplate(ident.indexName(), templateName);
      createdFromTemplate = true;
      concreteIndices =
          metaData.concreteIndices(IndicesOptions.lenientExpandOpen(), ident.indexName());
    } else {
      try {
        concreteIndices =
            metaData.concreteIndices(IndicesOptions.strictExpandOpen(), ident.indexName());
        if (concreteIndices.length == 0) {
          // no matching index found
          throw new TableUnknownException(ident);
        }
        docIndexMetaData = buildDocIndexMetaData(concreteIndices[0]);
      } catch (IndexMissingException ex) {
        throw new TableUnknownException(ident.fqn(), ex);
      }
    }

    if ((!createdFromTemplate && concreteIndices.length == 1) || !checkAliasSchema) {
      return docIndexMetaData;
    }
    for (int i = 0; i < concreteIndices.length; i++) {
      try {
        docIndexMetaData =
            docIndexMetaData.merge(
                buildDocIndexMetaData(concreteIndices[i]),
                transportPutIndexTemplateAction,
                createdFromTemplate);
      } catch (IOException e) {
        throw new UnhandledServerException("Unable to merge/build new DocIndexMetaData", e);
      }
    }
    return docIndexMetaData;
  }