diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java
index d88dfa3c92bbf..bf99c37c81745 100644
--- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java
+++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java
@@ -47,8 +47,8 @@ public class IndexLifecycleClient {
}
/**
- * Retrieve one or more lifecycle policy definition
- * See
+ * Retrieve one or more lifecycle policy definition. See
+ *
* the docs for more.
* @param request the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
@@ -62,8 +62,8 @@ public GetLifecyclePolicyResponse getLifecyclePolicy(GetLifecyclePolicyRequest r
}
/**
- * Asynchronously retrieve one or more lifecycle policy definition
- * See
+ * Asynchronously retrieve one or more lifecycle policy definition. See
+ *
* the docs for more.
* @param request the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ILMDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ILMDocumentationIT.java
index 69bfbc11f766b..4ff50ba33e752 100644
--- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ILMDocumentationIT.java
+++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ILMDocumentationIT.java
@@ -29,11 +29,16 @@
import org.elasticsearch.client.core.AcknowledgedResponse;
import org.elasticsearch.client.indexlifecycle.DeleteAction;
import org.elasticsearch.client.indexlifecycle.DeleteLifecyclePolicyRequest;
+import org.elasticsearch.client.indexlifecycle.GetLifecyclePolicyRequest;
+import org.elasticsearch.client.indexlifecycle.GetLifecyclePolicyResponse;
import org.elasticsearch.client.indexlifecycle.LifecycleAction;
import org.elasticsearch.client.indexlifecycle.LifecyclePolicy;
+import org.elasticsearch.client.indexlifecycle.LifecyclePolicyMetadata;
import org.elasticsearch.client.indexlifecycle.Phase;
import org.elasticsearch.client.indexlifecycle.PutLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.RolloverAction;
+import org.elasticsearch.client.indexlifecycle.ShrinkAction;
+import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
@@ -119,6 +124,108 @@ public void onFailure(Exception e) {
}
+ public void testGetLifecyclePolicy() throws IOException, InterruptedException {
+ RestHighLevelClient client = highLevelClient();
+
+ LifecyclePolicy myPolicyAsPut;
+ LifecyclePolicy otherPolicyAsPut;
+ // Set up some policies so we have something to get
+ {
+ Map phases = new HashMap<>();
+ Map hotActions = new HashMap<>();
+ hotActions.put(RolloverAction.NAME, new RolloverAction(
+ new ByteSizeValue(50, ByteSizeUnit.GB), null, null));
+ phases.put("hot", new Phase("hot", TimeValue.ZERO, hotActions));
+
+ Map deleteActions =
+ Collections.singletonMap(DeleteAction.NAME,
+ new DeleteAction());
+ phases.put("delete",
+ new Phase("delete",
+ new TimeValue(90, TimeUnit.DAYS), deleteActions));
+
+ myPolicyAsPut = new LifecyclePolicy("my_policy", phases);
+ PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(myPolicyAsPut);
+
+ Map otherPolicyPhases = new HashMap<>(phases);
+ Map warmActions = Collections.singletonMap(ShrinkAction.NAME, new ShrinkAction(1));
+ otherPolicyPhases.put("warm", new Phase("warm", new TimeValue(30, TimeUnit.DAYS), warmActions));
+ otherPolicyAsPut = new LifecyclePolicy("other_policy", otherPolicyPhases);
+
+ PutLifecyclePolicyRequest putRequest2 = new PutLifecyclePolicyRequest(otherPolicyAsPut);
+
+ AcknowledgedResponse putResponse = client.indexLifecycle().
+ putLifecyclePolicy(putRequest, RequestOptions.DEFAULT);
+ assertTrue(putResponse.isAcknowledged());
+ AcknowledgedResponse putResponse2 = client.indexLifecycle().
+ putLifecyclePolicy(putRequest2, RequestOptions.DEFAULT);
+ assertTrue(putResponse2.isAcknowledged());
+ }
+
+ // tag::ilm-get-lifecycle-policy-request
+ GetLifecyclePolicyRequest allRequest =
+ new GetLifecyclePolicyRequest(); // <1>
+ GetLifecyclePolicyRequest request =
+ new GetLifecyclePolicyRequest("my_policy", "other_policy"); // <2>
+ // end::ilm-get-lifecycle-policy-request
+
+ // tag::ilm-get-lifecycle-policy-execute
+ GetLifecyclePolicyResponse response = client.indexLifecycle()
+ .getLifecyclePolicy(request, RequestOptions.DEFAULT);
+ // end::ilm-get-lifecycle-policy-execute
+
+ // tag::ilm-get-lifecycle-policy-response
+ ImmutableOpenMap policies =
+ response.getPolicies();
+ LifecyclePolicyMetadata myPolicyMetadata =
+ policies.get("my_policy"); // <1>
+ String myPolicyName = myPolicyMetadata.getName();
+ long version = myPolicyMetadata.getVersion();
+ String lastModified = myPolicyMetadata.getModifiedDateString();
+ long lastModifiedDate = myPolicyMetadata.getModifiedDate();
+ LifecyclePolicy myPolicy = myPolicyMetadata.getPolicy(); // <2>
+ // end::ilm-get-lifecycle-policy-response
+
+ assertEquals(myPolicyAsPut, myPolicy);
+ assertEquals("my_policy", myPolicyName);
+ assertNotNull(lastModified);
+ assertNotEquals(0, lastModifiedDate);
+
+ LifecyclePolicyMetadata otherPolicyMetadata = policies.get("other_policy");
+ assertEquals(otherPolicyAsPut, otherPolicyMetadata.getPolicy());
+ assertEquals("other_policy", otherPolicyMetadata.getName());
+ assertNotNull(otherPolicyMetadata.getModifiedDateString());
+ assertNotEquals(0, otherPolicyMetadata.getModifiedDate());
+
+ // tag::ilm-get-lifecycle-policy-execute-listener
+ ActionListener listener =
+ new ActionListener() {
+ @Override
+ public void onResponse(GetLifecyclePolicyResponse response)
+ {
+ ImmutableOpenMap
+ policies = response.getPolicies(); // <1>
+ }
+
+ @Override
+ public void onFailure(Exception e) {
+ // <2>
+ }
+ };
+ // end::ilm-get-lifecycle-policy-execute-listener
+
+ // Replace the empty listener by a blocking listener in test
+ final CountDownLatch latch = new CountDownLatch(1);
+ listener = new LatchedActionListener<>(listener, latch);
+
+ // tag::ilm-get-lifecycle-policy-execute-async
+ client.indexLifecycle().getLifecyclePolicyAsync(request,
+ RequestOptions.DEFAULT, listener); // <1>
+ // end::ilm-get-lifecycle-policy-execute-async
+
+ assertTrue(latch.await(30L, TimeUnit.SECONDS));
+ }
+
static Map toMap(Response response) throws IOException {
return XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false);
}
diff --git a/docs/java-rest/high-level/ilm/get_lifecycle_policy.asciidoc b/docs/java-rest/high-level/ilm/get_lifecycle_policy.asciidoc
new file mode 100644
index 0000000000000..b86fad5880f67
--- /dev/null
+++ b/docs/java-rest/high-level/ilm/get_lifecycle_policy.asciidoc
@@ -0,0 +1,40 @@
+--
+:api: ilm-get-lifecycle-policy
+:request: GetLifecyclePolicyRequest
+:response: GetLifecyclePolicyResponse
+--
+
+[id="{upid}-{api}"]
+=== Get Lifecycle Policy API
+
+
+[id="{upid}-{api}-request"]
+==== Request
+
+The Get Lifecycle Policy API allows you to retrieve the definition of an Index
+Lifecycle Management Policy from the cluster.
+
+["source","java",subs="attributes,callouts,macros"]
+--------------------------------------------------
+include-tagged::{doc-tests-file}[{api}-request]
+--------------------------------------------------
+<1> Gets all policies.
+<2> Gets `my_policy` and `other_policy`
+
+[id="{upid}-{api}-response"]
+==== Response
+
+The returned +{response}+ contains a map of `LifecyclePolicyMetadata`,
+accessible by the name of the policy, which contains data about each policy,
+as well as the policy definition.
+
+["source","java",subs="attributes,callouts,macros"]
+--------------------------------------------------
+include-tagged::{doc-tests-file}[{api}-response]
+--------------------------------------------------
+<1> The retrieved policies are retrieved by name.
+<2> The policy definition itself.
+
+include::../execution.asciidoc[]
+
+
diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc
index 880a8621f0598..5fa05135cc035 100644
--- a/docs/java-rest/high-level/supported-apis.asciidoc
+++ b/docs/java-rest/high-level/supported-apis.asciidoc
@@ -444,5 +444,8 @@ The Java High Level REST Client supports the following Index Lifecycle
Management APIs:
* <<{upid}-ilm-put-lifecycle-policy>>
+* <<{upid}-ilm-get-lifecycle-policy>>
include::ilm/put_lifecycle_policy.asciidoc[]
+include::ilm/get_lifecycle_policy.asciidoc[]
+