# Updating doc using update API

**URL:** <https://discuss.elastic.co/t/updating-doc-using-update-api/177858>\
**Category:** Elasticsearch\
**Created:** [April 22, 2019, 1:53pm UTC](https://discuss.elastic.co/t/updating-doc-using-update-api/177858 "2019-04-22T13:53:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gued](https://avatars.discourse-cdn.com/v4/letter/g/ecae2f/32.png) [@gued](https://discuss.elastic.co/u/gued)\
**Post date:** [April 22, 2019, 1:53pm UTC](https://discuss.elastic.co/t/updating-doc-using-update-api/177858/1 "2019-04-22T13:53:43Z")

</div>

Hello. I am trying to append a list inside Elasticsearch using the python API. However the data incoming is in JSON-format. My query can take a single string item such as 'Blue' or 'Gimli: Dwarf' however it throws an exception when trying to insert JSON objects to the list.

The existing document is formatted as: `content: [<list>]`.

My query is: `''' {"script": {"source": "ctx._source.content.add(params.tag)", "lang": "painless", "params": {"tag": "%s"}} } ''' % doc`

The exception thrown is: `'RequestError(400, 'x_content_parse_exception', '[4:31] [script] failed to parse field [params]')'`. This is thrown when the doc variable is '{"Gandalf": "Wizard"}'.

The real data is logging output, but our structure is currently around appending these to a list that can later be parsed. I wish to use the update API to minimize network costs and the need to retrieve and then reindex a doc.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [April 23, 2019, 7:37am UTC](https://discuss.elastic.co/t/updating-doc-using-update-api/177858/2 "2019-04-23T07:37:05Z")

</div>

Hi,

Can you try with "Gandalf: Wizard" as in your first example with 'Gimli:Dwarf'.  
With {"Gandalf": "Wizard"} you send a dict instead of a string.

---

<div class="post-metadata">

**Author:** ![gued](https://avatars.discourse-cdn.com/v4/letter/g/ecae2f/32.png) [@gued](https://discuss.elastic.co/u/gued)\
**Post date:** [April 23, 2019, 3:45pm UTC](https://discuss.elastic.co/t/updating-doc-using-update-api/177858/3 "2019-04-23T15:45:44Z")

</div>

Hello.

Inserting `"Gandalf: Wizard"` works. The real data inserted is in dict-format, which is why I want to send it in. Making the dict to a string works, but in some cases doesn't. I believe this is due to, for example `serverHost.exe -k -f` values disturbs Elasticsearch's parsing.

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [April 24, 2019, 2:09am UTC](https://discuss.elastic.co/t/updating-doc-using-update-api/177858/4 "2019-04-24T02:09:21Z")

</div>

Hi,

You can try to use ingest to parse your data and check if it's dict format you can force format to string.

[https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html)

---

<div class="post-metadata">

**Author:** ![gued](https://avatars.discourse-cdn.com/v4/letter/g/ecae2f/32.png) [@gued](https://discuss.elastic.co/u/gued)\
**Post date:** [April 24, 2019, 12:47pm UTC](https://discuss.elastic.co/t/updating-doc-using-update-api/177858/5 "2019-04-24T12:47:04Z")

</div>

Thank you for the reply!

---

<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:** [May 22, 2019, 12:47pm UTC](https://discuss.elastic.co/t/updating-doc-using-update-api/177858/6 "2019-05-22T12:47:07Z")

</div>

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