# Create Index\_Pattern through API

**URL:** https://discuss.elastic.co/t/create-index-pattern-through-api/136148
**Category:** Kibana
**Created:** [June 15, 2018, 9:47pm UTC](https://discuss.elastic.co/t/create-index-pattern-through-api/136148 "2018-06-15T21:47:29Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![RobotWarden](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@RobotWarden](https://discuss.elastic.co/u/RobotWarden)
#### Post date: [June 15, 2018, 9:47pm UTC](https://discuss.elastic.co/t/create-index-pattern-through-api/136148/1 "2018-06-15T21:47:29Z")

</div>

I am attempting to create an index pattern through the api or by uploading a dashboard. I am using Kibana version 6.1.0 in a kubernetes cluster. After I import the dashboard I get errors on saying "Could not locate the visualization (id: #)" and the dependent index has not been created.

I've tried a curl statement:  
`curl -X POST -H "kbn-xsrf: true" http://localhost:5601/api/saved_objects/index-pattern/test -d '{"version": 1,"attributes":{"title":"test-*"}}'`

but get the error:  
`{"statusCode":400,"error":"Bad Request","message":"child "attributes" fails because ["attributes" is required]. \"&#x7b;&quot;version&quot;:1,&quot:attributes&quot:;&#x7b;&quot;title&quot;:&quot;test-&#x2a;&quot;&#x7d;\" is not allowed","validation":{"source":"payload","key":["attributes","&#x7b;&quot;version&quot;:1,&quot;attributes&quot;:&#x7b;&quot;title&quot;:&quot;test-&#x2a;&quot;&#x7d;&#x7d;"]}}`

---

<div class="post-metadata">

### Author: ![Bill\_McConaghy](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@Bill\_McConaghy](https://discuss.elastic.co/u/Bill_McConaghy)
#### Post date: [June 18, 2018, 1:38pm UTC](https://discuss.elastic.co/t/create-index-pattern-through-api/136148/2 "2018-06-18T13:38:32Z")

</div>

I would suggest creating an index pattern manually and then searching for it. This will show you the expected JSON shape of an index pattern. You can then use that example as the basis for your own.

---

<div class="post-metadata">

### Author: ![RobotWarden](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@RobotWarden](https://discuss.elastic.co/u/RobotWarden)
#### Post date: [June 18, 2018, 3:29pm UTC](https://discuss.elastic.co/t/create-index-pattern-through-api/136148/3 "2018-06-18T15:29:44Z")

</div>

Thank you for the response.

I created the index pattern, created a search, made sure I got hits, saved it, exported it, restarted my cluster, replaced the uuid \_id and index with “test-\*” but the index is not created when I try to re-import. I get a pop up that says:

> The following saved objects use index patterns that do not exist. Please select the index patterns you’d like to re-associate them with.

My JSON:

```
[
{
	“_id”: “Test”,
	“_type”: “search”,
	“_source”: {
		“title”: “Test Search”
		“description”: “”,
		“hits”: 0,
		“columns”: [
			“_source”
		],
		"sort": [
			"@timestamp",
			"desc"
		],
		"version": 1
		"kibanaSavedObjectMeta": {
			"searchSourceJSON": "{\"index\":\"test-*\", \"highlightAll\":true,\"version\":true,\"query\":{\"language\":\"lucene\",\"query\":\"*\"},\"filter\":[]}"
		}
	}
}
]

```

If I create the index in Kibana then import the search I still get the same pop up message as before. I can then select the index "test-\*" I just created and view the results. That makes me think there is still something wrong with my json or how it is trying to create the index?

---

<div class="post-metadata">

### Author: ![Bill\_McConaghy](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@Bill\_McConaghy](https://discuss.elastic.co/u/Bill_McConaghy)
#### Post date: [June 18, 2018, 6:50pm UTC](https://discuss.elastic.co/t/create-index-pattern-through-api/136148/4 "2018-06-18T18:50:43Z")

</div>

Sounds like the index-pattern ID the visualization is pointed at is not lining up with the index pattern id. Those two need to match.

---

<div class="post-metadata">

### Author: ![RobotWarden](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@RobotWarden](https://discuss.elastic.co/u/RobotWarden)
#### Post date: [June 19, 2018, 2:03pm UTC](https://discuss.elastic.co/t/create-index-pattern-through-api/136148/5 "2018-06-19T14:03:51Z")

</div>

I understand that the "{"index":"test-\*" in the json is referencing the id of the index but I think the thing I cannot figure out his how to declare that index. I have exported a ton of metricbeat base examples but I still am not finding where this index is actually declared. Is a curl statement what I'm missing?

---

<div class="post-metadata">

### Author: ![RobotWarden](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@RobotWarden](https://discuss.elastic.co/u/RobotWarden)
#### Post date: [June 19, 2018, 3:26pm UTC](https://discuss.elastic.co/t/create-index-pattern-through-api/136148/6 "2018-06-19T15:26:03Z")

</div>

I was able to make an index pattern with some changes to my original curl statement:

```
curl -f -XPOST -H 'Content-Type: application/json' -H 'kbn-xsrf: anything' 'http://localhost:5601/api/saved_objects/index-pattern/test-*' '-d{"attributes":{"title":"test-*","timeFieldName":"@timestamp"}}'

```

This was fine for my purposes but I would prefer a json method of adding an index pattern if there is one?

---

<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: [July 17, 2018, 3:26pm UTC](https://discuss.elastic.co/t/create-index-pattern-through-api/136148/7 "2018-07-17T15:26:05Z")

</div>

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