0
我有以下文件:彈性搜索部分更新嵌套文件
{
{
"_index": "demo_processinglog",
"_type": "status",
"_id": "1498130124024a",
"_score": 1,
"_source": {
"startTime": 1411230604024,
"clientName": "fastlog",
"projectName": "demo",
"sourcePath": "/nfs/clients/client1/projects/project1/",
"sourceFiles": [
{
"sourceFile": "/nfs/clients/client1/projects/project1/Readme.txt",
"fileSize": 3563
"status": "123"
},
{
"sourceFile": "/nfs/clients/client1/projects/project1/XML/data.xml",
"fileSize": 51893940,
"status": 234
},
{
"sourceFile": "/nfs/clients/client1/projects/project1/XML/data2.xml",
"fileSize": 1665,
"status": 345
},
{
"sourceFile": "/nfs/clients/client1/projects/project1/XML/data3.xml",
"fileSize": 5799680,
"status": 456
}
]
}
}
我想要做的就是更新一個特定的源文件的狀態字段。我嘗試使用「_update」端點進行更新,但是如果我嘗試僅更新源文件的「狀態」字段:
「sourceFile」:「/ nfs/clients/client1/projects/project1/Readme.txt「
它刪除」sourceFiles「數組中的所有內容。我如何只更新特定「sourceFile」的狀態字段並保持其他數據不變?我也嘗試使用「doc_as_upsert」選項進行更新,它仍然刪除了其他所有內容。
UPDATE
我只是綁住下面的腳本,它運行,但沒有被更新:
{
"script": "for (int i = 0; i < ctx._source.sourceFiles.size(); i ++) {if (ctx._source.sourceFiles[ i ].fileName == params.sourceFile) {ctx._source.sourceFiles[ i ].status = params.status;} }",
"lang": "painless",
"params": {
"status": "completed",
"sourceFile": "/nfs/clients/client1/projects/project1/Readme.txt"
}
}
謝謝!