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

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

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

IndicesAdminClient.preparePutTemplate介绍

[英]Puts an index template.
[中]放置索引模板。

代码示例

代码示例来源: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

/**
 * Create a new index in Elasticsearch
 * @param client Elasticsearch client
 * @param template Template name
 * @param json JSon content for the template
 * @throws Exception if something goes wrong
 * @deprecated Will be removed when we don't support TransportClient anymore
 */
@Deprecated
private static void createTemplateWithJsonInElasticsearch(Client client, String template, String json) throws Exception {
  logger.trace("createTemplate([{}])", template);
  assert client != null;
  assert template != null;
  AcknowledgedResponse response = client.admin().indices()
      .preparePutTemplate(template)
      .setSource(json.getBytes(), XContentType.JSON)
      .get();
  if (!response.isAcknowledged()) {
    logger.warn("Could not create template [{}]", template);
    throw new Exception("Could not create template ["+template+"].");
  }
  logger.trace("/createTemplate([{}])", template);
}

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

/**
 * Create a new index in Elasticsearch
 * @param client Elasticsearch client
 * @param template Template name
 * @param json JSon content for the template
 * @throws Exception if something goes wrong
 * @deprecated Will be removed when we don't support TransportClient anymore
 */
@Deprecated
private static void createTemplateWithJsonInElasticsearch(Client client, String template, String json) throws Exception {
  logger.trace("createTemplate([{}])", template);
  assert client != null;
  assert template != null;
  AcknowledgedResponse response = client.admin().indices()
      .preparePutTemplate(template)
      .setSource(json.getBytes(), XContentType.JSON)
      .get();
  if (!response.isAcknowledged()) {
    logger.warn("Could not create template [{}]", template);
    throw new Exception("Could not create template ["+template+"].");
  }
  logger.trace("/createTemplate([{}])", template);
}

代码示例来源:origin: hannesstockner/kafka-connect-elasticsearch

@Override
public void start(Map<String, String> props) {
 final String esHost = props.get(ElasticsearchSinkConnector.ES_HOST);
 indexPrefix = props.get(ElasticsearchSinkConnector.INDEX_PREFIX);
 try {
  client = TransportClient
   .builder()
   .build()
   .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(esHost), 9300));
  client
   .admin()
   .indices()
   .preparePutTemplate("kafka_template")
   .setTemplate(indexPrefix + "*")
   .addMapping(TYPE, new HashMap<String, Object>() {{
    put("date_detection", false);
    put("numeric_detection", false);
   }})
   .get();
 } catch (UnknownHostException ex) {
  throw new ConnectException("Couldn't connect to es host", ex);
 }
}

代码示例来源:origin: jloisel/elastic-crud

@Before
public void before() throws IOException {
 repository = factory.create(Person.class);
 repository.refreshPolicy(IMMEDIATE);
 final IndicesAdminClient indices = client.admin().indices();
 final PutIndexTemplateRequest datas = indices.preparePutTemplate("datas")
  .setSource(toByteArray(getClass().getResourceAsStream("/datas.json")), JSON)
  .request();
 checkState(indices.putTemplate(datas).actionGet().isAcknowledged());
}

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

.preparePutTemplate("random_index_template")
.setPatterns(Collections.singletonList("*"))
.setOrder(0)

代码示例来源:origin: apache/streams

@BeforeClass
public void prepareTestParentChildPersistWriter() throws Exception {
 testConfiguration = new ComponentConfigurator<>(ElasticsearchWriterConfiguration.class).detectConfiguration("ElasticsearchParentChildWriterIT");
 testClient = ElasticsearchClientManager.getInstance(testConfiguration).client();
 ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
 ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet();
 assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED);
 IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getIndex());
 IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet();
 if (indicesExistsResponse.isExists()) {
  DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getIndex());
  DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet();
  assertTrue(deleteIndexResponse.isAcknowledged());
 }
 PutIndexTemplateRequestBuilder putTemplateRequestBuilder = testClient.admin().indices().preparePutTemplate("mappings");
 URL templateURL = ElasticsearchParentChildWriterIT.class.getResource("/ActivityChildObjectParent.json");
 ObjectNode template = MAPPER.readValue(templateURL, ObjectNode.class);
 String templateSource = MAPPER.writeValueAsString(template);
 putTemplateRequestBuilder.setSource(templateSource);
 testClient.admin().indices().putTemplate(putTemplateRequestBuilder.request()).actionGet();
 Reflections reflections = new Reflections(new ConfigurationBuilder()
  .setUrls(ClasspathHelper.forPackage("org.apache.streams.pojo.json"))
  .setScanners(new SubTypesScanner()));
 objectTypes = reflections.getSubTypesOf(ActivityObject.class);
 Path testdataDir = Paths.get("target/dependency/activitystreams-testdata");
 files = Files.list(testdataDir).collect(Collectors.toList());
 assert( files.size() > 0);
}

相关文章

微信公众号

最新文章

更多

IndicesAdminClient类方法