Create Index_Pattern through API

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]. \"{"version":1,&quot:attributes&quot:;{"title":"test-*"}\" is not allowed","validation":{"source":"payload","key":["attributes","{"version":1,"attributes":{"title":"test-*"}}"]}}

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.

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.


	“_id”: “Test”,
	“_type”: “search”,
	“_source”: {
		“title”: “Test Search”
		“description”: “”,
		“hits”: 0,
		“columns”: [
		"sort": [
		"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?

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.

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?

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?

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