I need to delete a particular attribute from all documents in ElasticSearch. Is there a way to do it and can it be done via Bulk API. I am unable to find an API to Bulk Delete an attribute from ElasticSearch.
Is there any way to achieve the same.
Sample part of my document:
{
"media": {
"list1": [
{"title":"a"}
],
"list2": [
{"title":"b"}
]
}
}
Script to delete the same :
{
"script": "ctx._source.remove('media.list1')",
"query": {
"bool": {
"must": [
{
"exists": {
"field": "media.list1"
}
}
]
}
}
}
If you are looking to just delete a field from the doc (rather than deleting the entire doc), you need to use a painless script. See this question post as reference for writing a script to delete a field from a document.
To update all docs in an index, put the painless script to remove a field inside an Update By Query API, using a match_all as the 'query' to update all documents.
You wouldn't want to use Bulk API for this. Bulk API would be used if you wanted to replace entire documents (update) with new information.
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