Elasticsearch 參考指南(Reindex API)

Reindex API

重建索引要求爲源索引中的全部文檔啓用 _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_typecreate將致使_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"
  }
}
相關文章
相關標籤/搜索