我们可以在不为Elasticsearch指定文档ID的情况下进行批量更新吗?

2024-05-20 02:32:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我们可以在弹性搜索中进行批量更新而不指定文档ID吗。我无法在没有documentId的情况下进行批量更新,有没有办法通过queryby方法进行批量更新

length = len(test_final)
steps = 100
for i in range(0, length, steps):
    end_index = length-1 if i+steps>length else i+steps
    temp_list = test_final[i: end_index]
    bulk_file = ''
    actions = [{
        "_op_type": "update",
        "_index": "test_detail",
        "_type": "test_datas",
        "upsert": {
            {source['dataId']:{
                "test_value": int(test_data ['test_value'])
            }}
        },
        "script":{  "query": {
    "term": {
      "test_Id": test_data ['dataId']
    }

        }}}
        for test_data in temp_list
    ]
    helpers.bulk(es, actions)

Tags: intestactionsfordataindextypebulk