ES 动态模版配置(自用记录)

本文详细介绍Elasticsearch中动态模版的配置方法,包括模版的创建、更新、删除及索引设置。涵盖副本数、主分片数、日期检测、字段类型等关键参数的配置,以及如何通过curl命令进行模版操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ES 动态模版配置:
curl -XDELETE http://127.0.0.1:9200/_template/${template-name} //删除模板
curl -GET http://127.0.0.1:9200/_template/${template-name} //获取模版

curl -XGET http://127.0.0.1:9200/_cat/indices/${index-name-prefix*} //获取索引
curl -XDELETE http://127.0.0.1:9200/${index-name}?pretty //删除索引

//创建模板
curl -XPUT http://127.0.0.1:9200/_template/${template-name} -d ' //设置模版名字
{
    "template": "${index-template-prefix*}", //设置模版自建索引匹配前缀
    "order": 0, //设置模板优先级,同属性高优先级覆盖低优先级
    "settings": {
        "number_of_replicas": 1, //副本数
        "number_of_shards": 10 //主分片数
    },
    "mappings": {
        "event": {
            "date_detection": false, //关闭日期推断检测
            "_all": {
                "enabled": false //禁用该字段,不支持无字段文档检索
            },
            "properties": {
                "id": {
                    "type": "keyword"
                },
                "uid": {
                    "type": "keyword",
                    "doc_values": false //不分词字眼若不排序和聚合仅做过滤和匹配用可禁用该属性
                },
                "event": {
                    "type": "keyword"
                },
                "type": {
                    "type": "keyword"
                },
                "status": {
                    "type": "keyword"
                },
                "time_stamp": {
                    "type": "date",
                    "ignore_malformed": true, //忽略非正常时间戳数字
                    "format": "epoch_millis" //时间戳格式
                },
                "dev": {
                    "type": "keyword"
                },
                "extra": {
                    "type": "text" //分词字段
                }
            },
            "dynamic_templates": [{
                "string_as_keyword": {
                    "match": "*", //非指定字段统配
                    "match_mapping_type": "string", //匹配json中的格式
                    "mapping": {
                        "type": "keyword",
                        "doc_values": false, // 非指定字段禁用该属性,仅做过滤和匹配用
                        "ignore_above": 256 //超长字段部分部略
                    }
                }
            }]
        }
    }
}'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值