Last active
January 25, 2024 16:51
-
-
Save julie-mills/d64019542768baad2825e2f9c6bf94e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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