Thursday, April 28, 2016

Create index in kibana using curl command, Index creation in Kibana by code, Kibana index by command, create index in Kibana in background


Your ElasticSearch Servar and Kibana server should be running during this poc.

Just assume,

Kibana is running at 10.20.30.40:5601


First requirement, you should have same index in your Elasticsearch for which you wanted to create index in Kibana.
If you do not have any index in Elasticsearch then first create it.

{
 "_index": "twiteer_one",
            "_type": "tweet",
            "_id": "2",
            "_score": 1,
            "_source": {
               "nick": "Ishan@gmail.com",
               "date": "2015-02-10",
               "post": "NCFE",
               "other_name": "Ishan Suman"
            }
         },
         {
            "_index": "twiteer_one",
            "_type": "tweet",
            "_id": "17",
            "_score": 1,
            "_source": {
               "nick": "@binodsuman",
               "date": "2014-08-15",
               "post": "BigData, Kibana, ES, ML",
               "other_name": "Binod Suman"
            }
}

I hope your Elasticsearch must be running while using below command.

Now suppose you want to create index with name twiteer_one in your kibana, then use this below command in lunux flavor machine. (This command gives some error while executing in Windows Machine).

curl -H  "Content-Type: application/json" -XPOST -i -H "kbn-version:4.4.2" http://10.20.30.40:5601/elasticsearch/.kibana/index-pattern/twiteer_one?op_type=create -d '{"title": "twiteer_two", "timeFieldName": "date"}'

After successfully execute this command, come in Kibana and check.

Kibana -> Settings -> Indices, your twiteer_two index should be here.









Wednesday, April 27, 2016

Export and import via curl kibana’s dashboards and visualizations, Kibana Dashboard export into another Elasticsearch, command line load dashboard, How to save dashboard as json file, Location of custom Kibana dashboards in ElasticSearch


First in create some index and data in first ElasticSearch. As per my example:
{
 "_index": "twiteer_one",
            "_type": "tweet",
            "_id": "2",
            "_score": 1,
            "_source": {
               "nick": "Ishan@gmail.com",
               "date": "2015-02-10",
               "post": "NCFE",
               "other_name": "Ishan Suman"
            }
         },
         {
            "_index": "twiteer_one",
            "_type": "tweet",
            "_id": "17",
            "_score": 1,
            "_source": {
               "nick": "@binodsuman",
               "date": "2014-08-15",
               "post": "BigData, Kibana, ES, ML",
               "other_name": "Binod Suman"
            }

 - Connect this first ElasticSearch into your kibana dashboard.
 - Create two visualization using above index "twiteer_one"
   In my case, First-Visualization and Second-Visualization
 - Create one Dashboard in kibana using these two visualization.
   In my case my Dashboard name is "My-Dashboard".
 
- Export all three item (two visualization and one dashboard) individually from Kibana.
  HOW: In Kibana -> go to Settings -> Objects -> Visualization and
   * tick on First Visualization and export and save in one folder with name v1.json
   * tick on Second  Visualization and export and save in one folder with name v2.json
 
   - In Kibana -> go to Settings -> Objects -> Dashboard and
   * tick on My Dashboard and export and save in one folder with name dashboard.json
 
 
  - Stop this first ElasticSearch
  - Start your second ElasticSearch, make sure you should have same index "twiteer_one" with same set of data.
  Edit v1.json and remove first four line and your file should like this:
 
   {
      "title": "First Visualization",
      "visState": "{\"title\":\"New
 ----
 -----
  "searchSourceJSON": "{\"index\":\"twiteer_one\",\"query\":{\"query_string\":{\"query\":\"*\",\"analyze_wildcard\":true}},\"filter\":[]}"
      }
    }
  Edit v2.json and dashboard.json also and remove first four lines.
 
  Execute these three curl command:
  D:\Kibana_Json>curl localhost:9200/.kibana/visualization/First-Visualization -d @v1.json
  D:\Kibana_Json>curl localhost:9200/.kibana/visualization/Second-Visualization -d @v2.json
  D:\Kibana_Json>curl localhost:9200/.kibana/dashboard/My-Dashboard -d @dashboard.json
  Make sure after executing each command you must get "created":true message.
  {"_index":".kibana","_type":"dashboard","_id":"My-Dashboard","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}
D:\Kibana_Json>

  Now you connect second ElasticSearch with Kibana and you will be getting all your visualization and Dashboard.
  Please write if any problem or feedback.