간단하게 타겟 index를 사용해 새로운 색인으로 만들 수 있다.
POST /_reindex
{
"source": {
"index": "your_source_index"
},
"dest": {
"index": "your_target_index"
}
}
remote 로 다른 클러스터의 색인도 reindex 가능하다.
먼저 elasticsearch.yml에 remote할 클러스터의 정보를 입력한다.
#elasticsearch.yml
reindex.remote.whitelist: "host:9200"
그리고 reindex를 다음과 같이 진행한다.
POST _reindex?wait_for_completion=false
{
"source": {
"remote": {
"host": "http://host:9200",
"username": "elastic",
"password": "my-password"
},
"index": "test1",
"size": 1000,
"query": {
"match_all": {
}
}
},
"dest": {
"index": "test2"
},
"max_docs": 5000
,"requests_per_second": 100
}
참고로 리프레시를 비활성화 해놓으면 색인을 보다 빠르게 할 수 있다.
PUT /my-index/_settings
{"index": {"refresh_interval": "-1" // 리프레시를 비활성화}}
PUT /my-index/_settings
{"index": { "refresh_interval": "1s" // 기본값으로 되돌리기}}
! 단, 비활성화 동안은 색인된 문서가 보이지 않는다.
GET _tasks?actions=*reindex&wait_for_completion=false&detailed
실행중인 모든 작업 취소하기
POST _tasks/_cancel
특정 작업 취소하기
reindex작업을 확인하면 task_id 알 수 있다.
POST _tasks/'task_id입력'/_cancel
참고) https://www.elastic.co/kr/blog/3-best-practices-for-using-and-troubleshooting-the-reindex-api