or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

action-framework.mdclient-apis.mdcluster-management.mdindex-management.mdindex.mdplugin-framework.mdsearch-apis.md

cluster-management.mddocs/

0

# Cluster Management

1

2

Cluster state monitoring, node management, health checks, and cluster-wide settings configuration. OpenSearch provides comprehensive APIs for managing distributed clusters, monitoring node health, and configuring cluster behavior.

3

4

## Capabilities

5

6

### Cluster Health and Status

7

8

APIs for monitoring overall cluster health, status, and operational metrics.

9

10

```java { .api }

11

/**

12

* Request to check cluster health status and metrics

13

*/

14

class ClusterHealthRequest extends ActionRequest {

15

/**

16

* Create cluster health request for specified indices

17

* @param indices Index names to check health for (empty for cluster-wide)

18

*/

19

ClusterHealthRequest(String... indices);

20

21

/**

22

* Set request timeout

23

* @param timeout Maximum time to wait for response

24

*/

25

ClusterHealthRequest timeout(String timeout);

26

27

/**

28

* Wait for specific cluster status before returning

29

* @param status Minimum cluster status to wait for (GREEN, YELLOW, RED)

30

*/

31

ClusterHealthRequest waitForStatus(ClusterHealthStatus status);

32

33

/**

34

* Wait for specific number of nodes

35

* @param waitForNodes Number of nodes to wait for (e.g., ">=3", "5")

36

*/

37

ClusterHealthRequest waitForNodes(String waitForNodes);

38

39

/**

40

* Wait for specific number of active shards

41

* @param waitForActiveShards Number of active shards to wait for

42

*/

43

ClusterHealthRequest waitForActiveShards(ActiveShardCount waitForActiveShards);

44

45

/**

46

* Wait for no relocating shards

47

* @param waitForNoRelocatingShards Whether to wait for shard relocations to complete

48

*/

49

ClusterHealthRequest waitForNoRelocatingShards(boolean waitForNoRelocatingShards);

50

51

/**

52

* Wait for no initializing shards

53

* @param waitForNoInitializingShards Whether to wait for shard initialization to complete

54

*/

55

ClusterHealthRequest waitForNoInitializingShards(boolean waitForNoInitializingShards);

56

57

/**

58

* Set priority level for request

59

* @param priority Request priority (IMMEDIATE, URGENT, HIGH, NORMAL, LOW, LANGUID)

60

*/

61

ClusterHealthRequest priority(Priority priority);

62

63

/**

64

* Get target indices

65

*/

66

String[] indices();

67

}

68

69

/**

70

* Response containing cluster health information and metrics

71

*/

72

class ClusterHealthResponse extends ActionResponse {

73

/**

74

* Get overall cluster status

75

*/

76

ClusterHealthStatus getStatus();

77

78

/**

79

* Get cluster name

80

*/

81

String getClusterName();

82

83

/**

84

* Get number of nodes in cluster

85

*/

86

int getNumberOfNodes();

87

88

/**

89

* Get number of data nodes

90

*/

91

int getNumberOfDataNodes();

92

93

/**

94

* Get number of active primary shards

95

*/

96

int getActivePrimaryShards();

97

98

/**

99

* Get total number of active shards

100

*/

101

int getActiveShards();

102

103

/**

104

* Get number of relocating shards

105

*/

106

int getRelocatingShards();

107

108

/**

109

* Get number of initializing shards

110

*/

111

int getInitializingShards();

112

113

/**

114

* Get number of unassigned shards

115

*/

116

int getUnassignedShards();

117

118

/**

119

* Get number of delayed unassigned shards

120

*/

121

int getDelayedUnassignedShards();

122

123

/**

124

* Get active shards percentage

125

*/

126

double getActiveShardsPercent();

127

128

/**

129

* Check if request timed out

130

*/

131

boolean isTimedOut();

132

133

/**

134

* Get per-index health information

135

*/

136

Map<String, ClusterIndexHealth> getIndices();

137

}

138

139

/**

140

* Cluster health status enumeration

141

*/

142

enum ClusterHealthStatus {

143

/**

144

* All shards are allocated and replicated

145

*/

146

GREEN,

147

148

/**

149

* All primary shards allocated, some replicas missing

150

*/

151

YELLOW,

152

153

/**

154

* Some primary shards are not allocated

155

*/

156

RED

157

}

158

```

