0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Elasticsearch reindexで"No search context found for id [xx]"が発生したら

Posted at

7378件のreindexを実行しましたが、宛先indexの Doc count が 1000件のまま変化しなくなっていました。

reindexリクエスト
POST _reindex?wait_for_completion=false
{
  "source": {
    "index": "idx_text"
  },
  "dest": {
    "index": "text_index",
    "pipeline": "test_pipeline"
  }
}

タスクを見ると、No search context found for id [1221552] となりエラーになっていました。

reindexタスクの情報
{
  "completed": true,
  "task": {
    "node": "BLGIYZv8Sw6L3uyERfBW8Q",
    "id": 10449910,
    "type": "transport",
    "action": "indices:data/write/reindex",
    "status": {
      "total": 7378,
      "updated": 0,
      "created": 1000,
      "deleted": 0,
      "batches": 1,
      "version_conflicts": 0,
      "noops": 0,
      "retries": {
        "bulk": 0,
        "search": 0
      },
      "throttled_millis": 0,
      "requests_per_second": -1,
      "throttled_until_millis": 0
    },
    "description": "reindex from [idx_text] to [text_index]",
    "start_time_in_millis": 1735178547455,
    "running_time_in_nanos": 811210880235,
    "cancellable": true,
    "cancelled": false,
    "headers": {
      "trace.id": "8558b84f156d284379b656bdc978947c"
    }
  },
  "error": {
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": -1,
        "index": null,
        "reason": {
          "type": "search_context_missing_exception",
          "reason": "No search context found for id [1221552]"
        }
      }
    ],
    "caused_by": {
      "type": "search_context_missing_exception",
      "reason": "No search context found for id [1221552]"
    }
  }
}

このエラー No search context found for id でネット検索すると、scroll search実行が時間内に完了しなかった場合に発生することが多いということがわかりました。
ただ、今回はsearchではなくreindexなので、reindexの設定で対応できないかと調べたところ、reindex に次の記述を見つけました。

By default _reindex uses scroll batches of 1000. You can change the batch size with the size field in the source element:

そこで、batch size を小さく(今回は100)して試したところ、エラーが発生することなく全 7378件のreindexが完了しました。

reindexリクエスト
POST _reindex?wait_for_completion=false
{
  "source": {
    "index": "idx_text",
    "size": 100
  },
  "dest": {
    "index": "text_index",
    "pipeline": "test_pipeline"
  }
}
reindexタスクの情報
{
  "completed": true,
  "task": {
    "node": "BLGIYZv8Sw6L3uyERfBW8Q",
    "id": 10554735,
    "type": "transport",
    "action": "indices:data/write/reindex",
    "status": {
      "total": 7378,
      "updated": 1000,
      "created": 6378,
      "deleted": 0,
      "batches": 74,
      "version_conflicts": 0,
      "noops": 0,
      "retries": {
        "bulk": 0,
        "search": 0
      },
      "throttled_millis": 0,
      "requests_per_second": -1,
      "throttled_until_millis": 0
    },
    "description": "reindex from [idx_text] to [text_index]",
    "start_time_in_millis": 1735185743336,
    "running_time_in_nanos": 4010710037946,
    "cancellable": true,
    "cancelled": false,
    "headers": {
      "trace.id": "7d383d901968aba236f3513a37209634"
    }
  },
  "response": {
    "took": 4010709,
    "timed_out": false,
    "total": 7378,
    "updated": 1000,
    "created": 6378,
    "deleted": 0,
    "batches": 74,
    "version_conflicts": 0,
    "noops": 0,
    "retries": {
      "bulk": 0,
      "search": 0
    },
    "throttled": "0s",
    "throttled_millis": 0,
    "requests_per_second": -1,
    "throttled_until": "0s",
    "throttled_until_millis": 0,
    "failures": []
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?