我想将新文档与现有文档合并。我现有的文件如下:
{
"_source": {
"name": "xxx",
"recall": [
{
"title": "xxx-a",
"date": "2020-12-10"
"otherB": "abc"
}
]
}
}
新插入的文件如下:
{
"_source": {
"name": "xxx",
"recall": [
{
"title": "xxx-b",
"date": "2021-12-10"
"otherB": "abcd"
}
]
}
}
我要输出如下:
{
"_source": {
"name": "xxx",
"recall": [
{
"title": "xxx-a",
"date": "2020-12-10"
"otherB": "abc"
},
{
"title": "xxx-b",
"date": "2021-12-10"
"otherB": "abcd"
}
]
}
}
我使用logstash将数据加载到ES。我现在的剧本是:
script_lang => "painless"
script =>"if (ctx._source.containsKey('recall'))ctx._source.recall.addAll(params.event.recall);}"
但是它给了我这个输出,它将插入的文档追加到现有的而不是合并:
{
"_source": {
"name": "xxx",
"recall": [
{
"title": "xxx-a",
"date": "2020-12-10"
"otherB": "abc"
},
[
{
"title": "xxx-b",
"date": "2021-12-10"
"otherB": "abcd"
}
]
]
}
}
发布于 2022-10-24 23:43:35
您只需将脚本更改为:
script =>"if (ctx._source.containsKey('recall'))ctx._source.recall.addAll(Arrays.asList(params.event.recall));}"
https://stackoverflow.com/questions/74184340
复制相似问题