Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically set Kibana's default index pattern

A Kibana newbie would like to know how to set default index pattern programmatically rather than setting it on the Kibana UI through web browser during the first time viewing Kibana UI as mentioned on page https://www.elastic.co/guide/en/kibana/current/setup.html

like image 967
Rui Avatar asked Apr 26 '16 17:04

Rui


People also ask

How do I change the default index pattern?

For setting the default index pattern, we need to click on the index pattern name and then click on the star symbol link on top-right side of the page.

How do I set a default index pattern in Kibana?

Create an index patterneditOpen the main menu, then click to Stack Management > Index Patterns. Click Create index pattern. Start typing in the Index pattern field, and Kibana looks for the names of indices, data streams, and aliases that match your input.

What is the default configuration used in Logstash for index pattern?

See the Logstash documentation for more about the @metadata field. The default is apm. To change this value, set the index option in the APM Server config file. The default pipeline configuration: apm .


2 Answers

In kibana:6.5.3 this can be achieved this calling the kibana api.

curl -X POST "http://localhost:5601/api/saved_objects/index-pattern/logstash" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d'
{
  "attributes": {
    "title": "logstash-*",
    "timeFieldName": "@timestamp"
  }
}
'

the Docs are here it does mention that the feature is experimental.

like image 151
PB1 Avatar answered Sep 20 '22 14:09

PB1


Elasticsearch stores all Kibana metadata information under .kibana index. Kibana configurations like defaultIndex and advance settings are stored under index/type/id .kibana/config/4.5.0 where 4.5.0 is the version of your Kibana.

So you can achieve setting up or changing defaultIndex with following steps:

  1. Add index to Kibana which you want to set as defaultIndex. You can do that by executing following command:

    curl -XPUT http://<es node>:9200/.kibana/index-pattern/your_index_name -d '{"title" : "your_index_name",  "timeFieldName": "timestampFieldNameInYourInputData"}'
    
  2. Change your Kibana config to set index added earlier as defaultIndex:

    curl -XPUT http://<es node>:9200/.kibana/config/4.5.0 -d '{"defaultIndex" : "your_index_name"}'
    

Note: Make sure your giving correct index_name everywhere, valid timestamp field name and kibana version for example if you are using kibana 4.1.1 then you can replace 4.5.0 with 4.1.1 .

like image 39
avr Avatar answered Sep 19 '22 14:09

avr