# How to create Nested field in index using Java Client 8

**URL:** <https://discuss.elastic.co/t/how-to-create-nested-field-in-index-using-java-client-8/347496>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [November 20, 2023, 5:37am UTC](https://discuss.elastic.co/t/how-to-create-nested-field-in-index-using-java-client-8/347496 "2023-11-20T05:37:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Work\_account](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/james_work_account/32/124186_2.png) [@James\_Work\_account](https://discuss.elastic.co/u/James_Work_account)\
**Post date:** [November 20, 2023, 5:37am UTC](https://discuss.elastic.co/t/how-to-create-nested-field-in-index-using-java-client-8/347496/1 "2023-11-20T05:37:35Z")

</div>

I have an ES index that is created from Java code level when I index a POJO with ElasticsearchClient.

How do I specify that I need certain fields to be type: "nested" in my index?

---

<div class="post-metadata">

**Author:** ![swallez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/swallez/32/11972_2.png) [@swallez](https://discuss.elastic.co/u/swallez)\
**Post date:** [November 20, 2023, 7:29pm UTC](https://discuss.elastic.co/t/how-to-create-nested-field-in-index-using-java-client-8/347496/2 "2023-11-20T19:29:27Z")

</div>

You have to create the index with an index mapping that defines those fields as nested. With that mapping in place, the corresponding fields will be indexed as nested values.

> **[Nested field type | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html)**

---

<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:** [December 18, 2023, 7:30pm UTC](https://discuss.elastic.co/t/how-to-create-nested-field-in-index-using-java-client-8/347496/3 "2023-12-18T19:30:02Z")

</div>

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