Skip to content

Instantly share code, notes, and snippets.

@julie-mills
Last active January 25, 2024 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julie-mills/d64019542768baad2825e2f9c6bf94e6 to your computer and use it in GitHub Desktop.
Save julie-mills/d64019542768baad2825e2f9c6bf94e6 to your computer and use it in GitHub Desktop.
from elasticsearch import Elasticsearch
# Connect to Elasticsearch
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
# Index name and document ID
index_name = "your_index"
document_id = "1"
# Retrieve the existing document
existing_document = es.get(index=index_name, id=document_id)
# Make your changes to the document
existing_document["_source"]["field1"] = "new_value1"
existing_document["_source"]["field2"] = "new_value2"
# Call the index API to perform the full update
es.index(index=index_name, id=document_id, body=existing_document["_source"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment