Reputation: 1659
How to perform a single field bulk update in elastic search. Currently, I am trying with helper function as follows,
from elasticsearch import Elasticsearch, helpers
for doc in collection_1:
try:
uid = int(doc["uid"])
k.append({
"_index": "col1",
"_type" : "col1",
"_id" : uid,
"_source": doc
})
except Exception as err:
print(err)
helpers.bulk(es, k)
E.S version: 2.4
Upvotes: 3
Views: 4822
Reputation: 674
You could use script for updating just required fields not all _source document
"script": {
"source": "ctx._source.datetime2=new Date((long)(ctx._source.creationDate+12600000));"
,"lang": "painless"
}
Upvotes: 0
Reputation: 1146
Please show your import and and your Elasticsearch version. Also your code is missing a reference to collection1
variable. If you want to use the bulk helpers, you shall follow the syntax described in the python bulk helpers documentation.
You shall specify a field _op_type
in your body and set it to update
and then pass your partial document.
Upvotes: 2