티스토리 뷰

정말 오랜만에 Elasticsearch 관련 글을 쓰는 것 같다.

 

데이터를 생성하는 모델이 변경되어서 기존 데이터를 싹 마이그레이션 할 일이 생겼다.

 

가장 편한건 데이터를 싹 만들어두고 서버가 보는 index를 변경하는 것이었지만, 그럼 서버의 재배포가 필요하다.

 

그래서 그냥 index를 새로하나 만들고 두 index를 교체하는 방식으로 작업을 진행하려고 했다.

 

불행하게도 두 index를 교체하는 방식은 따로 제공하지 않았고, copy to 하는 형식의 reindex를 제공했다.

 

사용법은 간단하다.

POST _reindex
{
  "source": {
    "index": "from index"
  },
  "dest": {
    "index": "to index"
  }
}

이렇게 요청했을 때 바로 동작했으면 참 좋았겠지만, 으레 그렇듯 바로 되는 일이 없다.

{
  "error": {
    "root_cause": [
      {
        "type": "es_rejected_execution_exception",
        "reason": "rejected execution of coordinating operation [coordinating_and_primary_bytes=0, replica_bytes=0, all_bytes=0, coordinating_operation_bytes=57217088, max_coordinating_and_primary_bytes=53687091]"
      }
    ],
    "type": "es_rejected_execution_exception",
    "reason": "rejected execution of coordinating operation [coordinating_and_primary_bytes=0, replica_bytes=0, all_bytes=0, coordinating_operation_bytes=57217088, max_coordinating_and_primary_bytes=53687091]"
  },
  "status": 429
}

에러 메시지 자체는 잘 이해가 안된다. 그리고 데이터량이 많지는 않아서 왜 이런 문제가 발생했는지 알기 어려웠다. 

 

하지만 status code가 429면 Too Many Request 에러다.

 

그래서 짧은 시간에 너무 많은 요청을 보냈기 때문에 발생한 에러라고 추리할 수 있었다.

 

해결법은 요청을 나눠서 천천히 보내게끔 하면 된다.

POST _reindex
{
  "source": {
    "index": "from index",
    "size": 100 // 예시로 100 문서씩 처리
    
  },
  "dest": {
    "index": "to index"
  }
}

size로 청크를 나눠서 보내게끔 하면, 에러 없이 reindex가 잘 동작한다

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함