# cluster elect-leaders

Trigger a preferred or unclean leader election on one or more partitions

Package: @cookiemonsterdev/kafka-cli 1.12.1
Canonical: https://cookiemonsterdev.github.io/kafka/docs/cli/reference/commands/cluster/elect-leaders/
Source revision: b112a684d2b3cdc7deadb3513041fcdbdc1c18b5

<!-- Generated by scripts/generate-cli-docs.mjs. Do not edit by hand. -->

```sh
kafka cluster elect-leaders
```

Trigger a preferred or unclean leader election on one or more partitions

Shared options and defaults: [connection profiles, JSON output, logging and help](https://cookiemonsterdev.github.io/kafka/docs/cli/reference/global-options/).

## Defaults

Uses the requested election type and topic partitions; use --dry-run to inspect the request.

## Before you run

Changes leadership. Unclean election can lose records unavailable on the elected replica. Inspect ISR health and use a dry run before submitting.

## Flags

| Flag                                      | Description                                                      |
| ----------------------------------------- | ---------------------------------------------------------------- |
| `--brokers <string>`                      | comma-separated broker list, e.g. localhost:9092                 |
| `--election-type <string>`                | preferred or unclean                                             |
| `--topic-partition <string> (repeatable)` | a "topic:partition" to elect a leader on (repeatable)            |
| `--all-topic-partitions`                  | elect on every eligible partition                                |
| `--from-file <string>`                    | path to a kafka-leader-election.sh --path-to-json-file JSON file |
| `--timeout <number>`                      | request timeout in ms                                            |
| `--dry-run`                               | print the election target and exit without connecting            |
| `--yes`                                   | confirm the election without an interactive prompt               |
| `--force`                                 | required for --election-type unclean, which can lose data        |

## Examples

```sh
kafka cluster elect-leaders --election-type preferred --all-topic-partitions --brokers localhost:9092 --yes
kafka cluster elect-leaders --election-type unclean --topic-partition orders:0 --force --yes --brokers localhost:9092
```

## Output

Illustrative, abbreviated output. Empty arrays show the result envelope; actual entries, identifiers, optional fields and broker errors depend on the request and cluster.

With `--json`:

```json
{
  "results": []
}
```

Declared exit codes: `0`, `1`, `2`, `5`. See the exit-code reference for meanings.

## Related commands

[Browse the command group](https://cookiemonsterdev.github.io/kafka/docs/cli/reference/commands/#cluster) · [Exit codes](https://cookiemonsterdev.github.io/kafka/docs/cli/reference/exit-codes/)
