I tried to upsert a document to Opensearch, that means if no id exists it would insert the document, if the id already exists then it would update the document(not overwritten).
For example, if the doc already in Opensearch {"id":1,"name":"Jack"}, when I upserted {"id":1,"job":"engineer"}, the document in opensearch would become {"id":1,"name":"Jack","job":"engineer"}, not just overwritten.
I tried python index api with doc_as_upsert as following, but it failed:
pyClient.index(
index = indexName,
body = document,
id = document['id'],
refresh = True,
doc_as_upsert = True
)
The document object is: {"id":"123","name":"Jack","job":"Engineer"}
index, you should use the update methoddoc_as_upsert incorrectly. The documentation for the update function highlights that fact.The correct way to pass it would be:
document = {"id":1,"job":"engineer"}
body = {"doc": document, "doc_as_upsert": True}
pyClient.update(
index = indexName,
body = body,
id = document['id'],
refresh = True
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With