# java.lang.ArrayIndexOutOfBoundsException: 1 while preparing the index

**URL:** <https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-1-while-preparing-the-index/13900>\
**Category:** Elasticsearch\
**Created:** [October 10, 2013, 7:43am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-1-while-preparing-the-index/13900 "2013-10-10T07:43:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiran](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kiran](https://discuss.elastic.co/u/kiran)\
**Post date:** [October 10, 2013, 7:43am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-1-while-preparing-the-index/13900/1 "2013-10-10T07:43:34Z")

</div>

I have windows 7 32 bit os  
Elastic search is running separately  
Java Version: 1.7.0\_25

I am new to elastic search, I have not made any changes in  
elasticsearch.yml file  
I have added the mapping using chrome plugin sense

Mapping  
gatereader/gate/\_mapping  
{  
"gate" : {  
"\_id":{  
"path":"id"  
},  
"properties": {  
"id" : {"type": "long"},  
"name" : {"type": "string"},  
"description" : {"type": "string"},  
"isActive" : {"type": "boolean"},  
"gateReaderEntityList" :  
{"type": "object",  
"properties": {  
"id" : {"type": "long"},  
"readerName" : {"type": "string"},  
"readerRefName" : {"type": "string"},  
"isActive" : {"type": "boolean"},  
"readerType" : {"type": "string"}  
}  
}  
}  
}  
}

JSON String:  
{"id":1,"isActive":true,"description":"","name":"gate","gateReaderEntityList":[{"id":1,"isActive":true,"readerRefName":"Reader","readerType":{"readerType":"Exit"},"readerName":"Reader1"},{"id":2,"isActive":true,"readerRefName":"Reader2","readerType":{"readerType":"Exit"},"readerName":"Reader2"},{"id":3,"isActive":true,"readerRefName":"Reader3","readerType":{"readerType":"Exit"},"readerName":"Reader3"},{"id":4,"isActive":true,"readerRefName":"ExReader1","readerType":{"readerType":"Exit"},"readerName":"ExReader1"},{"id":5,"isActive":true,"readerRefName":"ExReader2","readerType":{"readerType":"Exit"},"readerName":"ExReader2"}]}

Java Code:  
Settings settings = ImmutableSettings.settingsBuilder().put()  
.put("client.transport.ignore\_cluster\_name", false).build();

```
    Client client = new 

```

TransportClient(settings).addTransportAddress(new  
InetSocketTransportAddress("localhost", 9300));

```
        IndexResponse response1 = client.prepareIndex("gatereader", 

```

"gate", String.valueOf(1))  
.setSource(jsonstring).execute().actionGet();

I am getting exception  
java.lang.ArrayIndexOutOfBoundsException: 1  
at  
org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:419)  
at  
org.elasticsearch.action.index.IndexRequestBuilder.setSource(IndexRequestBuilder.java:209)  
at  
waidTenant.ApplicationContextLoader.elasticsearch(ApplicationContextLoader.java:230)  
at  
waidTenant.ApplicationContextLoader.main(ApplicationContextLoader.java:164)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [October 10, 2013, 8:27am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-1-while-preparing-the-index/13900/2 "2013-10-10T08:27:51Z")

</div>

The number of arguments that you are passing to:

```
at 

```

org.elasticsearch.action.index.IndexRequestBuilder.setSource(IndexRequestBuilder.java:209)

must be even, I guess it's an odd number? Can you tell what args you are  
passing to it?

simon  
On Thursday, October 10, 2013 9:43:34 AM UTC+2, kiran wrote:

> I have windows 7 32 bit os  
> Elastic search is running separately  
> Java Version: 1.7.0\_25
> 
> I am new to Elasticsearch, I have not made any changes in  
> elasticsearch.yml file  
> I have added the mapping using chrome plugin sense
> 
> Mapping  
> gatereader/gate/\_mapping  
> {  
> "gate" : {  
> "\_id":{  
> "path":"id"  
> },  
> "properties": {  
> "id" : {"type": "long"},  
> "name" : {"type": "string"},  
> "description" : {"type": "string"},  
> "isActive" : {"type": "boolean"},  
> "gateReaderEntityList" :  
> {"type": "object",  
> "properties": {  
> "id" : {"type": "long"},  
> "readerName" : {"type": "string"},  
> "readerRefName" : {"type": "string"},  
> "isActive" : {"type": "boolean"},  
> "readerType" : {"type": "string"}  
> }  
> }  
> }  
> }  
> }
> 
> JSON String:
> 
> {"id":1,"isActive":true,"description":"","name":"gate","gateReaderEntityList":[{"id":1,"isActive":true,"readerRefName":"Reader","readerType":{"readerType":"Exit"},"readerName":"Reader1"},{"id":2,"isActive":true,"readerRefName":"Reader2","readerType":{"readerType":"Exit"},"readerName":"Reader2"},{"id":3,"isActive":true,"readerRefName":"Reader3","readerType":{"readerType":"Exit"},"readerName":"Reader3"},{"id":4,"isActive":true,"readerRefName":"ExReader1","readerType":{"readerType":"Exit"},"readerName":"ExReader1"},{"id":5,"isActive":true,"readerRefName":"ExReader2","readerType":{"readerType":"Exit"},"readerName":"ExReader2"}]}
> 
> Java Code:  
> Settings settings = ImmutableSettings.settingsBuilder().put()  
> .put("client.transport.ignore\_cluster\_name",  
> false).build();
> 
> ```
> Client client = new 
> 
> ```
> 
> TransportClient(settings).addTransportAddress(new  
> InetSocketTransportAddress("localhost", 9300));
> 
> ```
> IndexResponse response1 = client.prepareIndex("gatereader", 
> 
> ```
> 
> "gate", String.valueOf(1))  
> .setSource(jsonstring).execute().actionGet();
> 
> I am getting exception  
> java.lang.ArrayIndexOutOfBoundsException: 1  
> at  
> org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:419)  
> at  
> org.elasticsearch.action.index.IndexRequestBuilder.setSource(IndexRequestBuilder.java:209)  
> at  
> waidTenant.ApplicationContextLoader.elasticsearch(ApplicationContextLoader.java:230)  
> at  
> waidTenant.ApplicationContextLoader.main(ApplicationContextLoader.java:164)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![kiran](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kiran](https://discuss.elastic.co/u/kiran)\
**Post date:** [October 10, 2013, 8:34am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-1-while-preparing-the-index/13900/3 "2013-10-10T08:34:04Z")

</div>

IndexResponse response1 = client.prepareIndex("gatereader", "gate",  
String.valueOf(gateEntry.getKey()))  
.setSource(new JSONObject("").execute().actionGet();

On Thursday, October 10, 2013 1:57:51 PM UTC+5:30, simonw wrote:

> The number of arguments that you are passing to:
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.action.index.IndexRequestBuilder.setSource(IndexRequestBuilder.java:209)
> 
> must be even, I guess it's an odd number? Can you tell what args you are  
> passing to it?
> 
> simon  
> On Thursday, October 10, 2013 9:43:34 AM UTC+2, kiran wrote:
> 
> > I have windows 7 32 bit os  
> > Elastic search is running separately  
> > Java Version: 1.7.0\_25
> > 
> > I am new to Elasticsearch, I have not made any changes in  
> > elasticsearch.yml file  
> > I have added the mapping using chrome plugin sense
> > 
> > Mapping  
> > gatereader/gate/\_mapping  
> > {  
> > "gate" : {  
> > "\_id":{  
> > "path":"id"  
> > },  
> > "properties": {  
> > "id" : {"type": "long"},  
> > "name" : {"type": "string"},  
> > "description" : {"type": "string"},  
> > "isActive" : {"type": "boolean"},  
> > "gateReaderEntityList" :  
> > {"type": "object",  
> > "properties": {  
> > "id" : {"type": "long"},  
> > "readerName" : {"type": "string"},  
> > "readerRefName" : {"type": "string"},  
> > "isActive" : {"type": "boolean"},  
> > "readerType" : {"type": "string"}  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > JSON String:
> > 
> > {"id":1,"isActive":true,"description":"","name":"gate","gateReaderEntityList":[{"id":1,"isActive":true,"readerRefName":"Reader","readerType":{"readerType":"Exit"},"readerName":"Reader1"},{"id":2,"isActive":true,"readerRefName":"Reader2","readerType":{"readerType":"Exit"},"readerName":"Reader2"},{"id":3,"isActive":true,"readerRefName":"Reader3","readerType":{"readerType":"Exit"},"readerName":"Reader3"},{"id":4,"isActive":true,"readerRefName":"ExReader1","readerType":{"readerType":"Exit"},"readerName":"ExReader1"},{"id":5,"isActive":true,"readerRefName":"ExReader2","readerType":{"readerType":"Exit"},"readerName":"ExReader2"}]}
> > 
> > Java Code:  
> > Settings settings = ImmutableSettings.settingsBuilder().put()  
> > .put("client.transport.ignore\_cluster\_name",  
> > false).build();
> > 
> > ```
> > Client client = new 
> > 
> > ```
> > 
> > TransportClient(settings).addTransportAddress(new  
> > InetSocketTransportAddress("localhost", 9300));
> > 
> > ```
> > IndexResponse response1 = client.prepareIndex("gatereader", 
> > 
> > ```
> > 
> > "gate", String.valueOf(1))  
> > .setSource(jsonstring).execute().actionGet();
> > 
> > I am getting exception  
> > java.lang.ArrayIndexOutOfBoundsException: 1  
> > at  
> > org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:419)  
> > at  
> > org.elasticsearch.action.index.IndexRequestBuilder.setSource(IndexRequestBuilder.java:209)  
> > at  
> > waidTenant.ApplicationContextLoader.elasticsearch(ApplicationContextLoader.java:230)  
> > at  
> > waidTenant.ApplicationContextLoader.main(ApplicationContextLoader.java:164)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![kiran](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kiran](https://discuss.elastic.co/u/kiran)\
**Post date:** [October 10, 2013, 8:49am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-1-while-preparing-the-index/13900/4 "2013-10-10T08:49:04Z")

</div>

Thanks for the reply,  
I got it working, earlier I was adding the JSON object directly to the  
source now i changed to json string.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [October 10, 2013, 9:43am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-1-while-preparing-the-index/13900/5 "2013-10-10T09:43:39Z")

</div>

I just pushed a better error message for this:

> <https://github.com/elastic/elasticsearch/commit/e14e2a6597d2d580e34d28851d5047739f451407>
>
> Added checks to IndexRequest#source(Object...) to ensure and even number
> of para…meters. This method otherwise throws an AIOOBException which is
> confusing to users and doesn't report the root cause of the problem.

simon

On Thursday, October 10, 2013 10:49:04 AM UTC+2, kiran wrote:

> Thanks for the reply,  
> I got it working, earlier I was adding the JSON object directly to the  
> source now i changed to json string.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:13am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-1-while-preparing-the-index/13900/6 "2017-07-06T02:13:03Z")

</div>


