elasticsearch 7.6.2 delete by query 사용시 search_phase_execution_exception 오류 발생

오류 증상

Delete By Query를 이용하여 문서를 삭제 하던 중 아래와 같은 에러가 발생

elasticsearch version : 7.6.2

{
  "error": {
    "root_cause": [
      {
        "type": "exception",
        "reason": "Trying to create too many scroll contexts. Must be less than or equal to: [500]. This limit can be set by changing the [search.max_open_scroll_context] setting."
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "Partial shards failure",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 2,
        "index": "product",
        "node": "vot-mThQS46c5aBtTd1RwA",
        "reason": {
          "type": "exception",
          "reason": "Trying to create too many scroll contexts. Must be less than or equal to: [500]. This limit can be set by changing the [search.max_open_scroll_context] setting."
        }
      }
    ]
  },
  "status": 500
}

오류 원인

정확한 원인은 알 수 없으나 github elasticsearch 에 버그로 리포팅된 issue를 발견 github
문제점이 elasticsearch 데몬을 기동 하자 마자 발생하는게 아니라 정상 동작 후 어느 순간에 도달하면 발생하는 버그라 elasticsearch에 delete by query 를 동작하는 배치 코드에는 문제가 없는데 해당 코드가 문제인 줄 알고 삽질를 유발함

해결방법

  1. elasticsearch ver. 7.7.0 이상으로 업그레이드
  2. elasticsearch 의 search.max_open_scroll_context 값을 int.MAX_VALUE 으로 변경
    // [step 1] cluster update api를 이용하여 바로 반영
    PUT /_cluster/settings
    {
      "persistent" : {
     "search.max_open_scroll_context": 2147483647
      },
      "transient": {
     "search.max_open_scroll_context": 2147483647
      }
    }