es操作同一個索引里數據的複製語法 複製數據: POST _reindex { "source": { "index": "source_index" }, "dest": { "index": "destination_index" } } 欄位值修改: POST source_index/_up ...
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'" } }