# java.lang.IllegalArgumentException Error using Bulk Update API

**URL:** <https://discuss.elastic.co/t/java-lang-illegalargumentexception-error-using-bulk-update-api/217306>\
**Category:** Elasticsearch\
**Created:** [January 31, 2020, 7:01am UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-error-using-bulk-update-api/217306 "2020-01-31T07:01:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Toshif](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@Toshif](https://discuss.elastic.co/u/Toshif)\
**Post date:** [January 31, 2020, 7:01am UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-error-using-bulk-update-api/217306/1 "2020-01-31T07:01:12Z")

</div>

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}

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 31, 2020, 9:32am UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-error-using-bulk-update-api/217306/2 "2020-01-31T09:32:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Toshif](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@Toshif](https://discuss.elastic.co/u/Toshif)\
**Post date:** [January 31, 2020, 9:44am UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-error-using-bulk-update-api/217306/3 "2020-01-31T09:44:55Z")

</div>

No. That might not be the case

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 31, 2020, 9:47am UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-error-using-bulk-update-api/217306/4 "2020-01-31T09:47:27Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Toshif](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@Toshif](https://discuss.elastic.co/u/Toshif)\
**Post date:** [January 31, 2020, 9:50am UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-error-using-bulk-update-api/217306/5 "2020-01-31T09:50:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 28, 2020, 9:50am UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-error-using-bulk-update-api/217306/6 "2020-02-28T09:50:43Z")

</div>

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