问题
Is it possible to automate the configuration of an index pattern in kibana? Either via some settings file or perhaps a rest api. After installation it's possible to do it manually.
回答1:
Kibana 5.x exposes such an API to manage index patterns.
To create index pattern one can issue below command to kibana access url (just edit the kibana endpoint, index-name and timestamp variables to match your needs):
curl <kibana-endpoint>/es_admin/.kibana/index-pattern/<index-name>/_create\
-H "Content-Type: application/json"\
-H "Accept: application/json, text/plain, */*"\
-H "kbn-xsrf: <index-name>"\
--data-binary '{"title":"${<index-name>}","timeFieldName":"<timestamp-field>"}' -w "\n"
For instance if kibana is under localhost:5601 and index-name is alert (alert_time is timestamp field) then command:
curl localhost:5601/es_admin/.kibana/index-pattern/alert/_create\
-H "Content-Type: application/json"\
-H "Accept: application/json, text/plain, */*"\
-H "kbn-xsrf: alert"\
--data-binary '{"title":"alert","timeFieldName":"alert_time"}' -w "\n"
Similarly, one can define default index pattern using below API for the example:
curl localhost:5601/api/kibana/settings/defaultIndex\
-H "Content-Type: application/json"\
-H "Accept: application/json, text/plain, */*"\
-H "kbn-xsrf: alert"\
-H "Connection: keep-alive"\
--data-binary "{\"value\":\"alert\"}" -w "\n"
回答2:
At present this is not possible. There is an issue at the Kibana github repo which schedules an Index pattern creation API for the 4.5.0 release. https://github.com/elastic/kibana/issues/3709
来源:https://stackoverflow.com/questions/28811267/how-to-automate-the-configuration-of-an-index-pattern-in-kibana