# Put a mapping using java api not working

**URL:** <https://discuss.elastic.co/t/put-a-mapping-using-java-api-not-working/20218>\
**Category:** Elasticsearch\
**Created:** [October 13, 2014, 1:16pm UTC](https://discuss.elastic.co/t/put-a-mapping-using-java-api-not-working/20218 "2014-10-13T13:16:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aris\_Alexis](https://avatars.discourse-cdn.com/v4/letter/a/76d3ee/32.png) [@Aris\_Alexis](https://discuss.elastic.co/u/Aris_Alexis)\
**Post date:** [October 13, 2014, 1:16pm UTC](https://discuss.elastic.co/t/put-a-mapping-using-java-api-not-working/20218/1 "2014-10-13T13:16:52Z")

</div>

hi,

can you quickly spot any errors in my code? it fails with root type not  
empty

```
XContentBuilder mapping = null;
    try {
        mapping = jsonBuilder()
                .startObject()
                .startObject("message")
                .startObject("_parent")
                .field("type", "chat")
                .endObject()
                .endObject()
                .endObject();
    } catch (IOException e) {
        e.printStackTrace();
    }

    PutMappingResponse putMappingResponse = client.admin().indices()
            .preparePutMapping("messages")
            .setType("chat")
            .setSource(mapping)
            .execute().actionGet();
}

```

messages=index  
chat=parent document  
message=child document

error = Root type mapping not empty after parsing! Remaining fields:  
[message : {\_parent={type=chat}}]

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/fae56ba3-6bac-418d-8075-eafba49f5a28%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fae56ba3-6bac-418d-8075-eafba49f5a28%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 12:56am UTC](https://discuss.elastic.co/t/put-a-mapping-using-java-api-not-working/20218/2 "2017-07-06T00:56:33Z")

</div>