159

160

### Cluster State Information

161

162

APIs for retrieving detailed cluster state and configuration.

163

164

```java { .api }

165

/**

166

* Request to get comprehensive cluster state information

167

*/

168

class ClusterStateRequest extends ActionRequest {

169

/**

170

* Create cluster state request

171

*/

172

ClusterStateRequest();

173

174

/**

175

* Set whether to retrieve from local node only

176

* @param local Whether to get state from local node only

177

*/

178

ClusterStateRequest local(boolean local);

179

180

/**

181

* Set cluster manager node timeout

182

* @param clusterManagerNodeTimeout Timeout for cluster manager operations

183

*/

184

ClusterStateRequest clusterManagerNodeTimeout(String clusterManagerNodeTimeout);

185

186

/**

187

* Wait for metadata version

188

* @param waitForMetadataVersion Minimum metadata version to wait for

189

*/

190

ClusterStateRequest waitForMetadataVersion(long waitForMetadataVersion);

191

192

/**

193

* Set specific indices to include in state

194

* @param indices Index names to include

195

*/

196

ClusterStateRequest indices(String... indices);

197

198

/**

199

* Include metadata in response

200

* @param includeMetadata Whether to include cluster metadata

201

*/

202

ClusterStateRequest metadata(boolean includeMetadata);

203

204

/**

205

* Include nodes information in response

206

* @param includeNodes Whether to include node information

207

*/

208

ClusterStateRequest nodes(boolean includeNodes);

209

210

/**

211

* Include routing table in response

212

* @param includeRoutingTable Whether to include shard routing information

213

*/

214

ClusterStateRequest routingTable(boolean includeRoutingTable);

215

216

/**

217

* Include blocks information in response

218

* @param includeBlocks Whether to include cluster blocks

219

*/

220

ClusterStateRequest blocks(boolean includeBlocks);

221

}

222

223

/**

224

* Response containing comprehensive cluster state information

225

*/

226

class ClusterStateResponse extends ActionResponse {

227

/**

228

* Get cluster name

229

*/

230

ClusterName getClusterName();

231

232

/**

233

* Get complete cluster state

234

*/

235

ClusterState getState();

236

237

/**

238

* Check if cluster state was retrieved from local node

239

*/

240

boolean isWaitForTimedOut();

241

}

242

243

/**

244

* Request to get cluster statistics and metrics

245

*/

246

class ClusterStatsRequest extends ActionRequest {

247

/**

248

* Create cluster stats request

249

*/

250

ClusterStatsRequest();

251

252

/**

253

* Set specific node IDs to include in stats

254

* @param nodeIds Node identifiers to include

255

*/

256

ClusterStatsRequest nodeIds(String... nodeIds);

257

258

/**

259

* Set request timeout

260

* @param timeout Operation timeout

261

*/

262

ClusterStatsRequest timeout(String timeout);

263

}

264

265

/**

266

* Response containing cluster statistics and performance metrics

267

*/

268

class ClusterStatsResponse extends ActionResponse {

269

/**

270

* Get cluster status

271

*/

272

ClusterHealthStatus getStatus();

273

274

/**

275

* Get node statistics

276

*/

277

ClusterStatsNodes getNodesStats();

278

279

/**

280

* Get indices statistics

281

*/

282

ClusterStatsIndices getIndicesStats();

283

284

/**

285

* Get timestamp when stats were collected

286

*/

287

long getTimestamp();

288

}

289

```

290

291

### Node Information and Statistics

292

293

APIs for retrieving detailed information about individual cluster nodes.

294

295

