# Java.lang.ArrayIndexOutOfBoundsException 0?

**URL:** <https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993>\
**Category:** Elasticsearch\
**Created:** [March 4, 2013, 11:27am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993 "2013-03-04T11:27:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jingang\_Wang](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jingang\_Wang](https://discuss.elastic.co/u/Jingang_Wang)\
**Post date:** [March 4, 2013, 11:27am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/1 "2013-03-04T11:27:22Z")

</div>

Hi guys,

I am created indices in my data and began to make some queries on it. I  
could get the hits number, but I can not get the search results. following  
is my code in java.  
Can anybody tell my what I have missed? Thanks.

Node node = nodeBuilder().clusterName("myelasticsearch").node();  
Client client = node.client();  
QueryBuilder qb = QueryBuilders  
.boolQuery()  
.should(termQuery("kba.body.cleansed","steve"))  
.should(termQuery("kba.body.cleansed","ballmer"))  
.should(termQuery("kba.body.cleansed","Gaylor"));  
SearchResponse searchResponse = client.prepareSearch("test")  
.setQuery(qb)  
.execute()  
.actionGet();  
System.out.println("there are " + searchResponse.getHits().totalHits() +"  
hits in this search");  
SearchHits hits = searchResponse.getHits();  
for (int i = 0; i \< searchResponse.getHits().totalHits(); i++)  
{  
System.out.println(hits.getAt(i).getSource().get("doc\_id"));  
}

After I ran my code, it would output there are 2 hits in this search, but I  
can not iterator the SearchHits, and the exception just like following:

_Exception in thread "main" there are 2 hits in this search_  
_java.lang.ArrayIndexOutOfBoundsException: 0_

- at  
org.elasticsearch.search.internal.InternalSearchHits.getAt(InternalSearchHits.java:144)
- 

--  
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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 4, 2013, 11:37am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/2 "2013-03-04T11:37:59Z")

</div>

Have a look here: [https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267](https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267)

```
	for (SearchHit hit : searchResponse.getHits()) {
		// in hit.getSource(), you will be able to get your doc
	}

```

Note that you can't do a loop on totalHits as Elasticsearch will return by default the first ten hits.  
So if you hit 1 000 000 docs, you can't iterate on 1 000 000 (and you probably don't want to do it).

Does it help?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 4 mars 2013 à 12:27, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :

> Hi guys,
> 
> I am created indices in my data and began to make some queries on it. I could get the hits number, but I can not get the search results. following is my code in java.  
> Can anybody tell my what I have missed? Thanks.
> 
> Node node = nodeBuilder().clusterName("myelasticsearch").node();   
> Client client = node.client();  
> QueryBuilder qb = QueryBuilders  
> .boolQuery()  
> .should(termQuery("kba.body.cleansed","steve"))  
> .should(termQuery("kba.body.cleansed","ballmer"))  
> .should(termQuery("kba.body.cleansed","Gaylor"));  
> SearchResponse searchResponse = client.prepareSearch("test")  
> .setQuery(qb)  
> .execute()  
> .actionGet();  
> System.out.println("there are " + searchResponse.getHits().totalHits() +" hits in this search");  
> SearchHits hits = searchResponse.getHits();  
> for (int i = 0; i \< searchResponse.getHits().totalHits(); i++)  
> {  
> System.out.println(hits.getAt(i).getSource().get("doc\_id"));  
> }
> 
> After I ran my code, it would output there are 2 hits in this search, but I can not iterator the SearchHits, and the exception just like following:
> 
> Exception in thread "main" there are 2 hits in this search  
> java.lang.ArrayIndexOutOfBoundsException: 0  
> at org.elasticsearch.search.internal.InternalSearchHits.getAt(InternalSearchHits.java:144)
> 
> --  
> 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).

--  
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:** ![Jingang\_Wang](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jingang\_Wang](https://discuss.elastic.co/u/Jingang_Wang)\
**Post date:** [March 4, 2013, 11:46am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/3 "2013-03-04T11:46:44Z")

</div>

Hi David,  
Thanks so much for your reply. It really helps.  
However, I have tried your means, it also could not iterate in the hits  
results.

On Mon, Mar 4, 2013 at 7:37 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Have a look here:  
> [https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267](https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267)
> 
> ```
> for (SearchHit hit : searchResponse.getHits()) {
> // in hit.getSource(), you will be able to get your doc
> }
> 
> ```
> 
> Note that you can't do a loop on totalHits as Elasticsearch will return by  
> default the first ten hits.  
> So if you hit 1 000 000 docs, you can't iterate on 1 000 000 (and you  
> probably don't want to do it).
> 
> Does it help?
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 4 mars 2013 à 12:27, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> 
> Hi guys,
> 
> I am created indices in my data and began to make some queries on it. I  
> could get the hits number, but I can not get the search results. following  
> is my code in java.  
> Can anybody tell my what I have missed? Thanks.
> 
> Node node = nodeBuilder().clusterName("myelasticsearch").node();  
> Client client = node.client();  
> QueryBuilder qb = QueryBuilders  
> .boolQuery()  
> .should(termQuery("kba.body.cleansed","steve"))  
> .should(termQuery("kba.body.cleansed","ballmer"))  
> .should(termQuery("kba.body.cleansed","Gaylor"));  
> SearchResponse searchResponse = client.prepareSearch("test")  
> .setQuery(qb)  
> .execute()  
> .actionGet();  
> System.out.println("there are " + searchResponse.getHits().totalHits() +"  
> hits in this search");  
> SearchHits hits = searchResponse.getHits();  
> for (int i = 0; i \< searchResponse.getHits().totalHits(); i++)  
> {  
> System.out.println(hits.getAt(i).getSource().get("doc\_id"));  
> }
> 
> After I ran my code, it would output there are 2 hits in this search, but  
> I can not iterator the SearchHits, and the exception just like following:
> 
> _Exception in thread "main" there are 2 hits in this search_  
> _java.lang.ArrayIndexOutOfBoundsException: 0_
> 
> - at  
> org.elasticsearch.search.internal.InternalSearchHits.getAt(InternalSearchHits.java:144)
> - 
> 
> --  
> 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).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, 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).

--  
Wang Jingang(王金刚)  
Ph.D Candidate at  
Lab of High Volume Language Information Processing & Cloud Computing  
School of Computer Science  
Beijing Institute of Technology  
Beijing 100081  
P.R China

--  
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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 4, 2013, 11:54am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/4 "2013-03-04T11:54:33Z")

</div>

