angel的编程路 2017-03-02 02:41 采纳率: 33.3%
浏览 6731
已结题

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程序中,应该在什么时机设置这个模板才能让从第一次开始所有索引都按照我的模板建立。

  • 写回答

1条回答 默认 最新

  • 夕阳雨晴 2017-03-02 05:16
    关注

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

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog