Hi Team,
I trying to add one more field to existing in elastic search using JAVA API.
PutMappingRequest request = new PutMappingRequest(indexName);
XContentBuilder mapping = XContentFactory.jsonBuilder();
mapping.startObject();
try {
for(TargetField field:list){
if(field.getFieldIndexable() != null && field.getFieldIndexable() ==3){
String type="text";
if(field.getFieldTypeSource().equals("int") || field.getFieldTypeSource().equals("long")){
type="text";
}else if(field.getFieldTypeSource().equals("double") || field.getFieldTypeSource().equals("float")){
type="double";
}else if(field.getFieldTypeSource().equals("geo_point")){
type="geo_point";
}else if(field.getFieldTypeSource().equals("date")){
type="date";
}
if(type == null || type.length() == 0){
type="text";
}
if(type.equals("date")){
mapping.startObject(field.getFieldNameTarget()).field("type", type).field("format", "strict_date_optional_time").endObject();
}else{
if(type.equals("text") || field.getFieldTypeIndex() != null && field.getFieldTypeIndex().equals("text")) {
type="text";
mapping.startObject(field.getFieldNameTarget()).field("type", type).field("fielddata", true).endObject();
}else {
mapping.startObject(field.getFieldNameTarget()).field("type", type).endObject();
}}
}
}
mapping.endObject();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(mapping);
logger.info("Update index mapping "+indexName.toLowerCase());
request.source(mapping).type();
AcknowledgedResponse mapp = client.admin().indices().putMapping(request).actionGet();
Getting Error:org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: mapping type is missing;