Updating doc using update API

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.


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.


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.


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


Thank you for the reply!

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