Curl to add an index pattern and a json file to create dashboard

Hello,

I would like to use a curl command to add an index pattern to my kibana index. I am using logstash to index my data and indexes looks like that: logstash-{the current date}

I am using this command:

curl -XPOST "http://localhost:9200/.kibana1/_mappings/_doc/
{
 "properties": {
         "index-pattern":{
                 "properties":{
                         "title": "logstash*",
                         "timeFieldName": "time"}}}}"

I am getting this error: curl: (3) [globbing] nested brace in column 67

I have also a json file and I would like to send it to kibana by using curl.

Thank you for help

Hey @saisimo02,

It's highly not recommended to write to the Kibana index directly, it's not backward compatible and may not work in some cases that can put Kibana into undefined state at some point. The recommended way is to use Saved Objects API, it supports creation of index patterns as well.

To get the idea, you can create index pattern manually and use browser dev tools to see how request and its parameters look like or tune existing index pattern and then fetch it with the same API (find/get methods) to see the shape of the index pattern you want to create with cURL.

Best,
Oleg

1 Like

Thanks for your reply,

I have more than 50 kibana instance, and I don't want to index patterns manually. I already tried to use kibana interface. but now I would like to add a shell script to write to the kibana index directly even if it is not a good idea. To use the Saved Objects API I should add the index pattern before no ?

Another question, can I have the same id when I create an index pattern? and not generate it randomly? Thanks

To use the Saved Objects API I should add the index pattern before no ?

No, you can create index pattern with this API too (because index pattern is Saved Object for Kibana), please go through the docs I've linked above and let me know if there is something that's not clear.

Another question, can I have the same id when I create an index pattern? and not generate it randomly? Thanks

yes, and example in the linked docs illustrates exactly that (see my-pattern).

I have one last question :pray: . I should install a plugin or what to use saved object API

I would like to run this command but I don't know where.

POST api/saved_objects/index-pattern/logstash
{
  "attributes": {
    "title": "logstash-*"
  }
}

Nope, it should be available out of the box starting from Kibana 6.0 (every new version could change an API a bit, so that it depends on the version you use, but it shouldn't be difficult to figure out).

I would like to run this command but I don't know where.

This query format is for Kibana Dev Console, but every query example in Elastic Docs includes Copy as cURL link, so you can copy request that will work with cURL instead.

1 Like

I got it, working very well. Thansk a lot ^^

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.