Can you share your full test code on [gist.github.com](http://gist.github.com)? I will give a look at it.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 4 mars 2013 à 12:46, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :

> Hi David,  
> Thanks so much for your reply. It really helps.  
> However, I have tried your means, it also could not iterate in the hits results.
> 
> On Mon, Mar 4, 2013 at 7:37 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > Have a look here: [https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267](https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267)
> > 
> > ```
> > for (SearchHit hit : searchResponse.getHits()) {
> > 
> > // in hit.getSource(), you will be able to get your doc
> > 
> > }
> > 
> > ```
> > 
> > Note that you can't do a loop on totalHits as Elasticsearch will return by default the first ten hits.  
> > So if you hit 1 000 000 docs, you can't iterate on 1 000 000 (and you probably don't want to do it).
> > 
> > Does it help?
> > 
> > --  
> > David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> > @dadoonet | @elasticsearchfr | @scrutmydocs
> > 
> > Le 4 mars 2013 à 12:27, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> > 
> > > Hi guys,
> > > 
> > > I am created indices in my data and began to make some queries on it. I could get the hits number, but I can not get the search results. following is my code in java.  
> > > Can anybody tell my what I have missed? Thanks.
> > > 
> > > Node node = nodeBuilder().clusterName("myelasticsearch").node();   
> > > Client client = node.client();  
> > > QueryBuilder qb = QueryBuilders  
> > > .boolQuery()  
> > > .should(termQuery("kba.body.cleansed","steve"))  
> > > .should(termQuery("kba.body.cleansed","ballmer"))  
> > > .should(termQuery("kba.body.cleansed","Gaylor"));  
> > > SearchResponse searchResponse = client.prepareSearch("test")  
> > > .setQuery(qb)  
> > > .execute()  
> > > .actionGet();  
> > > System.out.println("there are " + searchResponse.getHits().totalHits() +" hits in this search");  
> > > SearchHits hits = searchResponse.getHits();  
> > > for (int i = 0; i \< searchResponse.getHits().totalHits(); i++)  
> > > {  
> > > System.out.println(hits.getAt(i).getSource().get("doc\_id"));  
> > > }
> > > 
> > > After I ran my code, it would output there are 2 hits in this search, but I can not iterator the SearchHits, and the exception just like following:
> > > 
> > > Exception in thread "main" there are 2 hits in this search  
> > > java.lang.ArrayIndexOutOfBoundsException: 0  
> > > at org.elasticsearch.search.internal.InternalSearchHits.getAt(InternalSearchHits.java:144)
> > > 
> > > --  
> > > 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).
> > 
> > --  
> > You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US).  
> > To unsubscribe from this group and all its topics, 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).
> 
> --  
> Wang Jingang(王金刚)  
> Ph.D Candidate at  
> Lab of High Volume Language Information Processing & Cloud Computing  
> School of Computer Science  
> Beijing Institute of Technology  
> Beijing 100081  
> P.R China
> 
> --  
> 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).

--  
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:** ![Jingang\_Wang](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jingang\_Wang](https://discuss.elastic.co/u/Jingang_Wang)\
**Post date:** [March 4, 2013, 11:58am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/5 "2013-03-04T11:58:30Z")

</div>

It's so nice of you.  
I have create it on git, please check here:

> <https://gist.github.com/bitwjg/5081814>

On Mon, Mar 4, 2013 at 7:54 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Can you share your full test code on [gist.github.com](http://gist.github.com)? I will give a look  
> at it.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 4 mars 2013 à 12:46, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> 
> Hi David,  
> Thanks so much for your reply. It really helps.  
> However, I have tried your means, it also could not iterate in the hits  
> results.
> 
> On Mon, Mar 4, 2013 at 7:37 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > Have a look here:  
> > [https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267](https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267)
> > 
> > ```
> > for (SearchHit hit : searchResponse.getHits()) {
> > // in hit.getSource(), you will be able to get your doc
> > }
> > 
> > ```
> > 
> > Note that you can't do a loop on totalHits as Elasticsearch will return  
> > by default the first ten hits.  
> > So if you hit 1 000 000 docs, you can't iterate on 1 000 000 (and you  
> > probably don't want to do it).
> > 
> > Does it help?
> > 
> > --  
> > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> > | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > 
> > Le 4 mars 2013 à 12:27, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> > 
> > Hi guys,
> > 
> > I am created indices in my data and began to make some queries on it. I  
> > could get the hits number, but I can not get the search results. following  
> > is my code in java.  
> > Can anybody tell my what I have missed? Thanks.
> > 
> > Node node = nodeBuilder().clusterName("myelasticsearch").node();  
> > Client client = node.client();  
> > QueryBuilder qb = QueryBuilders  
> > .boolQuery()  
> > .should(termQuery("kba.body.cleansed","steve"))  
> > .should(termQuery("kba.body.cleansed","ballmer"))  
> > .should(termQuery("kba.body.cleansed","Gaylor"));  
> > SearchResponse searchResponse = client.prepareSearch("test")  
> > .setQuery(qb)  
> > .execute()  
> > .actionGet();  
> > System.out.println("there are " + searchResponse.getHits().totalHits() +"  
> > hits in this search");  
> > SearchHits hits = searchResponse.getHits();  
> > for (int i = 0; i \< searchResponse.getHits().totalHits(); i++)  
> > {  
> > System.out.println(hits.getAt(i).getSource().get("doc\_id"));  
> > }
> > 
> > After I ran my code, it would output there are 2 hits in this search, but  
> > I can not iterator the SearchHits, and the exception just like following:
> > 
> > _Exception in thread "main" there are 2 hits in this search_  
> > _java.lang.ArrayIndexOutOfBoundsException: 0_
> > 
> > - at  
> > org.elasticsearch.search.internal.InternalSearchHits.getAt(InternalSearchHits.java:144)
> > - 
> > 
> > --  
> > 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).
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US)  
> > .  
> > To unsubscribe from this group and all its topics, 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).
> 
> --  
> Wang Jingang(王金刚)  
> Ph.D Candidate at  
> Lab of High Volume Language Information Processing & Cloud Computing  
> School of Computer Science  
> Beijing Institute of Technology  
> Beijing 100081  
> P.R China
> 
> --  
> 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).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, 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).

--  
Wang Jingang(王金刚)  
Ph.D Candidate at  
Lab of High Volume Language Information Processing & Cloud Computing  
School of Computer Science  
Beijing Institute of Technology  
Beijing 100081  
P.R China

--  
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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 4, 2013, 12:23pm UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/6 "2013-03-04T12:23:31Z")

</div>

How did you index your documents?  
Do you have already a running ES node?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 4 mars 2013 à 12:58, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :

It's so nice of you.  
I have create it on git, please check here: [searchTest · GitHub](https://gist.github.com/bitwjg/5081814)

On Mon, Mar 4, 2013 at 7:54 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Can you share your full test code on [gist.github.com](http://gist.github.com)? I will give a look at it.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 4 mars 2013 à 12:46, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> 
> > Hi David,  
> > Thanks so much for your reply. It really helps.  
> > However, I have tried your means, it also could not iterate in the hits results.
> > 
> > On Mon, Mar 4, 2013 at 7:37 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> > 
> > > Have a look here: [https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267](https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267)
> > > 
> > > ```
> > > for (SearchHit hit : searchResponse.getHits()) {
> > > 
> > > // in hit.getSource(), you will be able to get your doc
> > > 
> > > }
> > > 
> > > ```
> > > 
> > > Note that you can't do a loop on totalHits as Elasticsearch will return by default the first ten hits.  
> > > So if you hit 1 000 000 docs, you can't iterate on 1 000 000 (and you probably don't want to do it).
> > > 
> > > Does it help?
> > > 
> > > --  
> > > David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> > > @dadoonet | @elasticsearchfr | @scrutmydocs
> > > 
> > > Le 4 mars 2013 à 12:27, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> > > 
> > > > Hi guys,
> > > > 
> > > > I am created indices in my data and began to make some queries on it. I could get the hits number, but I can not get the search results. following is my code in java.  
> > > > Can anybody tell my what I have missed? Thanks.
> > > > 
> > > > Node node = nodeBuilder().clusterName("myelasticsearch").node();   
> > > > Client client = node.client();  
> > > > QueryBuilder qb = QueryBuilders  
> > > > .boolQuery()  
> > > > .should(termQuery("kba.body.cleansed","steve"))  
> > > > .should(termQuery("kba.body.cleansed","ballmer"))  
> > > > .should(termQuery("kba.body.cleansed","Gaylor"));  
> > > > SearchResponse searchResponse = client.prepareSearch("test")  
> > > > .setQuery(qb)  
> > > > .execute()  
> > > > .actionGet();  
> > > > System.out.println("there are " + searchResponse.getHits().totalHits() +" hits in this search");  
> > > > SearchHits hits = searchResponse.getHits();  
> > > > for (int i = 0; i \< searchResponse.getHits().totalHits(); i++)  
> > > > {  
> > > > System.out.println(hits.getAt(i).getSource().get("doc\_id"));  
> > > > }
> > > > 
> > > > After I ran my code, it would output there are 2 hits in this search, but I can not iterator the SearchHits, and the exception just like following:
> > > > 
> > > > Exception in thread "main" there are 2 hits in this search  
> > > > java.lang.ArrayIndexOutOfBoundsException: 0  
> > > > at org.elasticsearch.search.internal.InternalSearchHits.getAt(InternalSearchHits.java:144)
> > > > 
> > > > --  
> > > > 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).
> > > 
> > > --  
> > > You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US).  
> > > To unsubscribe from this group and all its topics, 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).
> > 
> > --  
> > Wang Jingang(王金刚)  
> > Ph.D Candidate at  
> > Lab of High Volume Language Information Processing & Cloud Computing  
> > School of Computer Science  
> > Beijing Institute of Technology  
> > Beijing 100081  
> > P.R China
> > 
> > --  
> > 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).
> 
> --  
> You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US).  
> To unsubscribe from this group and all its topics, 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).

