Java源码示例:org.elasticsearch.client.indices.PutIndexTemplateRequest

示例1
public boolean createTemplate(String indexName, Map<String, Object> settings,
                              Map<String, Object> mapping) throws IOException {
    indexName = formatIndexName(indexName);

    PutIndexTemplateRequest putIndexTemplateRequest = new PutIndexTemplateRequest(indexName).patterns(
        Collections.singletonList(indexName + "-*"))
                                                                                            .alias(new Alias(
                                                                                                indexName))
                                                                                            .settings(settings)
                                                                                            .mapping(mapping);

    AcknowledgedResponse acknowledgedResponse = client.indices()
                                                      .putTemplate(putIndexTemplateRequest, RequestOptions.DEFAULT);

    return acknowledgedResponse.isAcknowledged();
}
 
示例2
protected PutIndexTemplateRequest createIndexTemplateRequest(ElasticSearchIndexMetadata metadata) {
    String index = wrapIndex(metadata.getIndex());
    PutIndexTemplateRequest request = new PutIndexTemplateRequest(getTemplate(index));
    request.alias(new Alias(getAlias(index)));
    request.settings(properties.toSettings());
    Map<String, Object> mappingConfig = new HashMap<>();
    mappingConfig.put("properties", createElasticProperties(metadata.getProperties()));
    mappingConfig.put("dynamic_templates", createDynamicTemplates());
    request.mapping(mappingConfig);
    request.patterns(getIndexPatterns(index));
    return request;
}
 
示例3
@Override
public void putIndexTemplate(String name, String source) {
    var watch = new StopWatch();
    try {
        client().indices().putTemplate(new PutIndexTemplateRequest(name).source(new BytesArray(source), XContentType.JSON), RequestOptions.DEFAULT);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } finally {
        logger.info("put index template, name={}, elapsed={}", name, watch.elapsed());
    }
}