To delete any field with value from all the documents without deleting the whole document from the Elasticsearch index usually I use _update_by_query
API call with script
For Ex: on my_properties index I want to delete all the fields e.g (key=>value) from all the documents where it exists. Using below query I'm able to delete all the feed field where it is exists but it this case the feed field is text/string type
Index: my_properties
Field: feed
Type: text
Example Value on feed: feed: ["AB-1234"]
POST my_properties/_update_by_query?refresh&conflicts=proceed
{
"script" : "ctx._source.remove('feed')",
"query" : {
"exists": { "field": "feed" }
}
}
My main problem is when my field type is nested instead of text/string
Index: my_properties
Field: feed_v2
Type: nested
Example Value on feed_v2: feed_v2: [{"feed":12},{"id":["AB-9999"]}]
Approach 1:
POST my_properties/_update_by_query?refresh&conflicts=proceed
{
"script" : "ctx._source.remove('feed_v2')",
"query" : {
"exists": { "field": "feed_v2" }
}
}
Approach 2:
POST my_properties/_update_by_query?refresh&conflicts=proceed
{
"script" : "ctx._source.feed_v2.remove('feed')",
"query" : {
"exists": { "field": "feed_v2.feed" }
}
}
Nothing works, Am I missing something? Not sure but my guess is-
"query" : {"exists": { "field": "feed_v2" }}
query exists doesn't work same way with nested type field that's why it doesn't find anything while trying delete on
nested
type field
As per the Ref: https://stackoverflow.com/a/53771354/1138192 It should work for me but alas it doesn't work for me.