索引模板簡介
索引模板是創建索引的一種方式。將數據寫入指定索引時,如果該索引不存在,則根據索引名稱能匹配相應索引模板話,會根據模板的配置建立索引。更多介紹請查看官網的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版本,與最新版本有較大不同。