logstash使用自定义模板问题记录

起因:

使用ogstash把日志存储到es,由于修改字段类型节省空间的需要,考虑使用自定义模板

经过:

根据网上配置了logstash.conf

output {
    elasticsearch {
        hosts => ["127.0.0.1:9200"]
        index => "logstash-test-%{+YYYY.MM.dd}"
        timeout => 30
        template => "/data/conf/template.json"
        template_name => "template-test"
        template_overwrite => true
    }
}

模板:

{
    "order": 0,
    "index_patterns": [
        "logstash-test-*"
    ],
    "mappings": {
            "dynamic_templates": [
                {
                    "string_fields": {
                        "match": "*",
                        "match_mapping_type": "string",
                        "mapping": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    }
                },
                {
                    "long_fields": {
                        "match": "*",
                        "match_mapping_type": "long",
                        "mapping": {
                            "doc_values": true,
                            "type": "long"
                        }
                    }
                },
                {
                    "date_fields": {
                        "match": "*",
                        "match_mapping_type": "date",
                        "mapping": {
                            "doc_values": true,
                            "type": "date"
                        }
                    }
                },,
                {
                    "text_fields": {
                        "match_mapping_type": "string",
                        "mapping": {
                            "type": "text",
                            "fields": {
                                "raw": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        }
                    }
                }
            ],
            "properties": {
                "@timestamp": {
                    "type": "date",
                    "format": "yyyy-MM-dd HH:mm:ss||HH:mm:ss||strict_date_optional_time||epoch_millis"
                },
                "info": {
                    "type": "keyword",
                    "ignore_above": 256
                },
                "cost": {
                    "type": "long"
                },
                "description": {
                    "type": "text",            
                    "norms": false,
                    "fields": {
                        "raw": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    }
                },
                "userId": {
                    "type": "keyword",
                    "ignore_above": 256
                }
            }
        },
    "settings": {
        "index": {
            "max_ngram_diff": "253",
            "refresh_interval": "5s",
            "number_of_shards": "5",
            "analysis": {
                "normalizer": {
                    "lowercase_normalizer": {
                        "filter": [
                            "lowercase"
                        ],
                        "type": "custom"
                    }
                }
            }
        }
    }
}

问题:

1、没有执行模板安装

发现自己设置么 manage_template=true;

解决:去掉 manage_template=true;

2、安装模板报400 错误,通过http添加模板报

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "Malformed [mappings] section for type [dynamic_templates], should include an inner object describing the mapping"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "Malformed [mappings] section for type [dynamic_templates], should include an inner object describing the mapping"
    },
    "status": 400

}

原因:模板是es7的,要安装的服务器es是6+的

解决:

在Mapping结构下增加_doc {

包含 properties, dynamic_templates等(原谅我,那么长的模板不想ctrl+c  ctrl+v)

}

es7+的  不需要增加_doc

官网关于这个模板结构的6.8的文档:Removal of mapping types | Elasticsearch Guide [6.8] | Elastic

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值