Skip to content

Commit 24163d1

Browse files
authored
REST hl client: cluster health to default to cluster level (#31268)
With #29331 we added support for the cluster health API to the high-level REST client. The transport client does not support the level parameter, and it always returns all the info needed for shards level rendering. We have maintained that behaviour when adding support for cluster health to the high-level REST client, to ease migration, but the correct thing to do is to default the high-level REST client to `cluster` level, which is the same default as when going through the Elasticsearch REST layer.
1 parent 66f7dd2 commit 24163d1

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/ClusterClientIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ public void testClusterHealthYellowClusterLevel() throws IOException {
129129
createIndex("index2", Settings.EMPTY);
130130
ClusterHealthRequest request = new ClusterHealthRequest();
131131
request.timeout("5s");
132-
request.level(ClusterHealthRequest.Level.CLUSTER);
133132
ClusterHealthResponse response = execute(request, highLevelClient().cluster()::health, highLevelClient().cluster()::healthAsync);
134133

135134
assertYellowShards(response);
@@ -170,6 +169,7 @@ public void testClusterHealthYellowSpecificIndex() throws IOException {
170169
createIndex("index", Settings.EMPTY);
171170
createIndex("index2", Settings.EMPTY);
172171
ClusterHealthRequest request = new ClusterHealthRequest("index");
172+
request.level(ClusterHealthRequest.Level.SHARDS);
173173
request.timeout("5s");
174174
ClusterHealthResponse response = execute(request, highLevelClient().cluster()::health, highLevelClient().cluster()::healthAsync);
175175

client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ public void testClusterHealth() {
15681568
healthRequest.level(level);
15691569
expectedParams.put("level", level.name().toLowerCase(Locale.ROOT));
15701570
} else {
1571-
expectedParams.put("level", "shards");
1571+
expectedParams.put("level", "cluster");
15721572
}
15731573
if (randomBoolean()) {
15741574
Priority priority = randomFrom(Priority.values());

docs/java-rest/high-level/cluster/health.asciidoc

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-wai
6767
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-level]
6868
--------------------------------------------------
6969
<1> The level of detail of the returned health information. Accepts a `ClusterHealthRequest.Level` value.
70+
Default value is `cluster`.
7071

7172
["source","java",subs="attributes,callouts,macros"]
7273
--------------------------------------------------

docs/reference/migration/migrate_7_0/restclient.asciidoc

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,11 @@ header, e.g. `client.index(indexRequest)` becomes
1010
`client.index(indexRequest, RequestOptions.DEFAULT)`.
1111
In case you are specifying headers
1212
e.g. `client.index(indexRequest, new Header("name" "value"))` becomes
13-
`client.index(indexRequest, RequestOptions.DEFAULT.toBuilder().addHeader("name", "value").build());`
13+
`client.index(indexRequest, RequestOptions.DEFAULT.toBuilder().addHeader("name", "value").build());`
14+
15+
==== Cluster Health API default to `cluster` level
16+
17+
The Cluster Health API used to default to `shards` level to ease migration
18+
from transport client that doesn't support the `level` parameter and always
19+
returns information including indices and shards details. The level default
20+
value has been aligned with the Elasticsearch default level: `cluster`.

server/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthRequest.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public class ClusterHealthRequest extends MasterNodeReadRequest<ClusterHealthReq
4848
private Priority waitForEvents = null;
4949
/**
5050
* Only used by the high-level REST Client. Controls the details level of the health information returned.
51-
* The default value is 'shards' so it is backward compatible with the transport client behaviour.
51+
* The default value is 'cluster'.
5252
*/
53-
private Level level = Level.SHARDS;
53+
private Level level = Level.CLUSTER;
5454

5555
public ClusterHealthRequest() {
5656
}
@@ -250,8 +250,7 @@ public Priority waitForEvents() {
250250

251251
/**
252252
* Set the level of detail for the health information to be returned.
253-
* Only used by the high-level REST Client
254-
* The default value is 'shards' so it is backward compatible with the transport client behaviour.
253+
* Only used by the high-level REST Client.
255254
*/
256255
public void level(Level level) {
257256
this.level = Objects.requireNonNull(level, "level must not be null");
@@ -260,7 +259,6 @@ public void level(Level level) {
260259
/**
261260
* Get the level of detail for the health information to be returned.
262261
* Only used by the high-level REST Client.
263-
* The default value is 'shards' so it is backward compatible with the transport client behaviour.
264262
*/
265263
public Level level() {
266264
return level;

0 commit comments

Comments
 (0)