--  
Wang Jingang(王金刚)  
Ph.D Candidate at  
Lab of High Volume Language Information Processing & Cloud Computing  
School of Computer Science  
Beijing Institute of Technology  
Beijing 100081  
P.R China

--  
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).

--  
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:** ![Jingang\_Wang](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jingang\_Wang](https://discuss.elastic.co/u/Jingang_Wang)\
**Post date:** [March 4, 2013, 12:34pm UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/7 "2013-03-04T12:34:25Z")

</div>

Yes, I have a running ES node, and I could conduct search using  
Elasticsearch-Head-Master.  
While when I run the code, I just get the number of hits and can not  
iterate the hits to get details.  
The code snippet I created Index: [CreateIndex.java · GitHub](https://gist.github.com/bitwjg/5081967)  
I used bulkRequest to create the index.  
Thanks for your time.

On Mon, Mar 4, 2013 at 8:23 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> How did you index your documents?  
> Do you have already a running ES node?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 4 mars 2013 à 12:58, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> 
> It's so nice of you.  
> I have create it on git, please check here:  
> [searchTest · GitHub](https://gist.github.com/bitwjg/5081814)
> 
> On Mon, Mar 4, 2013 at 7:54 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > Can you share your full test code on [gist.github.com](http://gist.github.com)? I will give a look  
> > at it.
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 4 mars 2013 à 12:46, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> > 
> > Hi David,  
> > Thanks so much for your reply. It really helps.  
> > However, I have tried your means, it also could not iterate in the hits  
> > results.
> > 
> > On Mon, Mar 4, 2013 at 7:37 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> > 
> > > Have a look here:  
> > > [https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267](https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267)
> > > 
> > > ```
> > > for (SearchHit hit : searchResponse.getHits()) {
> > > 
> > > // in hit.getSource(), you will be able to get your doc
> > > 
> > > }
> > > 
> > > ```
> > > 
> > > Note that you can't do a loop on totalHits as Elasticsearch will return  
> > > by default the first ten hits.  
> > > So if you hit 1 000 000 docs, you can't iterate on 1 000 000 (and you  
> > > probably don't want to do it).
> > > 
> > > Does it help?
> > > 
> > > --  
> > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> > > | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > > 
> > > Le 4 mars 2013 à 12:27, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> > > 
> > > Hi guys,
> > > 
> > > I am created indices in my data and began to make some queries on it. I  
> > > could get the hits number, but I can not get the search results. following  
> > > is my code in java.  
> > > Can anybody tell my what I have missed? Thanks.
> > > 
> > > Node node = nodeBuilder().clusterName("myelasticsearch").node();  
> > > Client client = node.client();  
> > > QueryBuilder qb = QueryBuilders  
> > > .boolQuery()  
> > > .should(termQuery("kba.body.cleansed","steve"))  
> > > .should(termQuery("kba.body.cleansed","ballmer"))  
> > > .should(termQuery("kba.body.cleansed","Gaylor"));  
> > > SearchResponse searchResponse = client.prepareSearch("test")  
> > > .setQuery(qb)  
> > > .execute()  
> > > .actionGet();  
> > > System.out.println("there are " + searchResponse.getHits().totalHits()  
> > > +" hits in this search");  
> > > SearchHits hits = searchResponse.getHits();  
> > > for (int i = 0; i \< searchResponse.getHits().totalHits(); i++)  
> > > {  
> > > System.out.println(hits.getAt(i).getSource().get("doc\_id"));
> > > 
> > > }
> > > 
> > > After I ran my code, it would output there are 2 hits in this search,  
> > > but I can not iterator the SearchHits, and the exception just like  
> > > following:
> > > 
> > > _Exception in thread "main" there are 2 hits in this search_  
> > > _java.lang.ArrayIndexOutOfBoundsException: 0_
> > > 
> > > - at  
> > > org.elasticsearch.search.internal.InternalSearchHits.getAt(InternalSearchHits.java:144)
> > > - 
> > > 
> > > --  
> > > 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).
> > > 
> > > --  
> > > You received this message because you are subscribed to a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US)  
> > > .  
> > > To unsubscribe from this group and all its topics, 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).
> > 
> > --  
> > Wang Jingang(王金刚)  
> > Ph.D Candidate at  
> > Lab of High Volume Language Information Processing & Cloud Computing  
> > School of Computer Science  
> > Beijing Institute of Technology  
> > Beijing 100081  
> > P.R China
> > 
> > --  
> > 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).
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US)  
> > .  
> > To unsubscribe from this group and all its topics, 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).
> 
> --  
> Wang Jingang(王金刚)  
> Ph.D Candidate at  
> Lab of High Volume Language Information Processing & Cloud Computing  
> School of Computer Science  
> Beijing Institute of Technology  
> Beijing 100081  
> P.R China
> 
> --  
> 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).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, 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).

--  
Wang Jingang(王金刚)  
Ph.D Candidate at  
Lab of High Volume Language Information Processing & Cloud Computing  
School of Computer Science  
Beijing Institute of Technology  
Beijing 100081  
P.R China

--  
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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 4, 2013, 1:55pm UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/8 "2013-03-04T13:55:24Z")

</div>

I tried with a matchAll query on my indices and I can iterate over the 10 hits and get a field from each source.  
I also tried a boolQuery with 3 should term clauses and that was fine also.

I can't help more here without reproducing your _issue_.

What does a single document look like?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 4 mars 2013 à 13:34, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :

> Yes, I have a running ES node, and I could conduct search using Elasticsearch-Head-Master.  
> While when I run the code, I just get the number of hits and can not iterate the hits to get details.  
> The code snippet I created Index: [CreateIndex.java · GitHub](https://gist.github.com/bitwjg/5081967)  
> I used bulkRequest to create the index.  
> Thanks for your time.
> 
> On Mon, Mar 4, 2013 at 8:23 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
> How did you index your documents?  
> Do you have already a running ES node?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 4 mars 2013 à 12:58, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> 
> It's so nice of you.  
> I have create it on git, please check here: [searchTest · GitHub](https://gist.github.com/bitwjg/5081814)
> 
> On Mon, Mar 4, 2013 at 7:54 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
> Can you share your full test code on [gist.github.com](http://gist.github.com)? I will give a look at it.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 4 mars 2013 à 12:46, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> 
> > Hi David,  
> > Thanks so much for your reply. It really helps.  
> > However, I have tried your means, it also could not iterate in the hits results.
> > 
> > On Mon, Mar 4, 2013 at 7:37 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
> > Have a look here: [https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267](https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267)
> > 
> > ```
> > for (SearchHit hit : searchResponse.getHits()) {
> > 
> > // in hit.getSource(), you will be able to get your doc
> > 
> > }
> > 
> > ```
> > 
> > Note that you can't do a loop on totalHits as Elasticsearch will return by default the first ten hits.  
> > So if you hit 1 000 000 docs, you can't iterate on 1 000 000 (and you probably don't want to do it).
> > 
> > Does it help?
> > 
> > --  
> > David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> > @dadoonet | @elasticsearchfr | @scrutmydocs
> > 
> > Le 4 mars 2013 à 12:27, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> > 
> > > Hi guys,
> > > 
> > > I am created indices in my data and began to make some queries on it. I could get the hits number, but I can not get the search results. following is my code in java.  
> > > Can anybody tell my what I have missed? Thanks.
> > > 
> > > Node node = nodeBuilder().clusterName("myelasticsearch").node();   
> > > Client client = node.client();  
> > > QueryBuilder qb = QueryBuilders  
> > > .boolQuery()  
> > > .should(termQuery("kba.body.cleansed","steve"))  
> > > .should(termQuery("kba.body.cleansed","ballmer"))  
> > > .should(termQuery("kba.body.cleansed","Gaylor"));  
> > > SearchResponse searchResponse = client.prepareSearch("test")  
> > > .setQuery(qb)  
> > > .execute()  
> > > .actionGet();  
> > > System.out.println("there are " + searchResponse.getHits().totalHits() +" hits in this search");  
> > > SearchHits hits = searchResponse.getHits();  
> > > for (int i = 0; i \< searchResponse.getHits().totalHits(); i++)  
> > > {  
> > > System.out.println(hits.getAt(i).getSource().get("doc\_id"));  
> > > }
> > > 
> > > After I ran my code, it would output there are 2 hits in this search, but I can not iterator the SearchHits, and the exception just like following:
> > > 
> > > Exception in thread "main" there are 2 hits in this search  
> > > java.lang.ArrayIndexOutOfBoundsException: 0  
> > > at org.elasticsearch.search.internal.InternalSearchHits.getAt(InternalSearchHits.java:144)
> > > 
> > > --  
> > > 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).
> > 
> > --  
> > You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US).  
> > To unsubscribe from this group and all its topics, 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).
> > 
> > --  
> > Wang Jingang(王金刚)  
> > Ph.D Candidate at  
> > Lab of High Volume Language Information Processing & Cloud Computing  
> > School of Computer Science  
> > Beijing Institute of Technology  
> > Beijing 100081  
> > P.R China
> > 
> > --  
> > 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).
> 
> --  
> You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US).  
> To unsubscribe from this group and all its topics, 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).
> 
> --  
> Wang Jingang(王金刚)  
> Ph.D Candidate at  
> Lab of High Volume Language Information Processing & Cloud Computing  
> School of Computer Science  
> Beijing Institute of Technology  
> Beijing 100081  
> P.R China
> 
> --  
> 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).
> 
> --  
> You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US).  
> To unsubscribe from this group and all its topics, 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).
> 
> --  
> Wang Jingang(王金刚)  
> Ph.D Candidate at  
> Lab of High Volume Language Information Processing & Cloud Computing  
> School of Computer Science  
> Beijing Institute of Technology  
> Beijing 100081  
> P.R China
> 
> --  
> 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).

--  
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:** ![Jingang\_Wang](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jingang\_Wang](https://discuss.elastic.co/u/Jingang_Wang)\
**Post date:** [March 4, 2013, 1:58pm UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/9 "2013-03-04T13:58:59Z")

</div>

Hi David,

I found that the number of hits is 2 via  
searchResponse.getHits().totalHits() method.  
However, when I used the hit array, the array size is 0. It's so weird.

SearchHits hits = searchResponse.hits();  
System.out.println(hits.getTotalHits()); //output is 2  
SearchHit hit\_array = hits.getHits();  
System.out.println(hit\_array.length); // output is 0

On Mon, Mar 4, 2013 at 8:34 PM, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) wrote:

> Yes, I have a running ES node, and I could conduct search using  
> Elasticsearch-Head-Master.  
> While when I run the code, I just get the number of hits and can not  
> iterate the hits to get details.  
> The code snippet I created Index: [CreateIndex.java · GitHub](https://gist.github.com/bitwjg/5081967)  
> I used bulkRequest to create the index.  
> Thanks for your time.
> 
> On Mon, Mar 4, 2013 at 8:23 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > How did you index your documents?  
> > Do you have already a running ES node?
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 4 mars 2013 à 12:58, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> > 
> > It's so nice of you.  
> > I have create it on git, please check here:  
> > [searchTest · GitHub](https://gist.github.com/bitwjg/5081814)
> > 
> > On Mon, Mar 4, 2013 at 7:54 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> > 
> > > Can you share your full test code on [gist.github.com](http://gist.github.com)? I will give a  
> > > look at it.
> > > 
> > > --  
> > > David 😉  
> > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > 
> > > Le 4 mars 2013 à 12:46, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> > > 
> > > Hi David,  
> > > Thanks so much for your reply. It really helps.  
> > > However, I have tried your means, it also could not iterate in the hits  
> > > results.
> > > 
> > > On Mon, Mar 4, 2013 at 7:37 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> > > 
> > > > Have a look here:  
> > > > [https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267](https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267)
> > > > 
> > > > ```
> > > > for (SearchHit hit : searchResponse.getHits()) {
> > > > 
> > > > // in hit.getSource(), you will be able to get your doc
> > > > 
> > > > }
> > > > 
> > > > ```
> > > > 
> > > > Note that you can't do a loop on totalHits as Elasticsearch will return  
> > > > by default the first ten hits.  
> > > > So if you hit 1 000 000 docs, you can't iterate on 1 000 000 (and you  
> > > > probably don't want to do it).
> > > > 
> > > > Does it help?
> > > > 
> > > > --  
> > > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> > > > | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > > > 
> > > > Le 4 mars 2013 à 12:27, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> > > > 
> > > > Hi guys,
> > > > 
> > > > I am created indices in my data and began to make some queries on it. I  
> > > > could get the hits number, but I can not get the search results. following  
> > > > is my code in java.  
> > > > Can anybody tell my what I have missed? Thanks.
> > > > 
> > > > Node node = nodeBuilder().clusterName("myelasticsearch").node();  
> > > > Client client = node.client();  
> > > > QueryBuilder qb = QueryBuilders  
> > > > .boolQuery()  
> > > > .should(termQuery("kba.body.cleansed","steve"))  
> > > > .should(termQuery("kba.body.cleansed","ballmer"))  
> > > > .should(termQuery("kba.body.cleansed","Gaylor"));  
> > > > SearchResponse searchResponse = client.prepareSearch("test")  
> > > > .setQuery(qb)  
> > > > .execute()  
> > > > .actionGet();  
> > > > System.out.println("there are " +  
> > > > searchResponse.getHits().totalHits() +" hits in this search");  
> > > > SearchHits hits = searchResponse.getHits();  
> > > > for (int i = 0; i \< searchResponse.getHits().totalHits(); i++)  
> > > > {
> > > > 
> > > > System.out.println(hits.getAt(i).getSource().get("doc\_id"));  
> > > > }
> > > > 
> > > > After I ran my code, it would output there are 2 hits in this search,  
> > > > but I can not iterator the SearchHits, and the exception just like  
> > > > following:
> > > > 
> > > > _Exception in thread "main" there are 2 hits in this search_  
> > > > _java.lang.ArrayIndexOutOfBoundsException: 0_
> > > > 
> > > > - at  
> > > > org.elasticsearch.search.internal.InternalSearchHits.getAt(InternalSearchHits.java:144)
> > > > - 
> > > > 
> > > > --  
> > > > 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).
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to a topic in the  
> > > > Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this topic, visit  
> > > > [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US)  
> > > > .  
> > > > To unsubscribe from this group and all its topics, 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).
> > > 
> > > --  
> > > Wang Jingang(王金刚)  
> > > Ph.D Candidate at  
> > > Lab of High Volume Language Information Processing & Cloud Computing  
> > > School of Computer Science  
> > > Beijing Institute of Technology  
> > > Beijing 100081  
> > > P.R China
> > > 
> > > --  
> > > 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).
> > > 
> > > --  
> > > You received this message because you are subscribed to a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US)  
> > > .  
> > > To unsubscribe from this group and all its topics, 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).
> > 
> > --  
> > Wang Jingang(王金刚)  
> > Ph.D Candidate at  
> > Lab of High Volume Language Information Processing & Cloud Computing  
> > School of Computer Science  
> > Beijing Institute of Technology  
> > Beijing 100081  
> > P.R China
> > 
> > --  
> > 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).
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US)  
> > .  
> > To unsubscribe from this group and all its topics, 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).
> 
> --  
> Wang Jingang(王金刚)  
> Ph.D Candidate at  
> Lab of High Volume Language Information Processing & Cloud Computing  
> School of Computer Science  
> Beijing Institute of Technology  
> Beijing 100081  
> P.R China

--  
Wang Jingang(王金刚)  
Ph.D Candidate at  
Lab of High Volume Language Information Processing & Cloud Computing  
School of Computer Science  
Beijing Institute of Technology  
Beijing 100081  
P.R China

--  
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:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [March 4, 2013, 1:59pm UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/10 "2013-03-04T13:59:54Z")

</div>

Just a side note, it is not clear how you did combine index and search.  
If you have added the search code right immediately after the index  
code, it may not work because you also have to issue a refresh request  
to allow the index for reading the just indexed documents.

Jörg

Am 04.03.2013 13:34, schrieb Jingang Wang:

> Yes, I have a running ES node, and I could conduct search using  
> Elasticsearch-Head-Master.  
> While when I run the code, I just get the number of hits and can not  
> iterate the hits to get details.  
> The code snippet I created Index: [CreateIndex.java · GitHub](https://gist.github.com/bitwjg/5081967)  
> I used bulkRequest to create the index.

--  
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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 4, 2013, 2:03pm UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/11 "2013-03-04T14:03:20Z")

</div>

Hi Jörg,

I suspected that also but he said that he gets its documents from another node.  
He added also that he can run search using head plugin.

So I think that documents already exist there.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 4 mars 2013 à 14:58, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :

> Hi David,
> 
> I found that the number of hits is 2 via searchResponse.getHits().totalHits() method.  
> However, when I used the hit array, the array size is 0. It's so weird.
> 
> SearchHits hits = searchResponse.hits();  
> System.out.println(hits.getTotalHits()); //output is 2  
> SearchHit hit\_array = hits.getHits();  
> System.out.println(hit\_array.length); // output is 0
> 
> On Mon, Mar 4, 2013 at 8:34 PM, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) wrote:  
> Yes, I have a running ES node, and I could conduct search using Elasticsearch-Head-Master.  
> While when I run the code, I just get the number of hits and can not iterate the hits to get details.  
> The code snippet I created Index: [CreateIndex.java · GitHub](https://gist.github.com/bitwjg/5081967)  
> I used bulkRequest to create the index.  
> Thanks for your time.
> 
> On Mon, Mar 4, 2013 at 8:23 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
> How did you index your documents?  
> Do you have already a running ES node?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 4 mars 2013 à 12:58, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> 
> It's so nice of you.  
> I have create it on git, please check here: [searchTest · GitHub](https://gist.github.com/bitwjg/5081814)
> 
> On Mon, Mar 4, 2013 at 7:54 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
> Can you share your full test code on [gist.github.com](http://gist.github.com)? I will give a look at it.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 4 mars 2013 à 12:46, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> 
> > Hi David,  
> > Thanks so much for your reply. It really helps.  
> > However, I have tried your means, it also could not iterate in the hits results.
> > 
> > On Mon, Mar 4, 2013 at 7:37 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
> > Have a look here: [https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267](https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267)
> > 
> > ```
> > for (SearchHit hit : searchResponse.getHits()) {
> > 
> > // in hit.getSource(), you will be able to get your doc
> > 
> > }
> > 
> > ```
> > 
> > Note that you can't do a loop on totalHits as Elasticsearch will return by default the first ten hits.  
> > So if you hit 1 000 000 docs, you can't iterate on 1 000 000 (and you probably don't want to do it).
> > 
> > Does it help?
> > 
> > --  
> > David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> > @dadoonet | @elasticsearchfr | @scrutmydocs
> > 
> > Le 4 mars 2013 à 12:27, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :
> > 
> > > Hi guys,
> > > 
> > > I am created indices in my data and began to make some queries on it. I could get the hits number, but I can not get the search results. following is my code in java.  
> > > Can anybody tell my what I have missed? Thanks.
> > > 
> > > Node node = nodeBuilder().clusterName("myelasticsearch").node();   
> > > Client client = node.client();  
> > > QueryBuilder qb = QueryBuilders  
> > > .boolQuery()  
> > > .should(termQuery("kba.body.cleansed","steve"))  
> > > .should(termQuery("kba.body.cleansed","ballmer"))  
> > > .should(termQuery("kba.body.cleansed","Gaylor"));  
> > > SearchResponse searchResponse = client.prepareSearch("test")  
> > > .setQuery(qb)  
> > > .execute()  
> > > .actionGet();  
> > > System.out.println("there are " + searchResponse.getHits().totalHits() +" hits in this search");  
> > > SearchHits hits = searchResponse.getHits();  
> > > for (int i = 0; i \< searchResponse.getHits().totalHits(); i++)  
> > > {  
> > > System.out.println(hits.getAt(i).getSource().get("doc\_id"));  
> > > }
> > > 
> > > After I ran my code, it would output there are 2 hits in this search, but I can not iterator the SearchHits, and the exception just like following:
> > > 
> > > Exception in thread "main" there are 2 hits in this search  
> > > java.lang.ArrayIndexOutOfBoundsException: 0  
> > > at org.elasticsearch.search.internal.InternalSearchHits.getAt(InternalSearchHits.java:144)
> > > 
> > > --  
> > > 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).
> > 
> > --  
> > You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US).  
> > To unsubscribe from this group and all its topics, 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).
> > 
> > --  
> > Wang Jingang(王金刚)  
> > Ph.D Candidate at  
> > Lab of High Volume Language Information Processing & Cloud Computing  
> > School of Computer Science  
> > Beijing Institute of Technology  
> > Beijing 100081  
> > P.R China
> > 
> > --  
> > 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).
> 
> --  
> You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US).  
> To unsubscribe from this group and all its topics, 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).
> 
> --  
> Wang Jingang(王金刚)  
> Ph.D Candidate at  
> Lab of High Volume Language Information Processing & Cloud Computing  
> School of Computer Science  
> Beijing Institute of Technology  
> Beijing 100081  
> P.R China
> 
> --  
> 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).
> 
> --  
> You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US).  
> To unsubscribe from this group and all its topics, 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).
> 
> --  
> Wang Jingang(王金刚)  
> Ph.D Candidate at  
> Lab of High Volume Language Information Processing & Cloud Computing  
> School of Computer Science  
> Beijing Institute of Technology  
> Beijing 100081  
> P.R China
> 
> --  
> Wang Jingang(王金刚)  
> Ph.D Candidate at  
> Lab of High Volume Language Information Processing & Cloud Computing  
> School of Computer Science  
> Beijing Institute of Technology  
> Beijing 100081  
> P.R China
> 
> --  
> 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).