```java { .api }

296

/**

297

* Request to get information about cluster nodes

298

*/

299

class NodesInfoRequest extends ActionRequest {

300

/**

301

* Create nodes info request for specified nodes

302

* @param nodeIds Node IDs to get info for (empty for all nodes)

303

*/

304

NodesInfoRequest(String... nodeIds);

305

306

/**

307

* Add specific metrics to retrieve

308

* @param metrics Metric names (settings, os, process, jvm, thread_pool, transport, http, plugins, ingest)

309

*/

310

NodesInfoRequest addMetrics(String... metrics);

311

312

/**

313

* Clear all metrics (retrieve basic info only)

314

*/

315

NodesInfoRequest clear();

316

317

/**

318

* Set request timeout

319

* @param timeout Operation timeout

320

*/

321

NodesInfoRequest timeout(String timeout);

322

323

/**

324

* Get target node IDs

325

*/

326

String[] nodeIds();

327

328

/**

329

* Get requested metrics

330

*/

331

Set<String> requestedMetrics();

332

}

333

334

/**

335

* Response containing detailed node information

336

*/

337

class NodesInfoResponse extends ActionResponse {

338

/**

339

* Get cluster name

340

*/

341

ClusterName getClusterName();

342

343

/**

344

* Get information for all nodes

345

*/

346

List<NodeInfo> getNodes();

347

348

/**

349

* Get node info by node ID

350

* @param nodeId Node identifier

351

*/

352

NodeInfo getNodeById(String nodeId);

353

354

/**

355

* Get nodes info as map

356

*/

357

Map<String, NodeInfo> getNodesMap();

358

359

/**

360

* Get any failures that occurred

361

*/

362

List<FailedNodeException> failures();

363

}

364

365

/**

366

* Request to get runtime statistics from cluster nodes

367

*/

368

class NodesStatsRequest extends ActionRequest {

369

/**

370

* Create nodes stats request for specified nodes

371

* @param nodeIds Node IDs to get stats for (empty for all nodes)

372

*/

373

NodesStatsRequest(String... nodeIds);

374

375

/**

376

* Add specific metrics to retrieve

377

* @param metrics Metric names (indices, os, process, jvm, thread_pool, fs, transport, http, breaker, script, discovery, ingest)

378

*/

379

NodesStatsRequest addMetrics(String... metrics);

380

381

/**

382

* Clear all metrics

383

*/

384

NodesStatsRequest clear();

385

386

/**

387

* Set indices flags for detailed index statistics

388

* @param flags Index statistics flags (store, indexing, search, get, merge, refresh, flush, warmer, query_cache, fielddata, completion, segments, translog, request_cache, recovery)

389

*/

390

NodesStatsRequest indices(CommonStatsFlags flags);

391

392

/**

393

* Set request timeout

394

* @param timeout Operation timeout

395

*/

396

NodesStatsRequest timeout(String timeout);

397

398

/**

399

* Get target node IDs

400

*/

401

String[] nodeIds();

402

}

403

404

/**

405

* Response containing runtime node statistics

406

*/

407

class NodesStatsResponse extends ActionResponse {

408

/**

409

* Get cluster name

410

*/

411

ClusterName getClusterName();

412

413

/**

414

* Get statistics for all nodes

415

*/

416

List<NodeStats> getNodes();

417

418

/**

419

* Get node stats by node ID

420

* @param nodeId Node identifier

421

*/

422

NodeStats getNodeById(String nodeId);

423

424

/**

425

* Get nodes stats as map

426

*/

427

Map<String, NodeStats> getNodesMap();

428

429

/**

430

* Get any failures that occurred

431

*/

432

List<FailedNodeException> failures();

433

}

434

```

435

436

### Cluster Settings Management

437

438

APIs for configuring cluster-wide settings and behavior.

439

440

