I tried the typical _update method in elastic, which isn't working.
data_to_send ={
"new_key1": new_value1,
"new_key2": new_value2,
"new_key3": new_value3
}
response = requests.post(
url=f"https://{elasticurl}:{port}/{target_index}/_update/{id}",
headers={'Content-Type': 'application/json'},
json=data_to_send,
verify=False,
auth = (user,password))
the url is double checked and id is the document id used to identify the document to update. The key doubt here is what happens to the doc when we send data_to_send to the url, does the document accept the new key-value pairs? Documentation doesn't address the issue of inserting a new key-value pairs into an existing document, it only talks about updating values of existing keys.
I have also tried requests.put, elasticsearch.update both of them doesn't seem to work while trying to insert new key-value pairs into existing document. I need some way to insert new key-value pairs into existing doc using the document id in elastic.
You can refer this documentation and as it is mentioned, document should pass inside doc
for partial update.
POST test/type1/1/_update
{
"doc" : {
"name" : "new_name"
}
}
I am not expert in python but data_to_send
should change as below and it should work:
data_to_send ={
"doc" : {
"new_key1": new_value1,
"new_key2": new_value2,
"new_key3": new_value3
}
}