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

**URL:** <https://discuss.elastic.co/t/curl-to-add-an-index-pattern-and-a-json-file-to-create-dashboard/156818>\
**Category:** Kibana\
**Created:** [November 15, 2018, 9:12am UTC](https://discuss.elastic.co/t/curl-to-add-an-index-pattern-and-a-json-file-to-create-dashboard/156818 "2018-11-15T09:12:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![saisimo02](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@saisimo02](https://discuss.elastic.co/u/saisimo02)\
**Post date:** [November 15, 2018, 9:12am UTC](https://discuss.elastic.co/t/curl-to-add-an-index-pattern-and-a-json-file-to-create-dashboard/156818/1 "2018-11-15T09:12:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![azasypkin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/azasypkin/32/42216_2.png) [@azasypkin](https://discuss.elastic.co/u/azasypkin)\
**Post date:** [November 15, 2018, 9:21am UTC](https://discuss.elastic.co/t/curl-to-add-an-index-pattern-and-a-json-file-to-create-dashboard/156818/2 "2018-11-15T09:21:32Z")

</div>

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](https://www.elastic.co/guide/en/kibana/6.5/saved-objects-api-create.html), 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

---

<div class="post-metadata">

**Author:** ![saisimo02](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@saisimo02](https://discuss.elastic.co/u/saisimo02)\
**Post date:** [November 15, 2018, 9:35am UTC](https://discuss.elastic.co/t/curl-to-add-an-index-pattern-and-a-json-file-to-create-dashboard/156818/3 "2018-11-15T09:35:57Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![saisimo02](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@saisimo02](https://discuss.elastic.co/u/saisimo02)\
**Post date:** [November 15, 2018, 9:37am UTC](https://discuss.elastic.co/t/curl-to-add-an-index-pattern-and-a-json-file-to-create-dashboard/156818/4 "2018-11-15T09:37:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![azasypkin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/azasypkin/32/42216_2.png) [@azasypkin](https://discuss.elastic.co/u/azasypkin)\
**Post date:** [November 15, 2018, 9:43am UTC](https://discuss.elastic.co/t/curl-to-add-an-index-pattern-and-a-json-file-to-create-dashboard/156818/5 "2018-11-15T09:43:42Z")

</div>

> 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`).

---

<div class="post-metadata">

**Author:** ![saisimo02](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@saisimo02](https://discuss.elastic.co/u/saisimo02)\
**Post date:** [November 15, 2018, 9:59am UTC](https://discuss.elastic.co/t/curl-to-add-an-index-pattern-and-a-json-file-to-create-dashboard/156818/6 "2018-11-15T09:59:31Z")

</div>

I have one last question 🙏 . 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-*"
> }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![azasypkin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/azasypkin/32/42216_2.png) [@azasypkin](https://discuss.elastic.co/u/azasypkin)\
**Post date:** [November 15, 2018, 10:05am UTC](https://discuss.elastic.co/t/curl-to-add-an-index-pattern-and-a-json-file-to-create-dashboard/156818/7 "2018-11-15T10:05:32Z")

</div>

> [@saisimo02](#):
>
> I should install a plugin or what to use **saved object API**

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](https://www.elastic.co/guide/en/kibana/current/console-kibana.html), but every query example in Elastic Docs includes `Copy as cURL` link, so you can copy request that will work with cURL instead.

---

<div class="post-metadata">

**Author:** ![saisimo02](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@saisimo02](https://discuss.elastic.co/u/saisimo02)\
**Post date:** [November 15, 2018, 10:10am UTC](https://discuss.elastic.co/t/curl-to-add-an-index-pattern-and-a-json-file-to-create-dashboard/156818/8 "2018-11-15T10:10:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 13, 2018, 10:10am UTC](https://discuss.elastic.co/t/curl-to-add-an-index-pattern-and-a-json-file-to-create-dashboard/156818/9 "2018-12-13T10:10:37Z")

</div>

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