```java { .api }

441

/**

442

* Request to update cluster settings

443

*/

444

class ClusterUpdateSettingsRequest extends ActionRequest {

445

/**

446

* Create cluster update settings request

447

*/

448

ClusterUpdateSettingsRequest();

449

450

/**

451

* Set persistent settings (survive cluster restarts)

452

* @param persistentSettings Settings that persist across restarts

453

*/

454

ClusterUpdateSettingsRequest persistentSettings(Settings persistentSettings);

455

456

/**

457

* Set persistent settings from map

458

* @param source Settings as key-value pairs

459

*/

460

ClusterUpdateSettingsRequest persistentSettings(Map<String, Object> source);

461

462

/**

463

* Set transient settings (lost on cluster restart)

464

* @param transientSettings Settings that are temporary

465

*/

466

ClusterUpdateSettingsRequest transientSettings(Settings transientSettings);

467

468

/**

469

* Set transient settings from map

470

* @param source Settings as key-value pairs

471

*/

472

ClusterUpdateSettingsRequest transientSettings(Map<String, Object> source);

473

474

/**

475

* Set request timeout

476

* @param timeout Operation timeout

477

*/

478

ClusterUpdateSettingsRequest timeout(String timeout);

479

480

/**

481

* Set cluster manager node timeout

482

* @param clusterManagerNodeTimeout Timeout for cluster manager operations

483

*/

484

ClusterUpdateSettingsRequest clusterManagerNodeTimeout(String clusterManagerNodeTimeout);

485

486

/**

487

* Get persistent settings

488

*/

489

Settings persistentSettings();

490

491

/**

492

* Get transient settings

493

*/

494

Settings transientSettings();

495

}

496

497

/**

498

* Response for cluster settings update operations

499

*/

500

class ClusterUpdateSettingsResponse extends ActionResponse {

501

/**

502

* Check if update was acknowledged

503

*/

504

boolean isAcknowledged();

505

506

/**

507

* Get updated persistent settings

508

*/

509

Settings getPersistentSettings();

510

511

/**

512

* Get updated transient settings

513

*/

514

Settings getTransientSettings();

515

}

516

517

/**

518

* Request to retrieve current cluster settings

519

*/

520

class ClusterGetSettingsRequest extends ActionRequest {

521

/**

522

* Create cluster get settings request

523

*/

524

ClusterGetSettingsRequest();

525

526

/**

527

* Include default settings in response

528

* @param includeDefaults Whether to include default cluster settings

529

*/

530

ClusterGetSettingsRequest includeDefaults(boolean includeDefaults);

531

532

/**

533

* Set request timeout

534

* @param timeout Operation timeout

535

*/

536

ClusterGetSettingsRequest timeout(String timeout);

537

538

/**

539

* Set cluster manager node timeout

540

* @param clusterManagerNodeTimeout Timeout for cluster manager operations

541

*/

542

ClusterGetSettingsRequest clusterManagerNodeTimeout(String clusterManagerNodeTimeout);

543

}

544

545

/**

546

* Response containing current cluster settings

547

*/

548

class ClusterGetSettingsResponse extends ActionResponse {

549

/**

550

* Get persistent settings

551

*/

552

Settings getPersistentSettings();

553

554

/**

555

* Get transient settings

556

*/

557

Settings getTransientSettings();

558

559

/**

560

* Get default settings (if requested)

561

*/

562

Settings getDefaultSettings();

563

}

564

```

565

566

### Task Management

567

568

APIs for monitoring and managing long-running cluster operations.

569

570

```java { .api }

571

/**

572

* Request to list currently running tasks

573

*/

574

class ListTasksRequest extends ActionRequest {

575

/**

576

* Create list tasks request

577

*/

578

ListTasksRequest();

579

580

/**

581

* Set specific node IDs to get tasks from

582

* @param nodeIds Node identifiers to query

583

*/

584

ListTasksRequest setNodeIds(String... nodeIds);

585

586

/**

587

* Set task actions to filter by

588

* @param actions Action names to include

589

*/

590

ListTasksRequest setActions(String... actions);

591

592

/**

593

* Set parent task ID to filter by

594

* @param parentTaskId Parent task identifier

595

*/

596

ListTasksRequest setParentTaskId(TaskId parentTaskId);

597

598

/**

599

* Include detailed task information

600

* @param detailed Whether to include detailed task info

601

*/

602

ListTasksRequest setDetailed(boolean detailed);

603

604

/**

605

* Set request timeout

606

* @param timeout Operation timeout

607

*/

608

ListTasksRequest setTimeout(String timeout);

609

}

610

611

/**

612

* Response containing list of running tasks

613

*/

614

class ListTasksResponse extends ActionResponse {

615

/**

616

* Get all task information

617

*/

618

List<TaskInfo> getTasks();

619

620

/**

621

* Get tasks grouped by node

622

*/

623

Map<String, List<TaskInfo>> getPerNodeTasks();

624

625

/**

626

* Get any node failures

627

*/

628

List<TaskOperationFailure> getNodeFailures();

629

630

/**

631

* Get any task failures

632

*/

633

List<TaskOperationFailure> getTaskFailures();

634

}

635

636

/**

637

* Request to cancel running tasks

638

*/

639

class CancelTasksRequest extends ActionRequest {

640

/**

641

* Create cancel tasks request

642

*/

643

CancelTasksRequest();

644

645

/**

646

* Set specific task ID to cancel

647

* @param taskId Task identifier to cancel

648

*/

649

CancelTasksRequest setTaskId(TaskId taskId);

650

651

/**

652

* Set node IDs to cancel tasks on

653

* @param nodeIds Node identifiers

654

*/

655

CancelTasksRequest setNodeIds(String... nodeIds);

656

657

/**

658

* Set actions to cancel tasks for

659

* @param actions Action names to cancel

660

*/

661

CancelTasksRequest setActions(String... actions);

662

663

/**

664

* Set parent task ID to cancel child tasks

665

* @param parentTaskId Parent task identifier

666

*/

667

CancelTasksRequest setParentTaskId(TaskId parentTaskId);

668

}

669

```