--  
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:** ![Jingang\_Wang](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jingang\_Wang](https://discuss.elastic.co/u/Jingang_Wang)\
**Post date:** [March 4, 2013, 2:04pm UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/12 "2013-03-04T14:04:09Z")

</div>

T  
​hanks for your kind reply，  
Jörg  
​。  
I conducted search after indices were built after a while and I have tested  
searching using es-head-master tool， which worked very well。

On Mon, Mar 4, 2013 at 9:59 PM, Jörg Prante [joergprante@gmail.com](mailto:joergprante@gmail.com) wrote:

> Just a side note, it is not clear how you did combine index and search. If  
> you have added the search code right immediately after the index code, it  
> may not work because you also have to issue a refresh request to allow the  
> index for reading the just indexed documents.
> 
> Jörg
> 
> Am 04.03.2013 13:34, schrieb Jingang Wang:
> 
> Yes, I have a running ES node, and I could conduct search using
> 
> > Elasticsearch-Head-Master.  
> > While when I run the code, I just get the number of hits and can not  
> > iterate the hits to get details.  
> > The code snippet I created Index: [https://gist.github.com/](https://gist.github.com/)\*\*  
> > bitwjg/5081967 [https://gist.github.com/bitwjg/5081967](https://gist.github.com/bitwjg/5081967)  
> > I used bulkRequest to create the index.
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/](https://groups.google.com/d/)\*\*  
> topic/elasticsearch/\*\*l63cThzXKvI/unsubscribe?hl=en-\*\*US[https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, send an email to  
> elasticsearch+unsubscribe@\*\*[googlegroups.com](http://googlegroups.com)[elasticsearch%2Bunsubscribe@googlegroups.com](mailto:elasticsearch%2Bunsubscribe@googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> .

--  
Wang Jingang(王金刚)  
Ph.D Candidate at  
Lab of High Volume Language Information Processing & Cloud Computing  
School of Computer Science  
Beijing Institute of Technology  
Beijing 100081  
P.R China

--  
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:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [March 4, 2013, 2:05pm UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/13 "2013-03-04T14:05:04Z")

</div>

Forget to mention, it is not easy to follow the setup without knowing  
the index settings. Is it possible you have disabled fields like \_all or  
\_source?

Jörg

Am 04.03.2013 14:59, schrieb Jörg Prante:

> Just a side note, it is not clear how you did combine index and  
> search. If you have added the search code right immediately after the  
> index code, it may not work because you also have to issue a refresh  
> request to allow the index for reading the just indexed documents.
> 
> Jörg
> 
> Am 04.03.2013 13:34, schrieb Jingang Wang:
> 
> > Yes, I have a running ES node, and I could conduct search using  
> > Elasticsearch-Head-Master.  
> > While when I run the code, I just get the number of hits and can not  
> > iterate the hits to get details.  
> > The code snippet I created Index: [CreateIndex.java · GitHub](https://gist.github.com/bitwjg/5081967)  
> > I used bulkRequest to create the index.

--  
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:** ![Jingang\_Wang](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jingang\_Wang](https://discuss.elastic.co/u/Jingang_Wang)\
**Post date:** [March 4, 2013, 2:17pm UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/14 "2013-03-04T14:17:12Z")

</div>

Hi Jörg，  
FYI, here is my code creating index. [CreateIndex.java · GitHub](https://gist.github.com/bitwjg/5081967)  
I construct the index with Json string as following.

XContentBuilder xb = jsonBuilder()  
.startObject()  
.field("stream\_id", stream\_id).field("type",  
"string").field("store", "yes").field("index","no")  
.field("source", source).field("type",  
"string").field("store","yes").field("index", "no")  
.field("doc\_id", doc\_id).field("type",  
"string").field("store","yes").field("index","no")  
.startObject("stream\_time")  
.field("epoch\_ticks", epoch\_ticks).field("type",  
"double").field("index", "no").field("store","no")  
.field("zulu\_timestamp", zulu\_timestamp).field("type",  
"string").field("index","no").field("store","yes")  
.endObject()  
.startObject("body")  
.field("cleansed",  
body\_clean\_text).field("type","string").field("index",  
"yes").field("store","yes")  
.field("ner",  
body\_ner\_text).field("type","string").field("index","no").field("store",  
"yes")  
.endObject()  
.endObject();

On Mon, Mar 4, 2013 at 10:05 PM, Jörg Prante [joergprante@gmail.com](mailto:joergprante@gmail.com) wrote:

> Forget to mention, it is not easy to follow the setup without knowing the  
> index settings. Is it possible you have disabled fields like \_all or  
> \_source?
> 
> Jörg
> 
> Am 04.03.2013 14:59, schrieb Jörg Prante:
> 
> Just a side note, it is not clear how you did combine index and search.
> 
> > If you have added the search code right immediately after the index code,  
> > it may not work because you also have to issue a refresh request to allow  
> > the index for reading the just indexed documents.
> > 
> > Jörg
> > 
> > Am 04.03.2013 13:34, schrieb Jingang Wang:
> > 
> > > Yes, I have a running ES node, and I could conduct search using  
> > > Elasticsearch-Head-Master.  
> > > While when I run the code, I just get the number of hits and can not  
> > > iterate the hits to get details.  
> > > The code snippet I created Index: [https://gist.github.com/](https://gist.github.com/)\*\*  
> > > bitwjg/5081967 [https://gist.github.com/bitwjg/5081967](https://gist.github.com/bitwjg/5081967)  
> > > I used bulkRequest to create the index.
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/](https://groups.google.com/d/)\*\*  
> topic/elasticsearch/\*\*l63cThzXKvI/unsubscribe?hl=en-\*\*US[https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, send an email to  
> elasticsearch+unsubscribe@\*\*[googlegroups.com](http://googlegroups.com)[elasticsearch%2Bunsubscribe@googlegroups.com](mailto:elasticsearch%2Bunsubscribe@googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> .

--  
Wang Jingang(王金刚)  
Ph.D Candidate at  
Lab of High Volume Language Information Processing & Cloud Computing  
School of Computer Science  
Beijing Institute of Technology  
Beijing 100081  
P.R China

--  
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:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [March 4, 2013, 3:01pm UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/15 "2013-03-04T15:01:44Z")

</div>

I understand you just create documents, without using existing index  
settings or mappings.

You have several misconceptions in your code:

- you can not define field mappings in XContentBuilder. You must use the  
mapping API. XContentBuilder is just for content, as the name states.

- you use termQuery, in fact you are not looking for terms, but for  
analyzed text. For this, use matchQuery instead.

- you use long field names, with path like notation, also with index  
type included which will not work. You should use short field names  
("cleansed") in queries.

- you do not start the node with start() and do not stop with stop() - I  
don't know if you want to join a running cluster, or if you want a  
standalone test cluster =

To recreate the issue, I have rewritten your code, also removed your  
private class references, and made it runnable as a TestNG test.

The code is here: [Java code example for bitwijg · GitHub](https://gist.github.com/jprante/5082756)

The output I get works as expected.

[2013-03-04 15:50:47,602][INFO][test] ==\> Test  
Starting [BitwjgTest#test]  
[2013-03-04 15:50:47,775][INFO][node] [Scrambler]  
{0.90.0.Beta2-SNAPSHOT}[2312]: initializing ...  
[2013-03-04 15:50:47,782][INFO][plugins] [Scrambler]  
loaded , sites   
[2013-03-04 15:50:49,310][INFO][node] [Scrambler]  
{0.90.0.Beta2-SNAPSHOT}[2312]: initialized  
[2013-03-04 15:50:49,310][INFO][node] [Scrambler]  
{0.90.0.Beta2-SNAPSHOT}[2312]: starting ...  
[2013-03-04 15:50:49,408][INFO][transport] [Scrambler]  
bound\_address {inet[/0:0:0:0:0:0:0:0:9300]}, publish\_address  
{inet[/10.1.1.90:9300]}  
[2013-03-04 15:50:52,431][INFO][cluster.service] [Scrambler]  
new\_master [Scrambler][ezrhl6CsSEC7fZfwcAG7gw][inet[/10.1.1.90:9300]],  
reason: zen-disco-join (elected\_as\_master)  
[2013-03-04 15:50:52,455][INFO][discovery] [Scrambler]  
MSRA-KM/ezrhl6CsSEC7fZfwcAG7gw  
[2013-03-04 15:50:52,469][INFO][http] [Scrambler]  
bound\_address {inet[/0:0:0:0:0:0:0:0:9200]}, publish\_address  
{inet[/10.1.1.90:9200]}  
[2013-03-04 15:50:52,469][INFO][node] [Scrambler]  
{0.90.0.Beta2-SNAPSHOT}[2312]: started  
[2013-03-04 15:50:52,512][INFO][gateway] [Scrambler]  
recovered [0] indices into cluster\_state  
[2013-03-04 15:50:52,759][INFO][cluster.metadata] [Scrambler]  
[test] creating index, cause [api], shards [5]/[1], mappings   
[2013-03-04 15:50:53,150][INFO][cluster.metadata] [Scrambler]  
[test] update\_mapping [kba] (dynamic)  
[2013-03-04 15:50:53,301][INFO][test] there are 2  
hits in this search  
[2013-03-04 15:50:53,302][INFO][test] hit docid = 0  
[2013-03-04 15:50:53,302][INFO][test] hit docid = 1  
[2013-03-04 15:50:53,303][INFO][node] [Scrambler]  
{0.90.0.Beta2-SNAPSHOT}[2312]: stopping ...  
[2013-03-04 15:50:53,305][INFO][cluster.metadata] [Scrambler]  
[test] deleting index  
[2013-03-04 15:50:53,365][INFO][node] [Scrambler]  
{0.90.0.Beta2-SNAPSHOT}[2312]: stopped  
[2013-03-04 15:50:53,366][INFO][test] ==\> Test  
Success [BitwjgTest#test]

I hope the code is useful for your purposes (it should also work under  
0.19/0.20)

Best regards,

Jörg

Am 04.03.13 15:17, schrieb Jingang Wang:

> Hi Jörg，  
> FYI, here is my code creating index.  
> [CreateIndex.java · GitHub](https://gist.github.com/bitwjg/5081967)  
> I construct the index with Json string as following.

--  
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:** ![Jingang\_Wang](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jingang\_Wang](https://discuss.elastic.co/u/Jingang_Wang)\
**Post date:** [March 5, 2013, 8:14am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/16 "2013-03-05T08:14:33Z")

</div>

Thanks, Jörg.  
I appreciate your help so much. I have tested your code, the issue still  
exist. I attach the error information as following.  
FYI, I run ES 0.90.0 beta1 in Windows 8. Would it affect the program?

Exception in thread "main"  
org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to  
execute phase [query], total failure; shardFailures {[_na_][mytest][0]: No  
active shards}{[_na_][mytest][1]: No active shards}{[_na_][mytest][2]: No  
active shards}{[_na_][mytest][3]: No active shards}{[_na_][mytest][4]: No  
active shards}  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:260)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.start(TransportSearchTypeAction.java:145)  
at  
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction.doExecute(TransportSearchQueryThenFetchAction.java:58)  
at  
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction.doExecute(TransportSearchQueryThenFetchAction.java:48)  
at  
org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:61)  
at  
org.elasticsearch.action.search.TransportSearchAction.doExecute(TransportSearchAction.java:109)  
at  
org.elasticsearch.action.search.TransportSearchAction.doExecute(TransportSearchAction.java:44)  
at  
org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:61)  
at org.elasticsearch.client.node.NodeClient.execute(NodeClient.java:92)  
at  
org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:210)  
at  
org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:816)  
at  
org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:62)  
at  
org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:57)  
at com.msra.km.jingang.BitwjgTest.main(BitwjgTest.java:72)

the gist link of my code: [bitwjgTest.java · GitHub](https://gist.github.com/bitwjg/5088703)

On Mon, Mar 4, 2013 at 11:01 PM, Jörg Prante [joergprante@gmail.com](mailto:joergprante@gmail.com) wrote:

> I understand you just create documents, without using existing index  
> settings or mappings.
> 
> You have several misconceptions in your code:
> 
> - you can not define field mappings in XContentBuilder. You must use the  
> mapping API. XContentBuilder is just for content, as the name states.
> 
> - you use termQuery, in fact you are not looking for terms, but for  
> analyzed text. For this, use matchQuery instead.
> 
> - you use long field names, with path like notation, also with index type  
> included which will not work. You should use short field names ("cleansed")  
> in queries.
> 
> - you do not start the node with start() and do not stop with stop() - I  
> don't know if you want to join a running cluster, or if you want a  
> standalone test cluster =
> 
> To recreate the issue, I have rewritten your code, also removed your  
> private class references, and made it runnable as a TestNG test.
> 
> The code is here: [https://gist.github.com/\*\*jprante/5082756](https://gist.github.com/**jprante/5082756)[https://gist.github.com/jprante/5082756](https://gist.github.com/jprante/5082756)
> 
> The output I get works as expected.
> 
> [2013-03-04 15:50:47,602][INFO][test] ==\> Test  
> Starting [BitwjgTest#test]  
> [2013-03-04 15:50:47,775][INFO][node] [Scrambler]  
> {0.90.0.Beta2-SNAPSHOT}[2312]: initializing ...  
> [2013-03-04 15:50:47,782][INFO][plugins] [Scrambler]  
> loaded , sites   
> [2013-03-04 15:50:49,310][INFO][node] [Scrambler]  
> {0.90.0.Beta2-SNAPSHOT}[2312]: initialized  
> [2013-03-04 15:50:49,310][INFO][node] [Scrambler]  
> {0.90.0.Beta2-SNAPSHOT}[2312]: starting ...  
> [2013-03-04 15:50:49,408][INFO][transport] [Scrambler]  
> bound\_address {inet[/0:0:0:0:0:0:0:0:9300]}, publish\_address {inet[/  
> 10.1.1.90:9300]}  
> [2013-03-04 15:50:52,431][INFO][cluster.service] [Scrambler]  
> new\_master [Scrambler][\*\*ezrhl6CsSEC7fZfwcAG7gw][inet[/\*\*10.1.1.90:9300]],  
> reason: zen-disco-join (elected\_as\_master)  
> [2013-03-04 15:50:52,455][INFO][discovery] [Scrambler]  
> MSRA-KM/ezrhl6CsSEC7fZfwcAG7gw  
> [2013-03-04 15:50:52,469][INFO][http] [Scrambler]  
> bound\_address {inet[/0:0:0:0:0:0:0:0:9200]}, publish\_address {inet[/  
> 10.1.1.90:9200]}  
> [2013-03-04 15:50:52,469][INFO][node] [Scrambler]  
> {0.90.0.Beta2-SNAPSHOT}[2312]: started  
> [2013-03-04 15:50:52,512][INFO][gateway] [Scrambler]  
> recovered [0] indices into cluster\_state  
> [2013-03-04 15:50:52,759][INFO][cluster.metadata] [Scrambler]  
> [test] creating index, cause [api], shards [5]/[1], mappings   
> [2013-03-04 15:50:53,150][INFO][cluster.metadata] [Scrambler]  
> [test] update\_mapping [kba] (dynamic)  
> [2013-03-04 15:50:53,301][INFO][test] there are 2  
> hits in this search  
> [2013-03-04 15:50:53,302][INFO][test] hit docid = 0  
> [2013-03-04 15:50:53,302][INFO][test] hit docid = 1  
> [2013-03-04 15:50:53,303][INFO][node] [Scrambler]  
> {0.90.0.Beta2-SNAPSHOT}[2312]: stopping ...  
> [2013-03-04 15:50:53,305][INFO][cluster.metadata] [Scrambler]  
> [test] deleting index  
> [2013-03-04 15:50:53,365][INFO][node] [Scrambler]  
> {0.90.0.Beta2-SNAPSHOT}[2312]: stopped  
> [2013-03-04 15:50:53,366][INFO][test] ==\> Test  
> Success [BitwjgTest#test]
> 
> I hope the code is useful for your purposes (it should also work under  
> 0.19/0.20)
> 
> Best regards,
> 
> Jörg
> 
> Am 04.03.13 15:17, schrieb Jingang Wang:
> 
> Hi Jörg，
> 
> > FYI, here is my code creating index. [https://gist.github.com/](https://gist.github.com/)\*\*  
> > bitwjg/5081967 [https://gist.github.com/bitwjg/5081967](https://gist.github.com/bitwjg/5081967)  
> > I construct the index with Json string as following.
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/](https://groups.google.com/d/)\*\*  
> topic/elasticsearch/\*\*l63cThzXKvI/unsubscribe?hl=en-\*\*US[https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, send an email to  
> elasticsearch+unsubscribe@\*\*[googlegroups.com](http://googlegroups.com)[elasticsearch%2Bunsubscribe@googlegroups.com](mailto:elasticsearch%2Bunsubscribe@googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> .

--  
Wang Jingang(王金刚)  
Ph.D Candidate at  
Lab of High Volume Language Information Processing & Cloud Computing  
School of Computer Science  
Beijing Institute of Technology  
Beijing 100081  
P.R China

--  
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:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [March 5, 2013, 9:47am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/17 "2013-03-05T09:47:52Z")

</div>

Sorry, my fault. I was sloppy in the index creation/deletion action.  
Please use

client.admin().indices().create(new  
CreateIndexRequest("mytest")).actionGet();

and

client.admin().indices().delete(new  
DeleteIndexRequest("mytest")).actionGet();

that is, with ".actionGet()"

Your code runs here successfully.

Jörg

Am 05.03.13 09:14, schrieb Jingang Wang:

> I appreciate your help so much. I have tested your code, the issue  
> still exist. I attach the error information as following.  
> FYI, I run ES 0.90.0 beta1 in Windows 8. Would it affect the program?

--  
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:** ![Jingang\_Wang](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jingang\_Wang](https://discuss.elastic.co/u/Jingang_Wang)\
**Post date:** [March 5, 2013, 9:53am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/18 "2013-03-05T09:53:20Z")

</div>

Thanks, but there occurs another exception. I think there should be some  
mistakes in my settings of ES?

Exception in thread "main"  
org.elasticsearch.transport.TransportSerializationException: Failed to  
deserialize exception response from stream  
at  
org.elasticsearch.transport.netty.MessageChannelHandler.handlerResponseError(MessageChannelHandler.java:171)  
at  
org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:125)  
at  
org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)  
at  
org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:560)  
at  
org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:787)  
at  
org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:296)  
at  
org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462)  
at  
org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443)  
at  
org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303)  
at  
org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)  
at  
org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:560)  
at  
org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:555)  
at  
org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:268)  
at  
org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:255)  
at  
org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)  
at  
org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:107)  
at  
org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:312)  
at  
org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:88)  
at  
org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)  
at  
org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)  
at  
org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)  
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)  
at java.lang.Thread.run(Unknown Source)  
Caused by: java.io.EOFException  
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)  
at java.io.ObjectInputStream.skipCustomData(Unknown Source)  
at java.io.ObjectInputStream.readSerialData(Unknown Source)  
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)  
at java.io.ObjectInputStream.readObject0(Unknown Source)  
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)  
at java.io.ObjectInputStream.readSerialData(Unknown Source)  
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)  
at java.io.ObjectInputStream.readObject0(Unknown Source)  
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)  
at java.io.ObjectInputStream.readSerialData(Unknown Source)  
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)  
at java.io.ObjectInputStream.readObject0(Unknown Source)  
at java.io.ObjectInputStream.readObject(Unknown Source)  
at  
org.elasticsearch.transport.netty.MessageChannelHandler.handlerResponseError(MessageChannelHandler.java:169)  
... 23 more

