第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用 python 進(jìn)行 Elastic Search 批量更新,如何使用新數(shù)據(jù)追加數(shù)組字段

使用 python 進(jìn)行 Elastic Search 批量更新,如何使用新數(shù)據(jù)追加數(shù)組字段

慕的地6264312 2023-10-26 15:14:59
如何使用 python 中的bulkupdate 更新彈性搜索中的字段。我嘗試了很多方法,但都出錯(cuò)了。在某些情況下,我收到文檔丟失錯(cuò)誤,如何同時(shí)更新和更新插入。而且附加到字段也不起作用。elasticsearch==7.9.1 是我在 python 中使用的包for i in range(0, length, steps):    end_index = length-1 if i+steps>length else i+steps    temp_list = test_data[i: end_index]    bulk_file = ''    actions = [{        "_index": "test-data",        "_opt_type":"update",        "_type": "test-test-data",        "_id": test_row ['testId'],        "doc":{"script": {                          "source": "ctx._source.DataIds.add(params.DataIds)",                          "lang": "painless",                          "params": {                              "DataIds":test_row ['DataIds']                          }                      }}        }        for test_row in temp_list    ]    helpers.bulk(es, actions)我得到的錯(cuò)誤是這樣的    {'update': {'_index': 'test-data', '_type': 'products', '_id': '333', 'status': 400, 'error': {'type': 'illegal_argument_exception', 'reason': 'failed to execute script', 'caused_by': {'type': 'script_exception', 'reason': 'runtime error', 'script_stack': ['ctx._source.dataIds.add(params.dataIds)', '    ^---- HERE'], 'script': 'if (ctx._source.dataIds == null) { ctx._source.dataIds = []; } ctx._source.dataIds.add(params.dataIds)', 'lang': 'painless', 'position': {'offset': 105, 'start': 71, 'end': 118}, 'caused_by': {'type': 'illegal_argument_exception', 'reason': 'dynamic method [java.lang.String, add/1] not found'}}}, 'data': {'upsert': {}, 'scripted_upsert': True, 'script': {'source': 'if (ctx._source.dataIds == null) { ctx._source.dataIds = []; } ctx._source.dataIds.add(params.dataIds)', 'lang': 'painless', 'params': {'cdataIds': 'set123'}}}}}])
查看完整描述

1 回答

?
侃侃無(wú)極

TA貢獻(xiàn)2051條經(jīng)驗(yàn) 獲得超10個(gè)贊

upsert通過(guò)腳本的正確方法是不使用該部分,doc而僅使用該script部分。upsert如果您想在同一命令中更新插入和更新,您還需要該部分。事情是這樣的:

actions = [{

? ? "_op_type":"update",

? ? "_index": "test-data",

? ? "_type": "test-test-data",

? ? "_id": test_row ['testId'],

? ? "upsert": {

? ? ? ?"DataIds": test_row ['DataIds']

? ? },

? ? "script": {

? ? ? ? "source": "ctx._source.DataIds.add(params.DataIds)",

? ? ? ? "lang": "painless",

? ? ? ? "params": {

? ? ? ? ? ?"DataIds":test_row ['DataIds']

? ? ? ? }

? ? }

} for test_row in temp_list

]

另一種方法是使用scripted_upsert

actions = [{

? ? "_op_type":"update",

? ? "_index": "test-data",

? ? "_type": "test-test-data",

? ? "_id": test_row ['testId'],

? ? "upsert": {},

? ? "scripted_upsert": true,

? ? "script": {

? ? ? ? "source": "if (ctx._source.DataIds == null) { ctx._source.DataIds = []; } ctx._source.DataIds.add(params.DataIds)",

? ? ? ? "lang": "painless",

? ? ? ? "params": {

? ? ? ? ? ?"DataIds":test_row ['DataIds']

? ? ? ? }

? ? }

} for test_row in temp_list

]


查看完整回答
反對(duì) 回復(fù) 2023-10-26
  • 1 回答
  • 0 關(guān)注
  • 178 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)