completely overwrite _source elasticsearch-py

I am trying to take in a JSON block such that it completely overwrites an elasticsearch record. It seems to me that updates will add new keys if they don't exist, or overwrite them if they do, but it will not delete keys that aren't included in the update.

My users will send edited JSON that was the old _source field, so the easiest way to update would be to delete the old _source and use the new JSON as the full new _source. I get so far:

from elasticsearch import Elasticsearch

ES = Elasticsearch()

ES.update(index=ELASTIC_INDEX_NAME, doc_type=ELASTIC_EVENT_DOC_TYPE_NAME, id="44", body={"script": {"source": "ctx.op = 'delete'", "lang": "painless"}})
TransportError: TransportError(500, u'script_parse_exception', u'unexpected field [source]')

Also failed to just delete a key to see if I can do that at:

ES.update(index=ELASTIC_INDEX_NAME, doc_type=ELASTIC_EVENT_DOC_TYPE_NAME, id="33", body={"script": "ctx._source.remove('item_id')"})

RequestError: TransportError(400, u'illegal_argument_exception', u'[Ares][127.0.0.1:9300][indices:data/write/update[s]]')

Is there a way to completely overwrite an elasticsearch document with a new JSON document? Thank you

0 Comment

NO COMMENTS

LEAVE A REPLY

Captcha image