'remove an item using bulk update
I have an object with different values in Elasticsearch. When I want to update it, I use bulk api like below:
inventory_edition.append(
{
'_op_type': 'update',
'_index': value_index,
'_id': object['inventory.id'],
'_source': {'doc': object}
}
)
It update previous items whom I call them and also add new items but I dont know how to remove a previous item whom I'm not calling it! How can I remove a previous item in editing object using bulk api?
"hits" : [
{
"_index" : "index-name",
"_type" : "_doc",
"_id" : "list144bbfba447b9552ece89391d075",
"_score" : 1.2039728,
"_source" : {
"inventory.name" : "list1-edit",
"inventory.type" : "ip",
"inventory.description" : "description",
"inventory.id" : "list144bbfba447b9552ece89391d075"
}
}
]
Solution 1:[1]
I solved this way.. I used delete and create in bulk api instead of update.
inventory_edition.append(
{
'_op_type': 'delete',
'_index': value_index,
'_id': object['inventory.id'],
}
)
object[lablabla..] = lablabla..
inventory_edition.append(
{
'_op_type': 'create',
'_index': value_index,
'_id': object['inventory.id'],
'_source': object
}
)
self.es.remove_index(index = value_index)
self.es.check_index(value_index) // this function create new value_index
self.es.bulk_es(self.es.ES_CLIENT, inventory_edition)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shokouh Dareshiri |
