# Adding new index-pattern in Kibana through REST API

**URL:** <https://discuss.elastic.co/t/adding-new-index-pattern-in-kibana-through-rest-api/191742>\
**Category:** Kibana\
**Created:** [July 23, 2019, 6:19am UTC](https://discuss.elastic.co/t/adding-new-index-pattern-in-kibana-through-rest-api/191742 "2019-07-23T06:19:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![RAM\_NATHAN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ram_nathan/32/50393_2.png) [@RAM\_NATHAN](https://discuss.elastic.co/u/RAM_NATHAN)\
**Post date:** [July 23, 2019, 6:19am UTC](https://discuss.elastic.co/t/adding-new-index-pattern-in-kibana-through-rest-api/191742/1 "2019-07-23T06:19:48Z")

</div>

Hi

I'm upgrading from 5.6.13 to 7.0.0. I came to know there are few breaking changes.  
Earlier I use to have a script to create index-pattern, visualizations, dashboards through REST API

Can you direct me a sample to do the same in 7

Regards  
Ram

---

<div class="post-metadata">

**Author:** ![RAM\_NATHAN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ram_nathan/32/50393_2.png) [@RAM\_NATHAN](https://discuss.elastic.co/u/RAM_NATHAN)\
**Post date:** [July 23, 2019, 6:47am UTC](https://discuss.elastic.co/t/adding-new-index-pattern-in-kibana-through-rest-api/191742/2 "2019-07-23T06:47:28Z")

</div>

As an example , I have tried to create new visualization using below

curl -XPOST "[http://localhost:9200/.kibana/\_doc](http://localhost:9200/.kibana/_doc)" -H 'Content-Type: application/json' -d'  
{  
"visualization" :{

"title": "Test",  
"visState": "{....}",  
"uiStateJSON": "{.....}",  
"description": "",  
"version": 1,  
"kibanaSavedObjectMeta": {  
"searchSourceJSON": "{"index":"testindex","query":{"match\_all":{}},"filter":}"  
},  
"type": "visualization"  
}  
}'

I'm getting below error

"reason": "mapping set to strict, dynamic introduction of [type] within [visualization] is not allowed"

If I dont give "type", my visualizations are not getting listed in UI, though it got added successfully

Ironically "type" is working fine when I give for index-pattern as below

POST .kibana/\_doc  
{  
"index-pattern" :{"title" : "test",  
"timeFieldName" :"createdat",  
"type": "index-pattern"  
}

}

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [July 23, 2019, 10:39am UTC](https://discuss.elastic.co/t/adding-new-index-pattern-in-kibana-through-rest-api/191742/3 "2019-07-23T10:39:25Z")

</div>

Moving to Kibana forum - this is essentially an issue with how Kibana visualizations are stored internally and their changing document format.

---

<div class="post-metadata">

**Author:** ![RAM\_NATHAN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ram_nathan/32/50393_2.png) [@RAM\_NATHAN](https://discuss.elastic.co/u/RAM_NATHAN)\
**Post date:** [July 25, 2019, 5:19am UTC](https://discuss.elastic.co/t/adding-new-index-pattern-in-kibana-through-rest-api/191742/4 "2019-07-25T05:19:18Z")

</div>

Can some one reply please??

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [July 25, 2019, 7:15am UTC](https://discuss.elastic.co/t/adding-new-index-pattern-in-kibana-through-rest-api/191742/5 "2019-07-25T07:15:50Z")

</div>

> [@RAM\_NATHAN](#):
>
> Ironically "type" is working fine when I give for index-pattern as below

The problem you have is that the documents you present do not adhere to a schema (mapping). The schema is not formally documented and published because it is subject to change. However if you use the \_mapping api in elasticsearch you can probably reverse engineer what fields are defined in your version.

---

<div class="post-metadata">

**Author:** ![RAM\_NATHAN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ram_nathan/32/50393_2.png) [@RAM\_NATHAN](https://discuss.elastic.co/u/RAM_NATHAN)\
**Post date:** [July 25, 2019, 7:28am UTC](https://discuss.elastic.co/t/adding-new-index-pattern-in-kibana-through-rest-api/191742/6 "2019-07-25T07:28:37Z")

</div>

I thought mapping doesn't matter, as elasticsearch is flexible. I can give only fields I want.

But , is that the reason blocking me to create new visualization through POST/PUT API??

So is it possible to create visualization through API (which I was doing in 5.6.13 ) in 7.0.0? If yes, please share an example. I will adhere to that mapping schema

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [July 25, 2019, 7:55am UTC](https://discuss.elastic.co/t/adding-new-index-pattern-in-kibana-through-rest-api/191742/7 "2019-07-25T07:55:50Z")

</div>

> [@RAM\_NATHAN](#):
>
> I thought mapping doesn't matter, as elasticsearch is flexible

Mappings can be made strict which is what is happening here. What would be the point of your application sending the wrong fields and not being made aware of that failure?

> [@RAM\_NATHAN](#):
>
> So is it possible to create visualization through API

Yes

> [@RAM\_NATHAN](#):
>
> If yes, please share an example. I will adhere to that mapping schema

See my previous comment about using the \_mapping api to discover the schema in effect. Or - create a visualization manually in Kibana, save it, then find the saved JSON and copy as appropriate.

---

<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:** [August 22, 2019, 7:55am UTC](https://discuss.elastic.co/t/adding-new-index-pattern-in-kibana-through-rest-api/191742/8 "2019-08-22T07:55:56Z")

</div>

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