重建索引要求爲源索引中的全部文檔啓用
_source
。
重建索引不會嘗試設置目標索引,它不會複製源索引的設置,你應該在運行
_reindex
操做以前設置目標索引,包括設置映射、碎片數、副本等。
_reindex
的最基本形式只是將文檔從一個索引複製到另外一個索引,這會將twitter
索引中的文檔複製到new_twitter
索引中:併發
POST _reindex { "source": { "index": "twitter" }, "dest": { "index": "new_twitter" } }
這將返回以下內容:oop
{ "took" : 147, "timed_out": false, "created": 120, "updated": 0, "deleted": 0, "batches": 1, "version_conflicts": 0, "noops": 0, "retries": { "bulk": 0, "search": 0 }, "throttled_millis": 0, "requests_per_second": -1.0, "throttled_until_millis": 0, "total": 120, "failures" : [ ] }
就像_update_by_query
同樣,_reindex
獲取源索引的快照,但其目標必須是不一樣的索引,所以版本衝突不太可能,dest
元素能夠像索引API同樣配置,以控制樂觀併發控制。只是省略version_type
(如上所述)或將其設置爲internal
將致使Elasticsearch盲目地將文檔轉儲到目標中,覆蓋任何碰巧具備相同類型和id
的文檔:code
POST _reindex { "source": { "index": "twitter" }, "dest": { "index": "new_twitter", "version_type": "internal" } }
將version_type
設置爲external
將致使Elasticsearch保留源中的version
,建立缺乏的任何文檔,並更新目標索引中具備舊版本的文檔而不是源索引中的任何文檔:索引
POST _reindex { "source": { "index": "twitter" }, "dest": { "index": "new_twitter", "version_type": "external" } }
設置op_type
爲create
將致使_reindex
僅在目標索引中建立缺乏的文檔,全部現有文檔都會致使版本衝突:進程
POST _reindex { "source": { "index": "twitter" }, "dest": { "index": "new_twitter", "op_type": "create" } }
默認狀況下,版本衝突會停止_reindex
進程,但你能夠在請求體中設置"conflicts": "proceed"
便可計算:文檔
POST _reindex { "conflicts": "proceed", "source": { "index": "twitter" }, "dest": { "index": "new_twitter", "op_type": "create" } }
你能夠經過向source
添加類型或添加查詢來限制文檔,這個只會將kimchy
寫的推文複製到new_twitter
中:requests
POST _reindex { "source": { "index": "twitter", "type": "_doc", "query": { "term": { "user": "kimchy" } } }, "dest": { "index": "new_twitter" } }