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.
This commit is contained in:
parent
66f7dd2c4d
commit
24163d10b7
|
@ -129,7 +129,6 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase {
|
|||
createIndex("index2", Settings.EMPTY);
|
||||
ClusterHealthRequest request = new ClusterHealthRequest();
|
||||
request.timeout("5s");
|
||||
request.level(ClusterHealthRequest.Level.CLUSTER);
|
||||
ClusterHealthResponse response = execute(request, highLevelClient().cluster()::health, highLevelClient().cluster()::healthAsync);
|
||||
|
||||
assertYellowShards(response);
|
||||
|
@ -170,6 +169,7 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase {
|
|||
createIndex("index", Settings.EMPTY);
|
||||
createIndex("index2", Settings.EMPTY);
|
||||
ClusterHealthRequest request = new ClusterHealthRequest("index");
|
||||
request.level(ClusterHealthRequest.Level.SHARDS);
|
||||
request.timeout("5s");
|
||||
ClusterHealthResponse response = execute(request, highLevelClient().cluster()::health, highLevelClient().cluster()::healthAsync);
|
||||
|
||||
|
|
|
@ -1568,7 +1568,7 @@ public class RequestConvertersTests extends ESTestCase {
|
|||
healthRequest.level(level);
|
||||
expectedParams.put("level", level.name().toLowerCase(Locale.ROOT));
|
||||
} else {
|
||||
expectedParams.put("level", "shards");
|
||||
expectedParams.put("level", "cluster");
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
Priority priority = randomFrom(Priority.values());
|
||||
|
|
|
@ -67,6 +67,7 @@ include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-wai
|
|||
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-level]
|
||||
--------------------------------------------------
|
||||
<1> The level of detail of the returned health information. Accepts a `ClusterHealthRequest.Level` value.
|
||||
Default value is `cluster`.
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
|
|
|
@ -10,4 +10,11 @@ header, e.g. `client.index(indexRequest)` becomes
|
|||
`client.index(indexRequest, RequestOptions.DEFAULT)`.
|
||||
In case you are specifying headers
|
||||
e.g. `client.index(indexRequest, new Header("name" "value"))` becomes
|
||||
`client.index(indexRequest, RequestOptions.DEFAULT.toBuilder().addHeader("name", "value").build());`
|
||||
`client.index(indexRequest, RequestOptions.DEFAULT.toBuilder().addHeader("name", "value").build());`
|
||||
|
||||
==== Cluster Health API default to `cluster` level
|
||||
|
||||
The Cluster Health API used to default to `shards` level to ease migration
|
||||
from transport client that doesn't support the `level` parameter and always
|
||||
returns information including indices and shards details. The level default
|
||||
value has been aligned with the Elasticsearch default level: `cluster`.
|
|
@ -48,9 +48,9 @@ public class ClusterHealthRequest extends MasterNodeReadRequest<ClusterHealthReq
|
|||
private Priority waitForEvents = null;
|
||||
/**
|
||||
* Only used by the high-level REST Client. Controls the details level of the health information returned.
|
||||
* The default value is 'shards' so it is backward compatible with the transport client behaviour.
|
||||
* The default value is 'cluster'.
|
||||
*/
|
||||
private Level level = Level.SHARDS;
|
||||
private Level level = Level.CLUSTER;
|
||||
|
||||
public ClusterHealthRequest() {
|
||||
}
|
||||
|
@ -250,8 +250,7 @@ public class ClusterHealthRequest extends MasterNodeReadRequest<ClusterHealthReq
|
|||
|
||||
/**
|
||||
* Set the level of detail for the health information to be returned.
|
||||
* Only used by the high-level REST Client
|
||||
* The default value is 'shards' so it is backward compatible with the transport client behaviour.
|
||||
* Only used by the high-level REST Client.
|
||||
*/
|
||||
public void level(Level level) {
|
||||
this.level = Objects.requireNonNull(level, "level must not be null");
|
||||
|
@ -260,7 +259,6 @@ public class ClusterHealthRequest extends MasterNodeReadRequest<ClusterHealthReq
|
|||
/**
|
||||
* Get the level of detail for the health information to be returned.
|
||||
* Only used by the high-level REST Client.
|
||||
* The default value is 'shards' so it is backward compatible with the transport client behaviour.
|
||||
*/
|
||||
public Level level() {
|
||||
return level;
|
||||
|
|
Loading…
Reference in New Issue