org.elasticsearch.client.IndicesAdminClient.prepareGetTemplates()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(2.6k)|赞(0)|评价(0)|浏览(116)

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

IndicesAdminClient.prepareGetTemplates介绍

[英]Gets an index template (optional).
[中]获取索引模板(可选)。

代码示例

代码示例来源:origin: Netflix/conductor

/**
 * Initializes the index with required templates and mappings.
 */
private void initIndex() throws Exception {
  // 0. Add the tasklog template
  GetIndexTemplatesResponse result = elasticSearchClient.admin()
    .indices()
    .prepareGetTemplates("tasklog_template")
    .execute()
    .actionGet();
  if (result.getIndexTemplates().isEmpty()) {
    logger.info("Creating the index template 'tasklog_template'");
    InputStream stream = ElasticSearchDAOV5.class
      .getResourceAsStream("/template_tasklog.json");
    byte[] templateSource = IOUtils.toByteArray(stream);
    try {
      elasticSearchClient.admin()
        .indices()
        .preparePutTemplate("tasklog_template")
        .setSource(templateSource, XContentType.JSON)
        .execute()
        .actionGet();
    } catch (Exception e) {
      logger.error("Failed to init tasklog_template", e);
    }
  }
}

代码示例来源:origin: fr.pilato.elasticsearch/elasticsearch-beyonder

/**
 * Check if a template exists
 * @param client Elasticsearch client
 * @param template template name
 * @return true if the template exists
 * @deprecated Will be removed when we don't support TransportClient anymore
 */
@Deprecated
public static boolean isTemplateExist(Client client, String template) {
  return !client.admin().indices().prepareGetTemplates(template).get().getIndexTemplates().isEmpty();
}

代码示例来源:origin: dadoonet/elasticsearch-beyonder

/**
 * Check if a template exists
 * @param client Elasticsearch client
 * @param template template name
 * @return true if the template exists
 * @deprecated Will be removed when we don't support TransportClient anymore
 */
@Deprecated
public static boolean isTemplateExist(Client client, String template) {
  return !client.admin().indices().prepareGetTemplates(template).get().getIndexTemplates().isEmpty();
}

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

/**
 * Removes all templates, except the templates defined in the exclude
 */
public void wipeAllTemplates(Set<String> exclude) {
  if (size() > 0) {
    GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get();
    for (IndexTemplateMetaData indexTemplate : response.getIndexTemplates()) {
      if (exclude.contains(indexTemplate.getName())) {
        continue;
      }
      try {
        client().admin().indices().prepareDeleteTemplate(indexTemplate.getName()).execute().actionGet();
      } catch (IndexTemplateMissingException e) {
        // ignore
      }
    }
  }
}

相关文章

微信公众号

最新文章

更多

IndicesAdminClient类方法