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();
	try {		

		for(TargetField field:list){
			if(field.getFieldIndexable() != null && field.getFieldIndexable() ==3){
				String type="text";

				if(field.getFieldTypeSource().equals("int") || field.getFieldTypeSource().equals("long")){
				}else if(field.getFieldTypeSource().equals("double") || field.getFieldTypeSource().equals("float")){
				}else if(field.getFieldTypeSource().equals("geo_point")){
				}else if(field.getFieldTypeSource().equals("date")){
				if(type == null || type.length() == 0){

						mapping.startObject(field.getFieldNameTarget()).field("type", type).field("format", "strict_date_optional_time").endObject();	
						if(type.equals("text") || field.getFieldTypeIndex() != null && field.getFieldTypeIndex().equals("text")) {
							mapping.startObject(field.getFieldNameTarget()).field("type", type).field("fielddata", true).endObject();	
						}else {
						mapping.startObject(field.getFieldNameTarget()).field("type", type).endObject();	

	} catch (IOException e) {
	System.out.println(mapping);"Update index mapping "+indexName.toLowerCase());
	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


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.