1

I am implementing ElasticSearch 7.1.1 in my application using Python requests library. I have successfully created a document in the elastic index using

r = requests.put(url, auth=awsauth, json=document, headers=headers)

However, while updating an existing document, the JSON body(containing to be updated values) that I pass to the method, replaces the original document. How do I overcome this? Thank you.

1
  • 1
    You need to write python equivalent for update api. Commented Oct 22, 2019 at 6:53

1 Answer 1

3

You could do the following:

document = {
    "doc": {
        "field_1": "value_1",
        "field_2": "value_2"
    },
    "doc_as_upsert": True
}

...
r = requests.post(url, auth=awsauth, json=document, headers=headers)
  1. It should be POST instead of PUT
  2. You can update existing fields and also add new fields.

Refer the doc in the comment posted by Nishant Saini.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.