Thanks!
I can finally get some basic searches working from Java now. After looking
through some of that code I can run the simple example below. I'm sure
there are reasons I should bother with TransportClients, setting cluster
names (ours is not "elasticsearch"), etc.. But for just getting started
and making sure things work the code in the tutorial really helped. I wish
the guide at
Elasticsearch Platform — Find real-time answers at scale | Elastic had
actual code and not just snippets.
public static void main(String args){
Node node = NodeBuilder.nodeBuilder().node();
Assert.assertNotNull(node);
Assert.assertFalse(node.isClosed());
QueryBuilder qb = QueryBuilders.termQuery("tweet", "elastic");
SearchResponse sr = node.client().prepareSearch()
.setQuery(qb)
.execute()
.actionGet();
Assert.assertNotNull(sr);
Assert.assertNotNull(sr.getHits());
Assert.assertTrue(sr.getHits().getTotalHits() > 0);
java.util.Iterator hit_it = sr.getHits().iterator();
while(hit_it.hasNext()){
SearchHit hit = hit_it.next();
System.out.println(hit.getSourceAsString());
}
}
On Thursday, November 15, 2012 2:10:27 AM UTC-8, David Pilato wrote:
Not sure that my answer was posted. I'm reposting here.
Hi Ryan,
Have a look at this: GitHub - elasticsearchfr/hands-on: Hands On Lab
Answers are on answers branch:
GitHub - elasticsearchfr/hands-on at answers
Some slides (in french but you can understand code) are here:
Hands on lab Elasticsearch | PPT
I'm waiting for ES team to merge my Java tutorial:
https://github.com/elasticsearch/elasticsearch.github.com/pull/321
It will look like this:
https://github.com/dadoonet/elasticsearch.github.com/blob/9f6dae922247a81f1c72c77769d1dce3ad09dca5/tutorials/_posts/2012-11-07-using-java-api-basics.markdown
HTH
--
David
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
Le 15 nov. 2012 à 04:04, ryan compton <compto...@gmail.com <javascript:>>
a écrit :
I am completely new to Elastic Search. I have figured out enough that I
can retrieve jsons from our cluster with:
-bash-3.2$ curl -XGET http://10.10.1.7:9200/twitter-sept/_search -d
'{"query":{"bool":{"must":[{"term":{"tweet":"elastic"}}],"must_not":,"should":}},"from":0,"size":50,"sort":,"facets":{}}'
Since most of my code is in Java I figured things would be easier if I
used the Java API. I am completely stumped on how to do it. The guide
Elasticsearch Platform — Find real-time answers at scale | Elastic is
confusing. What are all those classes? Where are the javadocs? Is there a
simple example somewhere that explains how I can reproduce the above
command in Java? Do I need a TransportClient, a SearchSourceBuilder,
ImmutableSettings?
--
--