【发布时间】:2020-11-19 02:11:00
【问题描述】:
我想从弹性文档中的嵌套结构中删除一个对象, 这就是我的弹性文档在索引“提交”中的样子。 根据条件,我想从所有文档中删除一个对象。
{
"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"
}
]
}
}
]
}
}
我想试试 updateByQuery api ( _update_by_query ) 和 ctx._source.remove 查询
{
"query": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"match": {
"account_id": 2
}
},
{
"match": {
"survey_id": 15
}
}
]
}
},
{
"nested": {
"path": "answers",
"query": {
"bool": {
"must": [
{
"match": {
"answers.question_id": 142
}
}
]
}
}
}
}
]
}
}
}
对此有任何见解还是我有更好的方法?
【问题讨论】:
标签: elasticsearch elastic-stack