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.
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 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
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 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 a écrit :
It's so nice of you.
I have create it on git, please check here: searchTest · GitHub
On Mon, Mar 4, 2013 at 7:54 PM, David Pilato david@pilato.fr wrote:
Can you share your full test code on 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 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 wrote:
Have a look here: 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
@dadoonet | @elasticsearchfr | @scrutmydocs
Le 4 mars 2013 à 12:27, Jingang Wang 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.
For more options, visit 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.
To unsubscribe from this group and all its topics, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit 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.
For more options, visit 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.
To unsubscribe from this group and all its topics, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit 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.
For more options, visit 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.
To unsubscribe from this group and all its topics, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit 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.
For more options, visit https://groups.google.com/groups/opt_out.