670

671

## Usage Examples

672

673

### Monitoring Cluster Health

674

675

```java

676

import org.opensearch.action.admin.cluster.health.ClusterHealthRequest;

677

import org.opensearch.action.admin.cluster.health.ClusterHealthResponse;

678

import org.opensearch.cluster.health.ClusterHealthStatus;

679

import org.opensearch.common.unit.TimeValue;

680

681

// Basic cluster health check

682

ClusterHealthRequest request = new ClusterHealthRequest();

683

request.timeout(TimeValue.timeValueSeconds(10));

684

request.waitForStatus(ClusterHealthStatus.YELLOW);

685

686

ClusterHealthResponse response = client.admin().cluster().health(request);

687

688

System.out.println("Cluster status: " + response.getStatus());

689

System.out.println("Number of nodes: " + response.getNumberOfNodes());

690

System.out.println("Number of data nodes: " + response.getNumberOfDataNodes());

691

System.out.println("Active shards: " + response.getActiveShards());

692

System.out.println("Unassigned shards: " + response.getUnassignedShards());

693

System.out.println("Active shards percentage: " + response.getActiveShardsPercent());

694

695

// Check specific indices health

696

ClusterHealthRequest indexHealthRequest = new ClusterHealthRequest("products", "orders");

697

indexHealthRequest.waitForActiveShards(ActiveShardCount.ALL);

698

ClusterHealthResponse indexHealthResponse = client.admin().cluster().health(indexHealthRequest);

699

700

for (Map.Entry<String, ClusterIndexHealth> entry : indexHealthResponse.getIndices().entrySet()) {

701

String indexName = entry.getKey();

702

ClusterIndexHealth indexHealth = entry.getValue();

703

System.out.println("Index: " + indexName + ", Status: " + indexHealth.getStatus());

704

}

705

```

706

707

### Getting Node Information

708

709

```java

710

import org.opensearch.action.admin.cluster.node.info.NodesInfoRequest;

711

import org.opensearch.action.admin.cluster.node.info.NodesInfoResponse;

712

import org.opensearch.action.admin.cluster.node.info.NodeInfo;

713

714

// Get detailed node information

715

NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();

716

nodesInfoRequest.addMetrics("os", "process", "jvm", "transport", "http", "plugins");

717

718

NodesInfoResponse nodesInfoResponse = client.admin().cluster().nodesInfo(nodesInfoRequest);

719

720

for (NodeInfo nodeInfo : nodesInfoResponse.getNodes()) {

721

System.out.println("Node ID: " + nodeInfo.getNode().getId());

722

System.out.println("Node name: " + nodeInfo.getNode().getName());

723

System.out.println("Host: " + nodeInfo.getNode().getHostName());

724

System.out.println("Roles: " + nodeInfo.getNode().getRoles());

725

726

if (nodeInfo.getOs() != null) {

727

System.out.println("OS: " + nodeInfo.getOs().getName());

728

System.out.println("Available processors: " + nodeInfo.getOs().getAvailableProcessors());

729

}

730

731

if (nodeInfo.getJvm() != null) {

732

System.out.println("JVM version: " + nodeInfo.getJvm().getVersion());

733

System.out.println("JVM heap max: " + nodeInfo.getJvm().getMem().getHeapMax());

734

}

735

}

736

```

