I want to remove an object from a nested structure in elastic doc, This is how my elastic doc looks like in the index 'submissions'. Based on the conditions I want to remove an object from all the documents.
{
"took": 21,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 11,
"max_score": 1,
"hits": [
{
"_index": "submissions",
"_type": "_doc",
"_id": "15_12069",
"_score": 1,
"_source": {
"id": "15_12069",
"account_id": 2,
"survey_id": 15,
"submission_id": 12069,
"answers": [
{
"question_id": 142, //
"skipped": false, //<------ remove object with question_id: 142
"answer_txt": "product" //
},
{
"question_id": 153,
"skipped": false,
"answer_txt": "happy"
}
]
}
},
{
"_index": "submissions",
"_type": "_doc",
"_id": "15_12073",
"_score": 1,
"_source": {
"id": "15_12073",
"account_id": 2,
"survey_id": 15,
"submission_id": 12073,
"answers": [
{
"question_id": 142, //
"skipped": false, //<------ remove object with question_id: 142
"answer_txt": "coherent" //
},
{
"question_id": 153,
"skipped": false,
"answer_txt": "cool"
}
]
}
}
]
}
}
I wanted to try updateByQuery api ( _update_by_query ) and ctx._source.remove with query
{
"query": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"match": {
"account_id": 2
}
},
{
"match": {
"survey_id": 15
}
}
]
}
},
{
"nested": {
"path": "answers",
"query": {
"bool": {
"must": [
{
"match": {
"answers.question_id": 142
}
}
]
}
}
}
}
]
}
}
}
Any insight on this or do i have a better approach?