Elastisearch update by query

后端 未结 1 755
鱼传尺愫
鱼传尺愫 2021-01-17 21:11

I am using this code in python for updating my docs in elasticsearch. It\'s working fine but it\'s difficult to use it for a millions docs because I have to initialise the

1条回答
  •  离开以前
    2021-01-17 21:56

    Using the update_by_query (not the update) and the script, you should be able to update the documents that match your query.

     q = {
         "script": {
            "inline": "ctx._source.Device='Test'",
            "lang": "painless"
         },
         "query": {
            "match": {
                "Device": "Boiler"
            }
         }
    }
    
    es.update_by_query(body=q, doc_type='AAA', index='testindex')
    

    The above worked for me. The q finds the documents that match your query and the script updates the value using the _source of each document.

    I hope it works for you too, possibly with some adjustment on the query you want to use.

    0 讨论(0)
提交回复
热议问题