elasticsearch之索引模板

索引模板简介

索引模板是创建索引的一种方式。将数据写入指定索引时,如果该索引不存在,则根据索引名称能匹配相应索引模板话,会根据模板的配置建立索引。更多介绍请查看官网的Index templates

索引模板查看

查看某个索引模板

curl --user ${USERNAME}:${PASSWORD} -XGET "${ES_URL}/_template/ftp_download_log?pretty"

查看所有索引模板

curl --user ${USERNAME}:${PASSWORD} -XGET "${ES_URL}/_template?pretty"

索引模板创建

curl --user ${USERNAME}:${PASSWORD} -XPUT "${ES_URL}/_template/ftp_download_log" -H 'Content-Type: application/json' -d '
{
"index_patterns": ["ftp_download_log_*"],
"settings": {
    "index": {
      "number_of_shards": 12,
      "number_of_replicas": 0,
      "refresh_interval" : "30s"
    }
  },
  "mappings": {
    "properties": {
      "@timestamp": {
        "type": "date"
      },
      "ftpServerName": {
        "type": "keyword"
      },      
      "localPath": {
        "type": "keyword"
      },
      "logType": {
        "type": "keyword"
      },
      "remotePath": {
        "type": "keyword"
      },
      "srcFileSize": {
        "type": "long"
      },
      "srcFileTimestamp": {
        "type": "date"
      },
      "elapsedTime": {
        "type": "long"
      },
      "endTime": {
        "type": "date"
      },
      "startTime": {
        "type": "date"
      }
    }
   }
}'

索引模板删除

curl --user ${USERNAME}:${PASSWORD} -XDELETE "${ES_URL}/_template/ftp_download_log"

索引模板修改

curl --user ${USERNAME}:${PASSWORD} -XPUT "${ES_URL}/_template/ftp_download_log" -H 'Content-Type: application/json' -d '
{
"index_patterns": ["ftp_download_log_*"],
"settings": {
    "index": {
      "number_of_shards": 12,
      "number_of_replicas": 0,
      "refresh_interval" : "30s"
    }
  },
  "mappings": {
    "properties": {
      "@timestamp": {
        "type": "date"
      },
      "fileDataTimeMillis": {
        "type": "date"
      },
      "ftpServerName": {
        "type": "keyword"
      }
    }
   }
}'

注意:文章中涉及命令是基于elasticsearch 7.1.1版本,与最新版本有较大不同。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值