es操作同一個索引里資料的復制語法
復制資料:
POST _reindex { "source": { "index": "source_index" }, "dest": { "index": "destination_index" } }
欄位值修改:
POST source_index/_update_by_query { "script": { "source": "ctx._source.field_name = 'new_value'" }, "query": { "match": { "field_name": "old_value" } } }
可以通過在 source 中添加 query 來設定條件,只有滿足條件的檔案才會被復制到目標索引中,例如:
POST _reindex { "source": { "index": "source_index", "query": { "match": { "field_name": "value" } } }, "dest": { "index": "destination_index" } }
上述代碼將只復制 source_index 中 field_name 欄位值為 value 的檔案到 destination_index 中,
可以在復制資料時使用腳本來修改欄位的值,將修改后的值寫入目標索引中,例如:
POST _reindex { "source": { "index": "source_index" }, "dest": { "index": "destination_index" }, "script": { "source": "ctx._source.field_name = 'new_value'" } }
上述代碼將復制 source_index 中的所有檔案到 destination_index 中,并將其中的 field_name 欄位值修改為 new_value,如果需要對特定的檔案進行修改,可以在 source 中添加 query 條件來指定,
例:在同一個索引下復制并設定欄位新值
POST _reindex { "source": { "index": "source_index", "query": { "match": { "field_name": "value" } } }, "dest": { "index": "source_index" }, "script": { "source": "ctx._source.field_name = 'new_value'" } }
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/554825.html
標籤:大數據
上一篇:Hadoop的完全分布式搭建
下一篇:返回列表
