Creating ilm policies in Java using new java api client

Hi,

I am stuck creating a policy in java using the new java api client.
I am using Elasticsearch-java 7.16.2

Here is the faulty code:

String json= "{\"allocate\" : {\"number_of_replicas\" : 1},"
              + "\"forcemerge\" : {\"max_num_segments\" : 1}}";

client.ilm().putLifecycle(b -> b.name("ilm-policy-" + indexName)
        			.policy(p -> p.name("test").phases(phase -> phase
        					.warm(p2 -> p2.actions(JsonData.of(json)).minAge(Time.of(t -> t.time("75m")))))));

Here is the error:

2022-02-05 23:26:29,308 [main] TRACE tracer  - curl -iX PUT 'https://localhost:9200/_ilm/policy/ilm-policy-test' -d '{"policy":{"phases":{"warm":{"actions":"{\"allocate\" : {\"number_of_replicas\" : 1},\"forcemerge\" : {\"max_num_segments\" : 1}}","min_age":"75m"}},"name":"test"}}'
# HTTP/1.1 400 Bad Request
# content-type: application/json; charset=UTF-8
# content-length: 613
#
# {"error":{"root_cause":[{"type":"x_content_parse_exception","reason":"[1:40] [phase] actions doesn't support values of type: VALUE_STRING"}],"type":"x_content_parse_exception","reason":"[1:40] [put_lifecycle_request] failed to parse field [policy]","caused_by":{"type":"x_content_parse_exception","reason":"[1:40] [lifecycle_policy] failed to parse field [phases]","caused_by":{"type":"x_content_parse_exception","reason":"[1:40] [phases] failed to parse field [warm]","caused_by":{"type":"x_content_parse_exception","reason":"[1:40] [phase] actions doesn't support values of type: VALUE_STRING"}}}},"status":400}
Exception in thread "main" co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/ilm.put_lifecycle] failed: [x_content_parse_exception] [1:40] [put_lifecycle_request] failed to parse field [policy]

There is an issue with JsonData I can't solve.
Any help would be appreciated, i can't find documentation on that part.

Thank you!

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