Adding one more field in an existing mapping.json

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 :=>

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 :

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

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

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

That might help you.

Thanks! It is working now :smile: