【发布时间】:2021-12-31 10:25:08
【问题描述】:
{
"_index" : "test",
"_type" : "test",
"_id" : "1212",
"_version" : 5,
"found" : true,
"_source" : {
"count" : 42,
"list_data" : [ {
"list_id" : 11,
"timestamp" : 1469125397
}, {
"list_id" : 122,
"timestamp" : 1469050965
} ]
}
}
这是我的文档架构。list_data 是嵌套对象。我需要更新/删除list_data 中的特定文件。我可以使用 groovy 脚本更新 count 字段。
$ curl -XPOST 'localhost:9200/index/type/1212/_update?pretty' -d '
{
"script" : "ctx._source.count = 41"
}'
但不知道如何更新嵌套对象。
例如,我想将其添加到list_data。
{
"list_id" : 121,
"timestamp" : 1469050965
}
我的文档应该更改为:
{
"_index" : "test",
"_type" : "test",
"_id" : "1212",
"_version" : 6,
"found" : true,
"_source" : {
"count" : 41,
"list_data" : [ {
"list_id" : 11,
"timestamp" : 1469125397
}, {
"list_id" : 121,
"timestamp" : 1469050965
}, {
"list_id" : 122,
"timestamp" : 1469050965
} ]
}
}
如果我根据list_id = 122 执行删除,我的记录应该是这样的
{
"_index" : "test",
"_type" : "test",
"_id" : "1212",
"_version" : 7,
"found" : true,
"_source" : {
"count" : 41,
"list_data" : [ {
"list_id" : 11,
"timestamp" : 1469125397
}, {
"list_id" : 121,
"timestamp" : 1469050965
}]
}
}
【问题讨论】:
-
对于添加,这可能是一个更好的答案:stackoverflow.com/questions/42009778/…@Priyesh
标签: elasticsearch groovy