# ShardLockObtainFailedException: [my_index][0] obtaining shard lock failed

- **ID:** `elasticsearch/primary-shard-not-allocated-due-to-shard-lock`
- **Domain:** elasticsearch
- **Category:** system_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

A shard lock cannot be acquired because the shard is still being recovered or a previous node crash left a stale lock file on disk.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.17.10 | active | — | — |
| 8.6.2 | active | — | — |
| 8.11.0 | active | — | — |

## Workarounds

1. **Remove the stale shard lock file manually: find the shard directory under ES_PATH_CONF/data/nodes/0/indices/<index-uuid>/0/ and delete the 'index.lock' or 'shard.lock' file, then restart the node.** (90% success)
   ```
   Remove the stale shard lock file manually: find the shard directory under ES_PATH_CONF/data/nodes/0/indices/<index-uuid>/0/ and delete the 'index.lock' or 'shard.lock' file, then restart the node.
   ```
2. **Reroute the unassigned shard using the Cluster Reroute API: POST /_cluster/reroute { "commands": [{ "allocate_stale_primary": { "index": "my_index", "shard": 0, "node": "my_node", "accept_data_loss": true } }] }** (75% success)
   ```
   Reroute the unassigned shard using the Cluster Reroute API: POST /_cluster/reroute { "commands": [{ "allocate_stale_primary": { "index": "my_index", "shard": 0, "node": "my_node", "accept_data_loss": true } }] }
   ```

## Dead Ends

- **** — Deleting the index loses all data and may not resolve the underlying lock issue if the file system is corrupted. (70% fail)
- **** — Restarting does not remove stale lock files; the lock file persists and the same error occurs again. (85% fail)
