# Create lifecycle policy with Java API client

**URL:** <https://discuss.elastic.co/t/create-lifecycle-policy-with-java-api-client/304383>\
**Category:** Elasticsearch\
**Tags:** ilm-index-lifecycle-management, language-clients\
**Created:** [May 10, 2022, 6:39pm UTC](https://discuss.elastic.co/t/create-lifecycle-policy-with-java-api-client/304383 "2022-05-10T18:39:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![frankmontyne](https://avatars.discourse-cdn.com/v4/letter/f/c6cbf5/32.png) [@frankmontyne](https://discuss.elastic.co/u/frankmontyne)\
**Post date:** [May 10, 2022, 6:39pm UTC](https://discuss.elastic.co/t/create-lifecycle-policy-with-java-api-client/304383/1 "2022-05-10T18:39:07Z")

</div>

Hi,

Can someone tell me how to write this lifecycle policy test with the new Java API client? It is completely unclear to me. By the way, is there more extensive documentation on how to use the Java API client?

The code below uses the high level rest client.

```auto
public void testLifecyclePolicy() throws Exception {
	Map<String, Phase> phases = new HashMap<>();

	Map<String, LifecycleAction> hotActions = new HashMap<>();
	hotActions.put(RolloverAction.NAME, new RolloverAction(null, null, null, 1L));
	phases.put("hot", new Phase("hot", TimeValue.ZERO, hotActions)); 
		
	Map<String, LifecycleAction> deleteActions = Collections.singletonMap(DeleteAction.NAME, new DeleteAction());
	phases.put("delete", new Phase("delete", new TimeValue(10, TimeUnit.SECONDS), deleteActions)); 

	AcknowledgedResponse createLifecyclePolicyResponse = hlRestClient.indexLifecycle().putLifecyclePolicy(
				new PutLifecyclePolicyRequest(new LifecyclePolicy("test-policy", phases)),
				RequestOptions.DEFAULT);
		
	Preconditions.checkState(createLifecyclePolicyResponse.isAcknowledged(), "Failed to create lifecycle test-policy");
}

```

Thanks!

---

<div class="post-metadata">

**Author:** ![frankmontyne](https://avatars.discourse-cdn.com/v4/letter/f/c6cbf5/32.png) [@frankmontyne](https://discuss.elastic.co/u/frankmontyne)\
**Post date:** [May 16, 2022, 10:29am UTC](https://discuss.elastic.co/t/create-lifecycle-policy-with-java-api-client/304383/2 "2022-05-16T10:29:04Z")

</div>

Figured it out meanwhile, I must say this new Java API is lacking quite a bit in documentation. I surely doesn't help that some parts are not fully implemented leaving us with parameters like JsonData that tell nothing about the object needs to be passed.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 13, 2022, 10:29am UTC](https://discuss.elastic.co/t/create-lifecycle-policy-with-java-api-client/304383/3 "2022-06-13T10:29:28Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