737

738

### Monitoring Node Statistics

739

740

```java

741

import org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest;

742

import org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse;

743

import org.opensearch.action.admin.cluster.node.stats.NodeStats;

744

import org.opensearch.indices.NodeIndicesStats;

745

746

// Get runtime node statistics

747

NodesStatsRequest statsRequest = new NodesStatsRequest();

748

statsRequest.addMetrics("indices", "os", "process", "jvm", "thread_pool", "fs");

749

750

NodesStatsResponse statsResponse = client.admin().cluster().nodesStats(statsRequest);

751

752

for (NodeStats nodeStats : statsResponse.getNodes()) {

753

System.out.println("Node: " + nodeStats.getNode().getName());

754

755

// JVM statistics

756

if (nodeStats.getJvm() != null) {

757

System.out.println("JVM heap used: " + nodeStats.getJvm().getMem().getHeapUsed());

758

System.out.println("JVM heap percentage: " + nodeStats.getJvm().getMem().getHeapUsedPercent());

759

System.out.println("JVM uptime: " + nodeStats.getJvm().getUptime());

760

}

761

762

// OS statistics

763

if (nodeStats.getOs() != null) {

764

System.out.println("CPU percentage: " + nodeStats.getOs().getCpu().getPercent());

765

System.out.println("Load average: " + Arrays.toString(nodeStats.getOs().getCpu().getLoadAverage()));

766

}

767

768

// Indices statistics

769

NodeIndicesStats indicesStats = nodeStats.getIndices();

770

if (indicesStats != null) {

771

System.out.println("Indexing operations: " + indicesStats.getIndexing().getTotal().getIndexCount());

772

System.out.println("Search operations: " + indicesStats.getSearch().getTotal().getQueryCount());

773

System.out.println("Documents count: " + indicesStats.getDocs().getCount());

774

}

775

}

776

```

777

778

### Managing Cluster Settings

779

780

```java

781

import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;

782

import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse;

783

import org.opensearch.common.settings.Settings;

784

785

// Update cluster settings

786

ClusterUpdateSettingsRequest updateRequest = new ClusterUpdateSettingsRequest();

787

788

// Set persistent settings (survive restart)

789

Settings persistentSettings = Settings.builder()

790

.put("cluster.routing.allocation.enable", "all")

791

.put("cluster.routing.allocation.cluster_concurrent_rebalance", 2)

792

.put("indices.recovery.max_bytes_per_sec", "40mb")

793

.build();

794

795

updateRequest.persistentSettings(persistentSettings);

796

797

// Set transient settings (temporary)

798

Settings transientSettings = Settings.builder()

799

.put("cluster.routing.allocation.disk.watermark.low", "85%")

800

.put("cluster.routing.allocation.disk.watermark.high", "90%")

801

.put("logger.org.opensearch.index.search.slowlog.query", "DEBUG")

802

.build();

803

804

updateRequest.transientSettings(transientSettings);

805

806

ClusterUpdateSettingsResponse updateResponse = client.admin().cluster().updateSettings(updateRequest);

807

System.out.println("Settings updated: " + updateResponse.isAcknowledged());

808

809

// Retrieve current settings

810

ClusterGetSettingsRequest getRequest = new ClusterGetSettingsRequest();

811

getRequest.includeDefaults(true);

812

813

ClusterGetSettingsResponse getResponse = client.admin().cluster().getSettings(getRequest);

814

System.out.println("Persistent settings: " + getResponse.getPersistentSettings());

815

System.out.println("Transient settings: " + getResponse.getTransientSettings());

816

```

817

818

### Task Management

819

820

