# Import a visualisation using API

**URL:** <https://discuss.elastic.co/t/import-a-visualisation-using-api/72488>\
**Category:** Kibana\
**Created:** [January 23, 2017, 2:01pm UTC](https://discuss.elastic.co/t/import-a-visualisation-using-api/72488 "2017-01-23T14:01:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen\_Pengilley](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Stephen\_Pengilley](https://discuss.elastic.co/u/Stephen_Pengilley)\
**Post date:** [January 23, 2017, 2:01pm UTC](https://discuss.elastic.co/t/import-a-visualisation-using-api/72488/1 "2017-01-23T14:01:26Z")

</div>

Hi all,

I have exported a visualisation in Kibana, using the export button under settings. This has given me a JSON file. The name of the visualisation is Transaction-count.

I have then deleted the visualisation from Kibana.

I would now like to import the visualisation back into Kibana using the API.

If I type  
curl -XPUT "[http://localhost:9200/.kibana/visualization/Transaction-count](http://localhost:9200/.kibana/visualization/Transaction-count)" -d I get the following error;

{"error":{"root\_cause":[{"type":"mapper\_parsing\_exception","reason":"failed to parse"}],"type":"mapper\_parsing\_exception","reason":"failed to parse","caused\_by":{"type":"not\_x\_content\_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"}}

If I manually import the visualisation via the web GUI, it works fine.

If I then type;  
curl XGET "[http://localhost:9200/.kibana/visualization/Transaction-count](http://localhost:9200/.kibana/visualization/Transaction-count)" it gives me the following JSON;

{"\_index":".kibana","\_type":"visualization","\_id":"Transaction-count","\_version":1,"found":true,"\_source":{"title":"Transaction count","visState":"{"title":"Transaction count","type":"metric","params":{"handleNoResults":true,"fontSize":"120"},"aggs":[{"id":"1","type":"count","schema":"metric","params":{}}],"listeners":{}}","uiStateJSON":"{}","description":"","savedSearchId":"Transactions","version":1,"kibanaSavedObjectMeta":{"searchSourceJSON":"{"filter":[]}"}}}

If I then type;  
curl -XGET "[http://localhost:9200/.kibana/visualization/Transaction-count](http://localhost:9200/.kibana/visualization/Transaction-count)" -d '{"\_index":".kibana","\_type":"visualization","\_id":"Transaction-count","\_version":1,"found":true,"\_source":{"title":"Transaction count","visState":"{"title":"Transaction count","type":"metric","params":{"handleNoResults":true,"fontSize":"120"},"aggs":[{"id":"1","type":"count","schema":"metric","params":{}}],"listeners":{}}","uiStateJSON":"{}","description":"","savedSearchId":"Transactions","version":1,"kibanaSavedObjectMeta":{"searchSourceJSON":"{"filter":[]}"}}}'

I receive the following output;

{"error":{"root\_cause":[{"type":"mapper\_parsing\_exception","reason":"Field [\_index] is a metadata field and cannot be added inside a document. Use the index API request parameters."}],"type":"mapper\_parsing\_exception","reason":"Field [\_index] is a metadata field and cannot be added inside a document. Use the index API request parameters."},"status":400}

Running version 2.3.3 of Elastic and 4.5.1 of Kibana

What am I doing wrong?

---

<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:** [January 24, 2017, 3:05am UTC](https://discuss.elastic.co/t/import-a-visualisation-using-api/72488/2 "2017-01-24T03:05:38Z")

</div>

If you are looking to manually import, your going to need manipulate the request to Elasticsearch a bit.

The export looks something like this:

```json
[
  {
    "_id": "My-New-Visualization",
    "_type": "visualization",
    "_source": {
      "title": "My New Visualization",
      "visState": "{...}",
      "uiStateJSON": "{}",
      "description": "",
      "savedSearchId": "Kibana",
      "version": 1,
      "kibanaSavedObjectMeta": {
        "searchSourceJSON": "{\"filter\":[]}"
      }
    }
  }
]

```

To index this document, you would need to extract the contents of `_source` and create a document with the id containing the old document id (`_id`).

This leaves me with an updated JSON file (`my-viz.json`) containing:

```json
{
  "title": "My New Visualization",
  "visState": "{...}",
  "uiStateJSON": "{}",
  "description": "",
  "savedSearchId": "Kibana",
  "version": 1,
  "kibanaSavedObjectMeta": {
    "searchSourceJSON": "{\"filter\":[]}"
  }
}

```

Now I just need to index that file.

`curl -X PUT --data @my-viz.json 'http://localhost:9200/.kibana/visualization/My-New-Visualization'`

If you are going to be automatic this, it would be best to use your programming language of choice and parse the export, then using the [bulk API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html) to insert all visualizations at once.

---

<div class="post-metadata">

**Author:** ![Stephen\_Pengilley](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Stephen\_Pengilley](https://discuss.elastic.co/u/Stephen_Pengilley)\
**Post date:** [January 24, 2017, 9:07am UTC](https://discuss.elastic.co/t/import-a-visualisation-using-api/72488/3 "2017-01-24T09:07:11Z")

</div>

Hey Tyler,

Thanks for coming back to me. I appreciate your help.

It looks like the long term solution would definitely be to parse the JSON and make the required amendments.

Many thanks  
Stephen

---

<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:** [February 21, 2017, 9:07am UTC](https://discuss.elastic.co/t/import-a-visualisation-using-api/72488/4 "2017-02-21T09:07:38Z")

</div>

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