我在 elasticsearch 中有一個檔案是這樣的:
{
"_index": "user",
"_type": "_doc",
"_id": "20",
"_score": 1,
"_source": {
"id": "20",
"gender": null,
"uuid": "68de0b74-cdf6-4e21-a046-6876e569e4e3",
"first_name": null,
"last_name": null,
"nick_name": null,
"email": null,
"country_code": "98",
"mobile": "9xxx7",
"password": null,
"old_password": null,
"birthdate": null,
"email_verified_at": null,
"created_at": null,
"updated_at": null,
"deleted_at": null,
"old_data": null,
"devices": [
{
"updated_at": "2021-12-14T12:11:26.000000Z",
"serial": "sr_31",
"vendor": "folan",
"created_at": "2021-12-14T12:11:26.000000Z",
"model": "device_model",
"id": 4,
"device_app": {
"device_id": 4,
"updated_at": "2021-12-14T12:11:26.000000Z",
"created_at": "2021-12-14T12:11:26.000000Z",
"id": 4,
"uuid": "f60f7df0-5cd6-11ec-b71d-bdfd039f50b3"
},
"uuid": "f60a2ae0-5cd6-11ec-81cb-0128d6059ef1"
},
{
"updated_at": "2021-12-14T12:13:07.000000Z",
"serial": "sr_32",
"vendor": "folan",
"created_at": "2021-12-14T12:13:07.000000Z",
"model": "device_model",
"id": 5,
"device_app": {
"device_id": 5,
"updated_at": "2021-12-14T12:13:07.000000Z",
"created_at": "2021-12-14T12:13:07.000000Z",
"id": 5,
"uuid": "32481b80-5cd7-11ec-ba02-c33a09f165eb"
},
"uuid": "3242f860-5cd7-11ec-9d54-c3339177d9bb"
}
]
}
}
如您所見,我有一個名為的欄位devices,它是一個物件陣列。我想洗掉它的第一個元素不是通過選擇陣列的索引號而是通過陣列的內容,這意味著**我想給腳本一個serial欄位(每個設備都是唯一的)并洗掉整個物件對應的物件。
比方說,我想要一些輸入,sr_31而輸出將是這樣的(僅sr_31省略了物件 containsgin ):
{
"_index": "user",
"_type": "_doc",
"_id": "20",
"_score": 1,
"_source": {
"id": "20",
"gender": null,
"uuid": "68de0b74-cdf6-4e21-a046-6876e569e4e3",
"first_name": null,
"last_name": null,
"nick_name": null,
"email": null,
"country_code": "98",
"mobile": "9xxx7",
"password": null,
"old_password": null,
"birthdate": null,
"email_verified_at": null,
"created_at": null,
"updated_at": null,
"deleted_at": null,
"old_data": null,
"devices": [
{
"updated_at": "2021-12-14T12:13:07.000000Z",
"serial": "sr_32",
"vendor": "folan",
"created_at": "2021-12-14T12:13:07.000000Z",
"model": "device_model",
"id": 5,
"device_app": {
"device_id": 5,
"updated_at": "2021-12-14T12:13:07.000000Z",
"created_at": "2021-12-14T12:13:07.000000Z",
"id": 5,
"uuid": "32481b80-5cd7-11ec-ba02-c33a09f165eb"
},
"uuid": "3242f860-5cd7-11ec-9d54-c3339177d9bb"
}
]
}
}
我已經閱讀了更新檔案的檔案,但似乎沒有這種情況的例子。
uj5u.com熱心網友回復:
你需要的是這樣的:
POST index/_doc/20/_update
{
"script": {
"lang": "painless",
"source": "ctx._source.devices.removeIf(device -> device.id == 'sr_31')"
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/384124.html
標籤:弹性搜索
上一篇:Drfhowto:simple-jwtauthenticationwithouttheUSERNAME_FIELD
下一篇:使用Dlog4j2.formatMsgNoLookups臨時修復elasticsearchhelmchart中的log4j
