ElasticSearch创建索引如何使用模板?

ElasticSearch通过API可以设置template,设置mapping可以设置每个字段的类型和分词。比如下面的:

 {
        "template": "ld.log-*",
        "order":0,
        "settings": {
            "index.number_of_replicas": "1",
            "index.number_of_shards": "5"
        },
        "mappings": {
            "logs": {
                "properties": {
                    "@timestamp": {
                        "type": "date",
                        "format": "strict_date_optional_time||epoch_millis"
                    },
                    "@version": {
                        "doc_values": true,
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "Guid": {
                        "doc_values": true,
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "LogLevel": {
                        "type": "long"
                    }
                }
            }
        }
}

通过发Restful Api来更改模板的办法我知道,但是我现在做的是日志收集,每天都会自动创建新的index,可以用通配符匹配之后建立的索引,但问题是我想让ES部署完毕之后就自动按照我需要的模板建立索引,我觉得发API设模板不能满足我的需求。另外我是将发API写在JAVA程序里的,如果有办法实现,JAVA程序中,应该在什么时机设置这个模板才能让从第一次开始所有索引都按照我的模板建立。

安装此方式部署spring boot项目,http://blog.csdn.net/moest/article/details/52797857
使用模板时注入即可
// 注入ES模板
@Autowired
private ElasticsearchTemplate template;

List<SsoAccess> docList =
    template.queryForList(readerDomainSearchQuery.build(), SsoAccess.class);