在Elasticsearch中删除嵌套数组 [英] Delete nested array in elasticsearch
问题描述
我有以下格式的包含嵌套表的文档:
I have documents containing nested tables in the following format :
{
"dataId": "dataIdentifier",
"versionId": "versionIdentifier",
"items": [
{
"obj1": "value1",
"obj2": "value2",
"obj3": "value3",
},
{
"obj1": "value4",
"obj2": "value5",
"obj3": "value6"
},
{
"obj1": "value7",
"obj2": "value8",
"obj3": "value9"
}
]
}
项目"为嵌套类型.我要删除给定的项目"中的元素之一,而不是其中的对象之一具有特定值.例如:
With "items" being of nested type. I want to delete one of the elements inside the "items" given than one of the object inside has a certain value. For instance it would be :
if (obj1 == "value4" & dataId == "dataIdentifier" & versionId == versionIdentifier) :
DELETE TABLE ENTRY
在这种情况下,我想删除"items"的第二个条目.我尝试使用 update_by_query 来做到这一点,而我的尝试是:
In this case I want to delete the second entry of "items". I tried to do it with update_by_query, and my attempt was :
q = {
"query": {
"match_all": {}
}
},
"script": {
"lang" : "painless",
"inline" : {if (ctx._source.dataId == item.dataId && ctx._source.versionId == item.versionId && ctx._source.items.obj1 == item.obj1) {ctx._source.items.remove()}}",
"params" : {
'dataFrame': [{
"dataId" : 'myDataIdList',
"versionId" : 'myVersionId',
"obj1" : 'myValue'
} ]
}
}
}
es.update_by_query(index=myindex, body=q)
但是我不知道如何在"ctx._source.items.remove()"参数中指定相关条目.我看了一下Elasticsearch文档,但找不到我想要的东西.任何帮助将不胜感激.
But I do not know how to designate the concerned entry in the "ctx._source.items.remove()" argument. I took a look at the Elasticsearch documentation but could not find what I was looking for. Any help would be greatly appreciated.
推荐答案
通过查询更新不能删除字段",可以替换它,为此,可以用其他两个值更新它想保留或删除文档,并使用这两个值对新索引编制索引
With update by query you can't remove "a field", you can replace it, for that, you can update it with others two values you want to mantain or delete the document and index a new with that two values
这篇关于在Elasticsearch中删除嵌套数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!