# Number of object passed must be even

**URL:** <https://discuss.elastic.co/t/number-of-object-passed-must-be-even/1200>\
**Category:** Elasticsearch\
**Created:** [May 23, 2015, 5:05am UTC](https://discuss.elastic.co/t/number-of-object-passed-must-be-even/1200 "2015-05-23T05:05:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![GoldMarc](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@GoldMarc](https://discuss.elastic.co/u/GoldMarc)\
**Post date:** [May 23, 2015, 5:05am UTC](https://discuss.elastic.co/t/number-of-object-passed-must-be-even/1200/1 "2015-05-23T05:05:45Z")

</div>

Hello,

Iam new on elasticsearch, and I want to play a little.

I used a simple Java-Code to insert one document:

> ```
> Node node = NodeBuilder.nodeBuilder().clusterName("Suche")
> .node();
> Client client = node.client();
> 
> ```

> ```
> JSONObject obj = new JSONObject();
> 
> ```

> ```
> try {
> obj.put("id", "1");
> obj.put("adresse", "USA");
> } catch (Exception e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> 
> ```

> ```
> IndexRequest indexRequest = new IndexRequest("Test", "Adresses");
> indexRequest.source(obj);
> IndexResponse response = client.index(indexRequest).actionGet();
> 
> ```

> ```
> node.close(); 
> 
> ```

But well, I got an exception

The number of object passed must be even but was [1]

Can anyone help? Thanks.

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [May 23, 2015, 7:24am UTC](https://discuss.elastic.co/t/number-of-object-passed-must-be-even/1200/2 "2015-05-23T07:24:21Z")

</div>

This is because JSONObject is not allowed as a request source. Alternatively, you could use a map, or simply do

```auto
indexrequest.source("id", "1", "adresse", "USA");

```

---

<div class="post-metadata">

**Author:** ![GoldMarc](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@GoldMarc](https://discuss.elastic.co/u/GoldMarc)\
**Post date:** [May 23, 2015, 8:33am UTC](https://discuss.elastic.co/t/number-of-object-passed-must-be-even/1200/3 "2015-05-23T08:33:20Z")

</div>

Thanks for the fast response.

---

<div class="post-metadata">

**Author:** ![mshv](https://avatars.discourse-cdn.com/v4/letter/m/9de053/32.png) [@mshv](https://discuss.elastic.co/u/mshv)\
**Post date:** [June 22, 2015, 8:13am UTC](https://discuss.elastic.co/t/number-of-object-passed-must-be-even/1200/4 "2015-06-22T08:13:16Z")

</div>

I have the same issue

BulkRequestBuilder bulkRequest = client.prepareBulk();

```
	  for (int i = 0; i < jsonDataList.length(); i++) { //
	 
		  System.out.println(jsonDataList.optJSONObject(i)); 
		  JSONObject object = jsonDataList.optJSONObject(i);
	  
	  Map<String, String> map = new HashMap<String, String>(); 
		  Iterator keys = object.keys();
	  
	  try { while (keys.hasNext()) { 
		  String key = (String) keys.next();
		  map.put(key, object.get(key).toString()); 
		  } 
	  System.out.println(map);
	  

	   bulkRequest.add(client.prepareIndex(INDEX_NAME, INDEX_TYPE,object.get("id").toString())
			   .setSource(map)); //JSONObject is not allowed as a request source 
	   } catch (JSONException e) { 
		   // TODO Auto-generated catch block e.printStackTrace(); 
		   } 
	  } // ::End of for
	  // brb.execute().actionGet();
	  
	  BulkResponse bulkResponse = bulkRequest.execute().actionGet();

```

anyone can help ?

---

<div class="post-metadata">

**Author:** ![becjit](https://avatars.discourse-cdn.com/v4/letter/b/2bfe46/32.png) [@becjit](https://discuss.elastic.co/u/becjit)\
**Post date:** [June 25, 2015, 5:25am UTC](https://discuss.elastic.co/t/number-of-object-passed-must-be-even/1200/5 "2015-06-25T05:25:50Z")

</div>

use `Map<String, Object>` instead of `Map <String,String>`. see [Stackoverflow Question](http://stackoverflow.com/questions/31033717/error-in-bulkrequest-java-api-in-elasticsearch-the-number-of-object-passed-mu)

---

<div class="post-metadata">

**Author:** ![Harshit](https://avatars.discourse-cdn.com/v4/letter/h/c57346/32.png) [@Harshit](https://discuss.elastic.co/u/Harshit)\
**Post date:** [February 14, 2017, 6:31am UTC](https://discuss.elastic.co/t/number-of-object-passed-must-be-even/1200/6 "2017-02-14T06:31:51Z")

</div>

I have same issue Regarding this but i pass  
**ArrayList\<ArrayList\> batch = new ArrayList\<ArrayList\>();**

Is there any solution ?????????????

`BulkProcessor bulkProcessor = BulkProcessor.builder(client, new BulkProcessor.Listener() {

```
		public void beforeBulk(long arg0, BulkRequest arg1) {
			// TODO Auto-generated method stub

		}

		public void afterBulk(long arg0, BulkRequest arg1, Throwable arg2) {
			// TODO Auto-generated method stub

		}

		public void afterBulk(long arg0, BulkRequest arg1, BulkResponse arg2) {
			// TODO Auto-generated method stub

		}
	}).setBulkActions(1000).build();
	bulkProcessor.add(new IndexRequest(index, type).source(batch));
}`
```

---

<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:** [July 5, 2017, 10:03pm UTC](https://discuss.elastic.co/t/number-of-object-passed-must-be-even/1200/7 "2017-07-05T22:03:16Z")

</div>


