java.lang.IllegalArgumentException Error using Bulk Update API

Hello people,
I am trying to bulk update in elasticSearch using java.
I have a JSON list and I'm passing that list in bulk request to update, but its throwing an error as below :
Exception in thread "main" java.lang.IllegalArgumentException: The number of object passed must be even but was [1]
at org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:474)
at com.elastic.search.BulkUpdateApi.main(BulkUpdateApi.java:48)

My java code is :

RestHighLevelClient highLevelRestClient = new RestHighLevelClient(builder);

	BulkRequest bulkRequest = new BulkRequest();
	File file = new File("D:\\local\\list.JSON");
	
	bulkRequest.add(new IndexRequest().source(XContentType.JSON, file));
	
	try {
		
		BulkResponse bulkResponse = highLevelRestClient.bulk(bulkRequest, RequestOptions.DEFAULT);
		String a = "dummy";
		System.out.println(bulkResponse.toString());
		
	} catch (IOException e) {
		e.printStackTrace();
	}finally{
		try {
			highLevelRestClient.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

My JSON File is :

{ "update" : {"_id" : "1", "_index" : "dummy", "retry_on_conflict" : 3} }
{ "doc" : {"price" : "420"} }
{ "update" : { "_id" : "2", "_index" : "dummy", "retry_on_conflict" : 3} }
{ "doc" : {"price" : "520"}, "doc_as_upsert" : true }
{ "update" : {"_id" : "3", "_index" : "dummy", "_source" : true} }
{ "doc" : {"price" : "120"} }
{ "update" : {"_id" : "4", "_index" : "dummy"} }
{ "doc" : {"price" : "320"}, "_source": true}

One important thing is to also end the JSON file with a newline character, maybe that is not the case?

No. That might not be the case

what line ending do you use?

Also, does a curl (or another command line HTTP client) request instead of your java code work as expected with that file?

My JSON file is as above i shared.
I don't know about curl. m doing using java

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