6.6: Kibana API: get object/create object not compatible, mark index pattern as default via API?

Hi there,

I'm playing around with the (relatively) new "saved objects" API and programmatically populating Kibana.

In 5.4 I used to dump the .kibana index and (re)create it. (Because there was no other way to populate Kibana besides the frontend - ugly, but it worked just good enough)

Under 6.6 I struggle for two reasons:

First: I can not use the create object api to (re-)import data generated with the get object api. I have to modify the exported data (drop id, updated_at, ...), there seems to be no way to import it otherwise.

Is this a known limitation and will be fixed in a future version? In my opinion the create object API should work with data exported by the get object API.

Second: If the imported index is the first one to be created I have still can't use it out of the box, because it seems to have to manually "star" the index pattern to set it as the default pattern.

Is there a way to set an index pattern as default pattern using the Kibana API?

Hi, can you share an example of an object that was retrieved with Get Object API, but can't be imported with the Create Object API? I agree that the output of get should be compatible with create.

It is not possible to set an index pattern as "default" through the saved object API, because that state is stored as a Kibana Advanced Setting (defaultIndex). That setting might be able to be updated through updating the corresponding .kibana doc, however.

Hi @jen-huang,

thank you for your answer and sorry for long silence on my side.

Here are the steps I tried:

  1. Extract the data: curl --silent -XGET "http://localhost:5601/api/saved_objects/index-pattern/my-pattern" -H 'kbn-xsrf: true' > my-pattern.json
  2. my-pattern.json looks like this:
    {
     "id": "my-pattern",
     "type": "index-pattern",
     "updated_at": "2019-02-12T15:23:06.871Z",
     "version": 6,
     "attributes": {
       "title": "dummy-*",
       "timeFieldName": "@timestamp",
       "fields": lots of field definitions goes here
     }
    }
    
  3. I try to reimport the JSON: curl --silent -XPUT "http://localhost:5601/api/saved_objects/index-pattern/my-pattern" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d @my-pattern.json
  4. I get the following response (reformated, because unfortunately there is no ?pretty (yet?))
    {
      "statusCode": 400,
      "error": "Bad Request",
      "message": "\"id\" is not allowed. \"type\" is not allowed. \"updated_at\" is not allowed. \"version\" is not allowed",
      "validation": {
    	"source": "payload",
    	"keys": [
    	  "id",
    	  "type",
    	  "updated_at",
    	  "version"
    	]
      }
    }
    
  5. I have to adjust the json file like this:
    {
     "attributes": {
       "title": "dummy-*",
       "timeFieldName": "@timestamp",
       "fields": lots of field definitions goes here
     }
    }
    
  6. Try again: curl --silent -XPUT "http://localhost:5601/api/saved_objects/index-pattern/my-pattern" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d @my-pattern.json
  7. This works:
     {
       "id": "my-pattern",
       "type": "index-pattern",
       "updated_at": "2019-02-27T15:03:36.691Z",
       "version": 7,
       "attributes": {
     	"title": "dummy-*",
     	"timeFieldName": "@timestamp",
     	"fields": lots of field definitions goes here
       }
     }   
    

Same goes for creating new patterns, same errors. I don't say this is wrong, because even the documentation says it is working as I described it.

It's just pain to me and I wanted to ask if

a) I'm doing something wrong (maybe using wrong API to fetch the objects in the first place?) and/or
b) we can expect changes on this in the (near - 7.0?) future?

Regarding to the default index. You wrote

It is not possible to set an index pattern as "default" through the saved object API, because that state is stored as a Kibana Advanced Setting ( defaultIndex ). That setting might be able to be updated through updating the corresponding .kibana doc, however.

Thank you for the heads up. I do it like this now:

curl --silent -XPOST "http://localhost:5601/api/kibana/settings/defaultIndex" -H "Content-Type: application/json" -H "kbn-xsrf: true" -d '{"value": "dummy-*"}'

Seems to work. Thank you!

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