# How to import index-pattern in kibana 6 using API?

**URL:** <https://discuss.elastic.co/t/how-to-import-index-pattern-in-kibana-6-using-api/109299>\
**Category:** Kibana\
**Created:** [November 28, 2017, 2:33am UTC](https://discuss.elastic.co/t/how-to-import-index-pattern-in-kibana-6-using-api/109299 "2017-11-28T02:33:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fragatina](https://avatars.discourse-cdn.com/v4/letter/f/ccd318/32.png) [@fragatina](https://discuss.elastic.co/u/fragatina)\
**Post date:** [November 28, 2017, 2:33am UTC](https://discuss.elastic.co/t/how-to-import-index-pattern-in-kibana-6-using-api/109299/1 "2017-11-28T02:33:48Z")

</div>

I was successfully using API to create/import index-patterns using API with kibana 5.6.x version.  
After upgrading to kibana 6.0.0, the API format has changed and I cannot anymore create index-patterns using curl.  
What's the new format? I have multiple ways to get (export) the index-patterns from kibana 6 but I don't know how to save them programmatically.

---

<div class="post-metadata">

**Author:** ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)\
**Post date:** [November 28, 2017, 4:08am UTC](https://discuss.elastic.co/t/how-to-import-index-pattern-in-kibana-6-using-api/109299/2 "2017-11-28T04:08:22Z")

</div>

There are two API's which can accomplish this, both of which are available in 5.6.x and remain unchanged.

We are currently working on documentation, but in the meantime, you can reference the PR's.

Dashboard import/export API. This can be used to export/import a dashboard with all of its dependencies, including the index pattern: [https://github.com/elastic/kibana/pull/10858#issuecomment-327802510](https://github.com/elastic/kibana/pull/10858#issuecomment-327802510)

Saved Objects API. This is used under the hood by the dashboard import/export API and can be used to persist the data underlying Kibana. [https://github.com/elastic/kibana/pull/11632](https://github.com/elastic/kibana/pull/11632)

---

<div class="post-metadata">

**Author:** ![fragatina](https://avatars.discourse-cdn.com/v4/letter/f/ccd318/32.png) [@fragatina](https://discuss.elastic.co/u/fragatina)\
**Post date:** [November 28, 2017, 8:05pm UTC](https://discuss.elastic.co/t/how-to-import-index-pattern-in-kibana-6-using-api/109299/3 "2017-11-28T20:05:37Z")

</div>

Thanks tylersmalley for your response.  
I've tried that but it doesn't seem to be working.

Example:  
- The following query:  
curl -XPUT -H "kbn-xsrf:true" "[http://localhost:5601/api/saved\_objects/index-pattern/e38f6e90-cf2f-11e7-a5ef-9f5ab64be49e](http://localhost:5601/api/saved_objects/index-pattern/e38f6e90-cf2f-11e7-a5ef-9f5ab64be49e)" -d '{"version": 1, "attributes": {"title": "test-\*"}}'  
- it returns:  
{"statusCode":400,"error":"Bad Request","message":"child "attributes" fails because ["attributes" is required]. "{"version": 1, "attributes": {"title": "test-\*"}" is not allowed","validation":{"source":"payload","keys":["attributes","{"version": 1, "attributes": {"title": "test-\*"}"]}}

---

<div class="post-metadata">

**Author:** ![fragatina](https://avatars.discourse-cdn.com/v4/letter/f/ccd318/32.png) [@fragatina](https://discuss.elastic.co/u/fragatina)\
**Post date:** [November 28, 2017, 10:45pm UTC](https://discuss.elastic.co/t/how-to-import-index-pattern-in-kibana-6-using-api/109299/4 "2017-11-28T22:45:15Z")

</div>

After more investigation with the links you provided,  
I've successfully installed a index-pattern in a indirect way.  
I've done it by installing a dashboard. It seems that it also installs the index-patterns that depends on it.

However, I don't see how to set an index-pattern as the defaultIndex using an API.

I see that the defaultIndex is stored in the .kibana config but I don't know how to set it:

# curl -XGET [http://localhost:9200/.kibana/doc/\_search?q=type:config](http://localhost:9200/.kibana/doc/_search?q=type:config)

{"took":1,"timed\_out":false,"\_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":1,"max\_score":3.205453,"hits":[{"\_index":".kibana","\_type":"doc","\_id":"config:6.0.0","\_score":3.205453,"\_source":{"type":"config","config":{"buildNum":16070,"defaultIndex":"291176c0-cfda-11e7-a5ef-9f5ab64be49e"}}}]}}

Any help on this will be very much appreciated. Thanks.

---

<div class="post-metadata">

**Author:** ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)\
**Post date:** [November 28, 2017, 11:28pm UTC](https://discuss.elastic.co/t/how-to-import-index-pattern-in-kibana-6-using-api/109299/5 "2017-11-28T23:28:59Z")

</div>

You need to add `Content-Type: application/json` to the saved\_objects API call.

There is an API to set settings, you can set the setting and inspect the network calls.

`curl -X POST -H "Content-Type: application/json" -H "kbn-xsrf: true" -d '{"value":"e7502fa0-ca17-11e7-bab5-157d3f7aa014"}' http://elastic:changeme@localhost:5601/api/kibana/settings/defaultIndex`

---

<div class="post-metadata">

**Author:** ![fragatina](https://avatars.discourse-cdn.com/v4/letter/f/ccd318/32.png) [@fragatina](https://discuss.elastic.co/u/fragatina)\
**Post date:** [November 29, 2017, 8:27am UTC](https://discuss.elastic.co/t/how-to-import-index-pattern-in-kibana-6-using-api/109299/6 "2017-11-29T08:27:20Z")

</div>

thanks a lot tylersmalley for your response, that worked!

---

<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 27, 2017, 8:27am UTC](https://discuss.elastic.co/t/how-to-import-index-pattern-in-kibana-6-using-api/109299/7 "2017-12-27T08:27:55Z")

</div>

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