我想从elastic doc的嵌套结构中删除一个对象,这就是我的elastic doc在索引'submissions'中的样子。根据条件,我想从所有文档中删除一个对象。
{
"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(\u update \u by \u query)和ctx.\u 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
}
}
]
}
}
}
}
]
}
}
}
对此有什么见解吗?或者我有更好的方法吗?
1条答案
按热度按时间pb3skfrl1#
您可以按以下方式使用updatebyqueryapi
添加索引数据、Map和查询的工作示例
索引Map:
索引数据:
查询:
执行上述查询后,满足所有查询条件的文档。
"account_id": 2
以及"survey_id": 15
以及"answers.question_id": 142
,从具有question_id: 142
已删除。因此,从第一个文档(如上索引所示),包含
"answers.question_id": 142
现在文档包含以下数据(运行查询后)第二个文档不会有任何更改,因为它不满足所有查询条件。