kibana設置默認索引
版本:
ELK7.6.2
方法:
1.前提是es中有這個索引
2.通過腳本創建kibana中的索引
3.設置默認索引
腳本
#!/bin/bash
# 構建索引名字
today=`date +%Y.%m.%d`
system_log=system-${today}
logstash_log=logstash-${today}
#index_name=${system_log}
index_name=${logstash_log}
# 在kibana中創建索引模式並接收返回值
res=`curl -X POST -H "kbn-xsrf:reporting" -H "Content-Type: application/json" -d '{"attributes":{"title":"'$index_name'"}}' 'http://192.168.219.8:5601/api/saved_objects/index-pattern'`
# 對接收到的返回值提取id值
# 這里需要安裝jq: yum -y install jq
id=`echo $res |jq '.id' |sed 's/"//g'`
# 設置kibana中的默認索引
curl -X POST -H "kbn-xsrf:true" -H "Content-Type: application/json" -d "{\"changes\":{\"defaultIndex\":\"$id\"}}" http://192.168.219.8:5601/api/kibana/settings
靈感來源於stackoverflow關鍵是里面給出了解決思路
在這里給我卡了好幾天,嘗試過多種方法,都沒得到解決,其原因是默認索引用的是索引名字,而不是創建索引后返回的id值,反正7.6.2版本是這樣的,我查過好多資料也都是通過指定索引名字來進行設置,希望有着跟我一樣需求的人能看到這篇文章。
附效果