# Adding one more field in an existing mapping.json

**URL:** <https://discuss.elastic.co/t/adding-one-more-field-in-an-existing-mapping-json/29896>\
**Category:** Elasticsearch\
**Created:** [September 24, 2015, 6:53am UTC](https://discuss.elastic.co/t/adding-one-more-field-in-an-existing-mapping-json/29896 "2015-09-24T06:53:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![siddharth\_gupta](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@siddharth\_gupta](https://discuss.elastic.co/u/siddharth_gupta)\
**Post date:** [September 24, 2015, 6:53am UTC](https://discuss.elastic.co/t/adding-one-more-field-in-an-existing-mapping-json/29896/1 "2015-09-24T06:53:57Z")

</div>

Hello,

I have a mapping.json file and want to add another field to it using PUT Mapping API.

I am using the below mentioned code :=\>

```auto
try {
            jsonDocMapping = XContentFactory.jsonBuilder()
                    
                    .startObject("docs")
                        .startObject("properties")
                            .startObject("MY_FIELD")
                                .field("type", "string")
                                .field("analyzer", "shingleAnalyzer")
                                .startObject("fields")
                                    .startObject("raw_standard_analyzer")
                                        .field("type","string")
                                    .endObject()
                                .endObject()
                            .endObject()
                        .endObject()
                    .endObject()
             ;
            map.source(jsonDocMapping).type();
        
    PutMappingResponse mapp = ESclient.admin().indices().putMapping(map).actionGet();
        
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

```

But I execute I face the following error :

```auto
Exception in thread "main" org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: mapping type is missing;
    at org.elasticsearch.action.ValidateActions.addValidationError(ValidateActions.java:29)
    at org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest.validate(PutMappingRequest.java:85)
    at org.elasticsearch.action.TransportActionNodeProxy.execute(TransportActionNodeProxy.java:52)
    at org.elasticsearch.client.transport.support.InternalTransportIndicesAdminClient$1.doWithNode(InternalTransportIndicesAdminClient.java:89)
    at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:205)
    at org.elasticsearch.client.transport.support.InternalTransportIndicesAdminClient.execute(InternalTransportIndicesAdminClient.java:86)
    at org.elasticsearch.client.transport.support.InternalTransportIndicesAdminClient.execute(InternalTransportIndicesAdminClient.java:77)
    at org.elasticsearch.client.support.AbstractIndicesAdminClient.putMapping(AbstractIndicesAdminClient.java:467)
    at com.gauge.legal.search.index.IndexManager.updateIndex(IndexManager.java:84)
    at com.gauge.legal.search.databind.MongoDBDataBinderForUpdatingIndex.getDataToUpdate(MongoDBDataBinderForUpdatingIndex.java:112)
    at com.gauge.legal.search.common.ESIndexer.main(ESIndexer.java:119)

```

Can anybody please suggest something ?

Thanks  
Siddharth

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 24, 2015, 10:58am UTC](https://discuss.elastic.co/t/adding-one-more-field-in-an-existing-mapping-json/29896/2 "2015-09-24T10:58:02Z")

</div>

You need to add `.setType("docs")`.

```auto
PutMappingResponse mapp = ESclient.admin().indices().setType("docs").putMapping(map).actionGet();

```

That might help you.

---

<div class="post-metadata">

**Author:** ![siddharth\_gupta](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@siddharth\_gupta](https://discuss.elastic.co/u/siddharth_gupta)\
**Post date:** [September 25, 2015, 4:03am UTC](https://discuss.elastic.co/t/adding-one-more-field-in-an-existing-mapping-json/29896/3 "2015-09-25T04:03:23Z")

</div>

Thanks! It is working now 😄

---

<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 5, 2017, 11:48pm UTC](https://discuss.elastic.co/t/adding-one-more-field-in-an-existing-mapping-json/29896/4 "2017-07-05T23:48:09Z")

</div>