```java

821

import org.opensearch.action.admin.cluster.node.tasks.list.ListTasksRequest;

822

import org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse;

823

import org.opensearch.action.admin.cluster.node.tasks.cancel.CancelTasksRequest;

824

import org.opensearch.tasks.TaskInfo;

825

826

// List all running tasks

827

ListTasksRequest listRequest = new ListTasksRequest();

828

listRequest.setDetailed(true);

829

listRequest.setActions("indices:data/write/bulk*", "indices:data/read/search*");

830

831

ListTasksResponse listResponse = client.admin().cluster().listTasks(listRequest);

832

833

System.out.println("Running tasks:");

834

for (TaskInfo task : listResponse.getTasks()) {

835

System.out.println("Task ID: " + task.getTaskId());

836

System.out.println("Action: " + task.getAction());

837

System.out.println("Description: " + task.getDescription());

838

System.out.println("Start time: " + task.getStartTime());

839

System.out.println("Running time: " + task.getRunningTimeNanos() / 1_000_000 + "ms");

840

841

// Cancel long-running tasks if needed

842

if (task.getRunningTimeNanos() > TimeValue.timeValueMinutes(5).nanos()) {

843

CancelTasksRequest cancelRequest = new CancelTasksRequest();

844

cancelRequest.setTaskId(task.getTaskId());

845

846

client.admin().cluster().cancelTasks(cancelRequest);

847

System.out.println("Cancelled long-running task: " + task.getTaskId());

848

}

849

}

850

```

851

852

## Types

853

854

```java { .api }

855

/**

856

* Cluster state container with metadata, routing, and node information

857

*/

858

class ClusterState implements Streamable {

859

/**

860

* Get cluster metadata

861

*/

862

Metadata metadata();

863

864

/**

865

* Get routing table

866

*/

867

RoutingTable routingTable();

868

869

/**

870

* Get discovery nodes

871

*/

872

DiscoveryNodes nodes();

873

874

/**

875

* Get cluster blocks

876

*/

877

ClusterBlocks blocks();

878

879

/**

880

* Get state version

881

*/

882

long version();

883

884

/**

885

* Get state UUID

886

*/

887

String stateUUID();

888

}

889

890

/**

891

* Node information container with static node details

892

*/

893

class NodeInfo implements Streamable {

894

/**

895

* Get discovery node information

896

*/

897

DiscoveryNode getNode();

898

899

/**

900

* Get node settings

901

*/

902

Settings getSettings();

903

904

/**

905

* Get operating system information

906

*/

907

OsInfo getOs();

908

909

/**

910

* Get process information

911

*/

912

ProcessInfo getProcess();

913

914

/**

915

* Get JVM information

916

*/

917

JvmInfo getJvm();

918

919

/**

920

* Get transport information

921

*/

922

TransportInfo getTransport();

923

924

/**

925

* Get HTTP information

926

*/

927

HttpInfo getHttp();

928

929

/**

930

* Get installed plugins

931

*/

932

List<PluginInfo> getPlugins();

933

}

934

935

/**

936

* Node runtime statistics container

937

*/

938

class NodeStats implements Streamable {

939

/**

940

* Get discovery node information

941

*/

942

DiscoveryNode getNode();

943

944

/**

945

* Get indices statistics

946

*/

947

NodeIndicesStats getIndices();

948

949

/**

950

* Get operating system statistics

951

*/

952

OsStats getOs();

953

954

/**

955

* Get process statistics

956

*/

957

ProcessStats getProcess();

958

959

/**

960

* Get JVM statistics

961

*/

962

JvmStats getJvm();

963

964

/**

965

* Get thread pool statistics

966

*/

967

ThreadPoolStats getThreadPool();

968

969

/**

970

* Get filesystem statistics

971

*/

972

FsInfo getFs();

973

974

/**

975

* Get transport statistics

976

*/

977

TransportStats getTransport();

978

}

979

980

/**

981

* Task identifier for tracking operations

982

*/

983

class TaskId implements Streamable {

984

/**

985

* Get node ID where task is running

986

*/

987

String getNodeId();

988

989

/**

990

* Get task sequence number

991

*/

992

long getId();

993

994

/**

995

* Create task ID from string representation

996

* @param taskId String in format "nodeId:taskNumber"

997

*/

998

static TaskId fromString(String taskId);

999

}

1000

1001

/**

1002

* Request priority levels

1003

*/

1004

enum Priority {

1005

IMMEDIATE,

1006

URGENT,

1007

HIGH,

1008

NORMAL,

1009

LOW,

1010

LANGUID

1011

}

1012

```