• Elasticsearch索引自动套用模板


    方案选择:

    方案一:可对logstash配置output参数:

     如下所示:

     这种方案在logstash中指定模板文件,由logstash将template写入ES集群;

    方案二:直接将template写入ES集群

    通过ES提供的API,将JSON格式的template写入目标ES集群的_template路径,对新生成的所有符合过滤规则的索引直接套用该模板。

    模板的结构大致分四块吧:

    第一部分:通用设置,主要是模板匹配索引的过滤规则,影响该模板对哪些索引生效;

    第二部分:settings:配置索引的公共参数,比如索引的replicas,以及分片数shards等参数;

    第三部分:mappings:最重要的一部分,在这部分中配置每个type下的每个field的相关属性,比如field类型(string,long,date等等),是否分词,是否在内存中缓存等等属性都在这部分配置;

    第四部分:aliases:索引别名,索引别名可用在索引数据迁移等用途上。

    典型的一个template如下所示:

    {
            "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"
                        },
                        "Exp": {
                            "doc_values": true,
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "Guid": {
                            "doc_values": true,
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "LogLevel": {
                            "type": "long"
                        },
                        "LogTime": {
                            "type": "date",
                            "format": "strict_date_optional_time||epoch_millis"
                        },
                        "LoggerName": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "Message": {
                            "doc_values": true,
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "ProcessId": {
                            "type": "long"
                        },
                        "StackTrace": {
                            "doc_values": true,
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "ThreadId": {
                            "type": "long"
                        },
                        "exp": {
                            "doc_values": true,
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "logLevel": {
                            "type": "long"
                        },
                        "logTime": {
                            "doc_values": true,
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "loggerName": {
                            "doc_values": true,
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "message": {
                            "doc_values": true,
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "processId": {
                            "type": "long"
                        },
                        "tags": {
                            "doc_values": true,
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "threadId": {
                            "type": "long"
                        }
                    }
                }
            },
            "aliases": {
            }
    }

    在这个JSON中可以清楚地看到四个部分,并且对string类型的fields设置了不进行默认分词信息。

  • 相关阅读:
    使用POI读取excel文件内容
    有序链表
    jQuery Validate验证框架详解
    怎样在VS2010中打开VS2012的项目
    在Win8.1系统下如何安装运行SQL Server 2005
    SQL2005 2008配置错误,无法识别的配置节 system.serviceModel machine.config配置文件有问题
    深入浅出学Spring Data JPA
    Java 学习摘要
    JFinal
    spring 4 + jpa(hibernate 3/4) + spring mvc 多数据源配置
  • 原文地址:https://www.cnblogs.com/fat-girl-spring/p/14241180.html
Copyright © 2020-2023  润新知