# How to add nested datatype using Java api?

**URL:** <https://discuss.elastic.co/t/how-to-add-nested-datatype-using-java-api/263542>\
**Category:** Elasticsearch\
**Created:** [February 8, 2021, 5:20am UTC](https://discuss.elastic.co/t/how-to-add-nested-datatype-using-java-api/263542 "2021-02-08T05:20:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rohit.singh3](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@rohit.singh3](https://discuss.elastic.co/u/rohit.singh3)\
**Post date:** [February 8, 2021, 5:20am UTC](https://discuss.elastic.co/t/how-to-add-nested-datatype-using-java-api/263542/1 "2021-02-08T05:20:44Z")

</div>

Below is the sample snippet:

```auto
"price":{  
           "type":"nested", --> how to add this nested type?
           "properties":{  
              "activity_price":{  
                 "type":"double"
              },
              "multimedia_price":{  
                 "type":"double"
              },
              "transportation_price":{  
                 "type":"double"
              }
           }
        }

```

I want to perform nested query on it using java api but getting **[nested] nested object under path [price] is not of nested type.**

Currently I am using XContentBuilder.jsonBuilder() for mapping in java code.

---

<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 8, 2021, 5:21am UTC](https://discuss.elastic.co/t/how-to-add-nested-datatype-using-java-api/263542/2 "2021-03-08T05:21:14Z")

</div>

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