On Tue, Mar 5, 2013 at 5:47 PM, Jörg Prante [joergprante@gmail.com](mailto:joergprante@gmail.com) wrote:

> Sorry, my fault. I was sloppy in the index creation/deletion action.  
> Please use
> 
> client.admin().indices().**create(new CreateIndexRequest("mytest")).**  
> actionGet();
> 
> and
> 
> client.admin().indices().**delete(new DeleteIndexRequest("mytest")).**  
> actionGet();
> 
> that is, with ".actionGet()"
> 
> Your code runs here successfully.
> 
> Jörg
> 
> Am 05.03.13 09:14, schrieb Jingang Wang:
> 
> I appreciate your help so much. I have tested your code, the issue still
> 
> > exist. I attach the error information as following.  
> > FYI, I run ES 0.90.0 beta1 in Windows 8. Would it affect the program?
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/](https://groups.google.com/d/)\*\*  
> topic/elasticsearch/\*\*l63cThzXKvI/unsubscribe?hl=en-\*\*US[https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, send an email to  
> elasticsearch+unsubscribe@\*\*[googlegroups.com](http://googlegroups.com)[elasticsearch%2Bunsubscribe@googlegroups.com](mailto:elasticsearch%2Bunsubscribe@googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> .

--  
Wang Jingang(王金刚)  
Ph.D Candidate at  
Lab of High Volume Language Information Processing & Cloud Computing  
School of Computer Science  
Beijing Institute of Technology  
Beijing 100081  
P.R China

--  
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:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [March 5, 2013, 9:59am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/19 "2013-03-05T09:59:40Z")

</div>

This error is mainly caused by mixing different ES versions, are you  
sure you use only one ES version in the running nodes, on the local network?

Jörg

Am 05.03.13 10:53, schrieb Jingang Wang:

> Thanks, but there occurs another exception. I think there should be  
> some mistakes in my settings of ES?
> 
> Exception in thread "main"  
> org.elasticsearch.transport.TransportSerializationException: Failed to  
> deserialize exception response from stream  
> at  
> org.elasticsearch.transport.netty.MessageChannelHandler.handlerResponseError(MessageChannelHandler.java:171)

--  
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:** ![Jingang\_Wang](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jingang\_Wang](https://discuss.elastic.co/u/Jingang_Wang)\
**Post date:** [March 5, 2013, 10:05am UTC](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993/20 "2013-03-05T10:05:14Z")

</div>

I ever used ES 0.12 and now 0.90.  
In my current machine, I run ES 0.90, I have not replace the old ES  
version, but the ES instance in that machine is not initialized now.  
would it be affected?

On Tue, Mar 5, 2013 at 5:59 PM, Jörg Prante [joergprante@gmail.com](mailto:joergprante@gmail.com) wrote:

> This error is mainly caused by mixing different ES versions, are you sure  
> you use only one ES version in the running nodes, on the local network?
> 
> Jörg
> 
> Am 05.03.13 10:53, schrieb Jingang Wang:
> 
> Thanks, but there occurs another exception. I think there should be some
> 
> > mistakes in my settings of ES?
> > 
> > Exception in thread "main" org.elasticsearch.transport.\*\*  
> > TransportSerializationExceptio\*\*n: Failed to deserialize exception  
> > response from stream  
> > at org.elasticsearch.transport. **netty.MessageChannelHandler.**  
> > handlerResponseError(\*\*MessageChannelHandler.java:\*\*171)
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/](https://groups.google.com/d/)\*\*  
> topic/elasticsearch/\*\*l63cThzXKvI/unsubscribe?hl=en-\*\*US[https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/l63cThzXKvI/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, send an email to  
> elasticsearch+unsubscribe@\*\*[googlegroups.com](http://googlegroups.com)[elasticsearch%2Bunsubscribe@googlegroups.com](mailto:elasticsearch%2Bunsubscribe@googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> .

--  
Wang Jingang(王金刚)  
Ph.D Candidate at  
Lab of High Volume Language Information Processing & Cloud Computing  
School of Computer Science  
Beijing Institute of Technology  
Beijing 100081  
P.R China

--  
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).

[Next page](https://discuss.elastic.co/t/java-lang-arrayindexoutofboundsexception-0/10993.md?page=2)
