Is it possiable to add one more filed to existing index in elastic search,using java API

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;

You should try to do it first using Kibana dev console. Then it will be easier to adapt your code accordingly.

Can you please share any example

See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html

i gothrough that earlier,i got a error like this
org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: mapping type is missing;

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

Hi we are using Java API

I know that.

I'm asking that you create a script that can run in Kibana dev console first.
Then we can help fixing the Java part of the problem.

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