ElasticSearch, ingest-attachment error - Validation Failed: 1: source is missing;2: content type is missing

Am trying to indexing my pdf file from local path via java code. During indexing am getting the below error.

Exception in thread "main" org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: source is missing;2: content type is missing;
	at org.elasticsearch.action.ValidateActions.addValidationError(ValidateActions.java:26)
	at org.elasticsearch.action.index.IndexRequest.validate(IndexRequest.java:153)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:436)
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:429)
	at org.elasticsearch.client.RestHighLevelClient.index(RestHighLevelClient.java:312)
	at com.es.utility.DocumentIndex.main(DocumentIndex.java:82)

Please find my java code below.

public static void main(String args[]) throws IOException {
	String filePath = "D:\\\\1SearchEngine\\testing.pdf";
	String encodedfile = null;
	RestHighLevelClient restHighLevelClient = null;
	File file = new File(filePath);
	try {
		FileInputStream fileInputStreamReader = new FileInputStream(file);
		byte[] bytes = new byte[(int) file.length()];
		fileInputStreamReader.read(bytes);
		encodedfile = new String(Base64.getEncoder().encodeToString(bytes));
		//System.out.println(encodedfile);
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	}

	try {
		if (restHighLevelClient != null) {
			restHighLevelClient.close();
		}
	} catch (final Exception e) {
		System.out.println("Error closing ElasticSearch client: ");
	}

	try {
		restHighLevelClient = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http"),
				new HttpHost("localhost", 9201, "http")));
	} catch (Exception e) {
		System.out.println(e.getMessage());
	}
	
	IndexRequest request = new IndexRequest( "attach_local", "doc", "103");   
	Map<String, Object> jsonMap = new HashMap<>();
	jsonMap.put("resume", "Karthikeyan");
	jsonMap.put("postDate", new Date());
	jsonMap.put("resume", encodedfile);
	try {
	    IndexResponse response = restHighLevelClient.index(request);
	} catch(ElasticsearchException e) {
	    if (e.status() == RestStatus.CONFLICT) {
	        
	    }
	}
}

Please find my mapping file for attachment

PUT attach_local
{
  "mappings" : {
	"doc" : {
	  "properties" : {
		"attachment" : {
		  "properties" : {
			"content" : {
			  "type" : "binary"
			},
			"content_length" : {
			  "type" : "long"
			},
			"content_type" : {
			  "type" : "text"
			},
			"language" : {
			  "type" : "text"
			}
		  }
		},
		"resume" : {
		  "type" : "text"
		}
	  }
	}
  }
}

Am using ElasticSearch 6.2.3 version and i have installed ingest-attachment plugin version 6.3.0

Please find the document available in my index, which i indexed to ElasticSearch via curl script in kibana

  "took": 41,
  "timed_out": false,
  "_shards": {
	"total": 5,
	"successful": 5,
	"skipped": 0,
	"failed": 0
  },
  "hits": {
	"total": 2,
	"max_score": 1,
	"hits": [
	  {
		"_index": "attach_local",
		"_type": "doc",
		"_id": "101",
		"_score": 1,
		"_source": {
		  "resume": "e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0=",
		  "attachment": {
			"content_type": "application/rtf",
			"language": "ro",
			"content": "Lorem ipsum dolor sit amet",
			"content_length": 28
		  }
		}
	  }

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