# Creating ilm policies in Java using new java api client

**URL:** <https://discuss.elastic.co/t/creating-ilm-policies-in-java-using-new-java-api-client/296375>\
**Category:** Elasticsearch\
**Tags:** ilm-index-lifecycle-management, language-clients\
**Created:** [February 6, 2022, 12:18am UTC](https://discuss.elastic.co/t/creating-ilm-policies-in-java-using-new-java-api-client/296375 "2022-02-06T00:18:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas35](https://avatars.discourse-cdn.com/v4/letter/n/51bf81/32.png) [@Nicolas35](https://discuss.elastic.co/u/Nicolas35)\
**Post date:** [February 6, 2022, 12:18am UTC](https://discuss.elastic.co/t/creating-ilm-policies-in-java-using-new-java-api-client/296375/1 "2022-02-06T00:18:43Z")

</div>

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:

```auto
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:

```auto
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!

---

<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:** [March 6, 2022, 12:19am UTC](https://discuss.elastic.co/t/creating-ilm-policies-in-java-using-new-java-api-client/296375/2 "2022-03-06T00:19:38Z")

</div>

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