Create lifecycle policy with Java API client

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.

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!

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.

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