我想將新檔案合并到現有檔案。我現有的檔案是這樣的:
{
"_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"
}
]
]
}
}
uj5u.com熱心網友回復:
您只需要將腳本更改為:
script =>"if (ctx._source.containsKey('recall'))ctx._source.recall.addAll(Arrays.asList(params.event.recall));}"
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/525337.html
標籤:弹性搜索日志存储数组合并
