# A simple example of how to use the Java API?

**URL:** <https://discuss.elastic.co/t/a-simple-example-of-how-to-use-the-java-api/9723>\
**Category:** Elasticsearch\
**Created:** [November 15, 2012, 3:04am UTC](https://discuss.elastic.co/t/a-simple-example-of-how-to-use-the-java-api/9723 "2012-11-15T03:04:41Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryan\_compton](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ryan_compton/32/2610_2.png) [@ryan\_compton](https://discuss.elastic.co/u/ryan_compton)\
**Post date:** [November 15, 2012, 3:04am UTC](https://discuss.elastic.co/t/a-simple-example-of-how-to-use-the-java-api/9723/1 "2012-11-15T03:04:41Z")

</div>

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](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  
[http://www.elasticsearch.org/guide/reference/java-api/search.html](http://www.elasticsearch.org/guide/reference/java-api/search.html) 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?

--

---

<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:** [November 15, 2012, 7:12am UTC](https://discuss.elastic.co/t/a-simple-example-of-how-to-use-the-java-api/9723/2 "2012-11-15T07:12:37Z")

</div>

Hi Ryan,

Have a look at this: [https://github.com/elasticsearchfr/hands-on](https://github.com/elasticsearchfr/hands-on)  
Answers are on answers branch: [https://github.com/elasticsearchfr/hands-on/tree/answers](https://github.com/elasticsearchfr/hands-on/tree/answers)

Some slides (in french but you can understand code) are here: [http://www.slideshare.net/mobile/dadoonet/hands-on-lab-elasticsearch](http://www.slideshare.net/mobile/dadoonet/hands-on-lab-elasticsearch)

I'm waiting for ES team to merge my Java tutorial: [https://github.com/elasticsearch/elasticsearch.github.com/pull/321](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](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 [compton.ryan@gmail.com](mailto:compton.ryan@gmail.com) 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](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 [http://www.elasticsearch.org/guide/reference/java-api/search.html](http://www.elasticsearch.org/guide/reference/java-api/search.html) 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?

--

---

<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:** [November 15, 2012, 10:10am UTC](https://discuss.elastic.co/t/a-simple-example-of-how-to-use-the-java-api/9723/3 "2012-11-15T10:10:27Z")

</div>

Not sure that my answer was posted. ☹ I'm reposting here.

Hi Ryan,

Have a look at this: [https://github.com/elasticsearchfr/hands-on](https://github.com/elasticsearchfr/hands-on)  
Answers are on answers branch: [https://github.com/elasticsearchfr/hands-on/tree/answers](https://github.com/elasticsearchfr/hands-on/tree/answers)

Some slides (in french but you can understand code) are here: [http://www.slideshare.net/mobile/dadoonet/hands-on-lab-elasticsearch](http://www.slideshare.net/mobile/dadoonet/hands-on-lab-elasticsearch)

I'm waiting for ES team to merge my Java tutorial: [https://github.com/elasticsearch/elasticsearch.github.com/pull/321](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](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 [compton.ryan@gmail.com](mailto:compton.ryan@gmail.com) 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](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 [http://www.elasticsearch.org/guide/reference/java-api/search.html](http://www.elasticsearch.org/guide/reference/java-api/search.html) 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?

--

---

<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:** [November 15, 2012, 1:28pm UTC](https://discuss.elastic.co/t/a-simple-example-of-how-to-use-the-java-api/9723/4 "2012-11-15T13:28:42Z")

</div>

Not sure that my answer was posted. ☹ I'm reposting here.  
Something goes wrong with the mailing list or do I have a problem on my side?

(Sorry for the disturb)

Hi Ryan,

Have a look at this: [https://github.com/elasticsearchfr/hands-on](https://github.com/elasticsearchfr/hands-on)  
Answers are on answers branch: [https://github.com/elasticsearchfr/hands-on/tree/answers](https://github.com/elasticsearchfr/hands-on/tree/answers)

Some slides (in french but you can understand code) are here: [http://www.slideshare.net/mobile/dadoonet/hands-on-lab-elasticsearch](http://www.slideshare.net/mobile/dadoonet/hands-on-lab-elasticsearch)

I'm waiting for ES team to merge my Java tutorial: [https://github.com/elasticsearch/elasticsearch.github.com/pull/321](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](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 [compton.ryan@gmail.com](mailto:compton.ryan@gmail.com) 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](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 [http://www.elasticsearch.org/guide/reference/java-api/search.html](http://www.elasticsearch.org/guide/reference/java-api/search.html) 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?

--

---

<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:** [November 15, 2012, 2:11pm UTC](https://discuss.elastic.co/t/a-simple-example-of-how-to-use-the-java-api/9723/5 "2012-11-15T14:11:02Z")

</div>

Hi Ryan,

Have a look at this: [https://github.com/elasticsearchfr/hands-on](https://github.com/elasticsearchfr/hands-on)  
Answers are on answers branch: [https://github.com/elasticsearchfr/hands-on/tree/answers](https://github.com/elasticsearchfr/hands-on/tree/answers)

Some slides (in french but you can understand code) are here: [http://www.slideshare.net/mobile/dadoonet/hands-on-lab-elasticsearch](http://www.slideshare.net/mobile/dadoonet/hands-on-lab-elasticsearch)

I'm waiting for ES team to merge my Java tutorial: [https://github.com/elasticsearch/elasticsearch.github.com/pull/321](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](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

--

---

<div class="post-metadata">

**Author:** ![ryan\_compton](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ryan_compton/32/2610_2.png) [@ryan\_compton](https://discuss.elastic.co/u/ryan_compton)\
**Post date:** [November 15, 2012, 8:54pm UTC](https://discuss.elastic.co/t/a-simple-example-of-how-to-use-the-java-api/9723/6 "2012-11-15T20:54:05Z")

</div>

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](http://www.elasticsearch.org/guide/reference/java-api/search.html) 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](https://github.com/elasticsearchfr/hands-on)  
> Answers are on answers branch:  
> [GitHub - elasticsearchfr/hands-on at answers](https://github.com/elasticsearchfr/hands-on/tree/answers)
> 
> Some slides (in french but you can understand code) are here:  
> [Hands on lab Elasticsearch | PPT](http://www.slideshare.net/mobile/dadoonet/hands-on-lab-elasticsearch)
> 
> I'm waiting for ES team to merge my Java tutorial:  
> [https://github.com/elasticsearch/elasticsearch.github.com/pull/321](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](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](mailto: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](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](http://www.elasticsearch.org/guide/reference/java-api/search.html) 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?
> 
> --

--

---

<div class="post-metadata">

**Author:** ![drewr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drewr/32/7803_2.png) [@drewr](https://discuss.elastic.co/u/drewr)\
**Post date:** [November 16, 2012, 9:37pm UTC](https://discuss.elastic.co/t/a-simple-example-of-how-to-use-the-java-api/9723/7 "2012-11-16T21:37:37Z")

</div>

ryan compton wrote:

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

Hi Ryan! I heartily recommend reading the tests in IntelliJ. That's  
how I usually figure out what was intended in the Java API. The  
coverage of the search API is pretty robust.

-Drew

--

---

<div class="post-metadata">

**Author:** ![ElasticSearch\_Users\_](https://avatars.discourse-cdn.com/v4/letter/e/b4bc9f/32.png) [@ElasticSearch\_Users\_](https://discuss.elastic.co/u/ElasticSearch_Users_)\
**Post date:** [March 24, 2015, 11:58am UTC](https://discuss.elastic.co/t/a-simple-example-of-how-to-use-the-java-api/9723/8 "2015-03-24T11:58:23Z")

</div>

Hey David,

I'm looking at the code now and I see lots of TODOs and nulls, but no  
actual indexing. Perhaps that code needs to be cleaned up?

On Thursday, November 15, 2012 at 9:11:02 AM UTC-5, David Pilato wrote:

> Hi Ryan,
> 
> Have a look at this: [GitHub - elasticsearchfr/hands-on: Hands On Lab](https://github.com/elasticsearchfr/hands-on)  
> Answers are on answers branch:  
> [GitHub - elasticsearchfr/hands-on at answers](https://github.com/elasticsearchfr/hands-on/tree/answers)
> 
> Some slides (in french but you can understand code) are here:  
> [Hands on lab Elasticsearch | PPT](http://www.slideshare.net/mobile/dadoonet/hands-on-lab-elasticsearch)
> 
> I'm waiting for ES team to merge my Java tutorial:  
> [https://github.com/elasticsearch/elasticsearch.github.com/pull/321](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](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

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/92c7a0f5-ef47-45c2-b121-8c0302fa8c71%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/92c7a0f5-ef47-45c2-b121-8c0302fa8c71%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 24, 2015, 12:05pm UTC](https://discuss.elastic.co/t/a-simple-example-of-how-to-use-the-java-api/9723/9 "2015-03-24T12:05:48Z")

</div>

Did you look at answer branch?

> > Answers are on answers branch: [GitHub - elasticsearchfr/hands-on at answers](https://github.com/elasticsearchfr/hands-on/tree/answers)

David

> Le 24 mars 2015 à 12:58, 'newbo' via elasticsearch [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com) a écrit :
> 
> Hey David,
> 
> I'm looking at the code now and I see lots of TODOs and nulls, but no actual indexing. Perhaps that code needs to be cleaned up?
> 
> > On Thursday, November 15, 2012 at 9:11:02 AM UTC-5, David Pilato wrote:
> > 
> > Hi Ryan,
> > 
> > Have a look at this: [GitHub - elasticsearchfr/hands-on: Hands On Lab](https://github.com/elasticsearchfr/hands-on)  
> > Answers are on answers branch: [GitHub - elasticsearchfr/hands-on at answers](https://github.com/elasticsearchfr/hands-on/tree/answers)
> > 
> > Some slides (in french but you can understand code) are here: [Hands on lab Elasticsearch | PPT](http://www.slideshare.net/mobile/dadoonet/hands-on-lab-elasticsearch)
> > 
> > I'm waiting for ES team to merge my Java tutorial: [https://github.com/elasticsearch/elasticsearch.github.com/pull/321](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](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
> 
> --  
> 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).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/92c7a0f5-ef47-45c2-b121-8c0302fa8c71%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/92c7a0f5-ef47-45c2-b121-8c0302fa8c71%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/F32F4B0D-3A65-45C6-BC95-19608C8AE62B%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/F32F4B0D-3A65-45C6-BC95-19608C8AE62B%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Mark\_Warner](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@Mark\_Warner](https://discuss.elastic.co/u/Mark_Warner)\
**Post date:** [March 27, 2015, 8:11pm UTC](https://discuss.elastic.co/t/a-simple-example-of-how-to-use-the-java-api/9723/10 "2015-03-27T20:11:07Z")

</div>

So where is a good java example showing how to use the java api to do a  
simple and condition. I can get this to work work fine with curl but how do  
I use the java api to implement it.

curl -XPOST 10.20.71.30:9200/sessionmsg/\_search?pretty -d '{  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"roomid": "7087"  
}  
},  
{  
"term": {  
"sessionid": "55622"  
}  
}  
]  
}  
}  
}  
}'

how can I implement the above with this kind of call?  
SearchResponse response = client.prepareSearch("sessionmsg")  
.setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
.setQuery(QueryBuilders.termQuery("roomid", "7087"))  
.setFrom(0).setSize(60).setExplain(true).execute().actionGet();

On Tuesday, March 24, 2015 at 8:05:57 AM UTC-4, David Pilato wrote:

> Did you look at answer branch?
> 
> Answers are on answers branch:
> 
> > [GitHub - elasticsearchfr/hands-on at answers](https://github.com/elasticsearchfr/hands-on/tree/answers)
> 
> David
> 
> Le 24 mars 2015 à 12:58, 'newbo' via elasticsearch \<  
> [elasti...@googlegroups.com](mailto:elasti...@googlegroups.com) \<javascript:\>\> a écrit :
> 
> Hey David,
> 
> I'm looking at the code now and I see lots of TODOs and nulls, but no  
> actual indexing. Perhaps that code needs to be cleaned up?
> 
> On Thursday, November 15, 2012 at 9:11:02 AM UTC-5, David Pilato wrote:
> 
> > Hi Ryan,
> > 
> > Have a look at this: [GitHub - elasticsearchfr/hands-on: Hands On Lab](https://github.com/elasticsearchfr/hands-on)  
> > Answers are on answers branch:  
> > [GitHub - elasticsearchfr/hands-on at answers](https://github.com/elasticsearchfr/hands-on/tree/answers)
> > 
> > Some slides (in french but you can understand code) are here:  
> > [Hands on lab Elasticsearch | PPT](http://www.slideshare.net/mobile/dadoonet/hands-on-lab-elasticsearch)
> > 
> > I'm waiting for ES team to merge my Java tutorial:  
> > [https://github.com/elasticsearch/elasticsearch.github.com/pull/321](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](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
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/92c7a0f5-ef47-45c2-b121-8c0302fa8c71%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/92c7a0f5-ef47-45c2-b121-8c0302fa8c71%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/92c7a0f5-ef47-45c2-b121-8c0302fa8c71%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/92c7a0f5-ef47-45c2-b121-8c0302fa8c71%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6541b592-3e0f-4d6e-8ae3-6e37595d3ee2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6541b592-3e0f-4d6e-8ae3-6e37595d3ee2%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Mark\_Warner](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@Mark\_Warner](https://discuss.elastic.co/u/Mark_Warner)\
**Post date:** [March 27, 2015, 8:36pm UTC](https://discuss.elastic.co/t/a-simple-example-of-how-to-use-the-java-api/9723/11 "2015-03-27T20:36:23Z")

</div>

Here is how you do it..

QueryBuilder qb = QueryBuilders  
.boolQuery()  
.must(QueryBuilders.termQuery("roomid","7087") )  
.must(QueryBuilders.termQuery("sessionid","55622"));

On Wednesday, November 14, 2012 at 10:04:41 PM UTC-5, Ryan Compton wrote:

> 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](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](http://www.elasticsearch.org/guide/reference/java-api/search.html) 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?

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/84c0ad1c-7242-49ae-ac2b-3f9ea0d0a619%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/84c0ad1c-7242-49ae-ac2b-3f9ea0d0a619%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:23am UTC](https://discuss.elastic.co/t/a-simple-example-of-how-to-use-the-java-api/9723/12 "2017-07-06T00:23:23Z")

</div>


