# Java Api

**URL:** https://discuss.elastic.co/t/java-api/4756
**Category:** Elasticsearch
**Created:** [July 2, 2011, 11:31am UTC](https://discuss.elastic.co/t/java-api/4756 "2011-07-02T11:31:11Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![nachiket](https://avatars.discourse-cdn.com/v4/letter/n/4491bb/32.png) [@nachiket](https://discuss.elastic.co/u/nachiket)
#### Post date: [July 2, 2011, 11:31am UTC](https://discuss.elastic.co/t/java-api/4756/1 "2011-07-02T11:31:11Z")

</div>

Hi. There is very less documentation on Java api. I could not figure  
out even how to build simple queries like termQuery. Can somebody  
help ??

---

<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: [July 2, 2011, 11:36am UTC](https://discuss.elastic.co/t/java-api/4756/2 "2011-07-02T11:36:52Z")

</div>

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Show a working example

David 😉

Le 2 juil. 2011 à 13:31, nachiket bhagwat [nachiketbhagwat@gmail.com](mailto:nachiketbhagwat@gmail.com) a écrit :

> Hi. There is very less documentation on Java api. I could not figure  
> out even how to build simple queries like termQuery. Can somebody  
> help ??

---

<div class="post-metadata">

### Author: ![nachiket](https://avatars.discourse-cdn.com/v4/letter/n/4491bb/32.png) [@nachiket](https://discuss.elastic.co/u/nachiket)
#### Post date: [July 2, 2011, 11:52am UTC](https://discuss.elastic.co/t/java-api/4756/3 "2011-07-02T11:52:29Z")

</div>

Hi David. I have tried using the query you gave reference of. But it  
is also not working. What I cant understand is how termQuery is  
working without being part of any class. If it is part of a class how  
termQuery("multi", "test") is running without initializing termquery  
first.

On Jul 2, 4:36 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/java-api/search.html)
> 
> Show a working example
> 
> David 😉
> 
> Le 2 juil. 2011 à 13:31, nachiket bhagwat [nachiketbhag...@gmail.com](mailto:nachiketbhag...@gmail.com) a écrit :
> 
> > Hi. There is very less documentation on Java api. I could not figure  
> > out even how to build simple queries like termQuery. Can somebody  
> > help ??

---

<div class="post-metadata">

### Author: ![nachiket](https://avatars.discourse-cdn.com/v4/letter/n/4491bb/32.png) [@nachiket](https://discuss.elastic.co/u/nachiket)
#### Post date: [July 2, 2011, 12:01pm UTC](https://discuss.elastic.co/t/java-api/4756/4 "2011-07-02T12:01:01Z")

</div>

Ok I tried QueryBuilders.termQuery and it worked. But now it is  
showing a different error.

SearchResponse response = client.prepareSearch("test")  
.setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
.setQuery(QueryBuilders.termQuery( "user" , "new"))  
.setFrom(0).setSize(60).setExplain(true)) \<\<\<- Error here.  
Syntax error on token ")", delete this token  
.execute()  
.actionGet();

On Jul 2, 4:52 pm, nachiket bhagwat [nachiketbhag...@gmail.com](mailto:nachiketbhag...@gmail.com) wrote:

> Hi David. I have tried using the query you gave reference of. But it  
> is also not working. What I cant understand is how termQuery is  
> working without being part of any class. If it is part of a class how  
> termQuery("multi", "test") is running without initializing termquery  
> first.
> 
> On Jul 2, 4:36 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/java-api/search.html)
> 
> > Show a working example
> 
> > David 😉
> 
> > Le 2 juil. 2011 à 13:31, nachiket bhagwat [nachiketbhag...@gmail.com](mailto:nachiketbhag...@gmail.com) a écrit :
> 
> > > Hi. There is very less documentation on Java api. I could not figure  
> > > out even how to build simple queries like termQuery. Can somebody  
> > > help ??

---

<div class="post-metadata">

### Author: ![Hari\_Shankar](https://avatars.discourse-cdn.com/v4/letter/h/ad7895/32.png) [@Hari\_Shankar](https://discuss.elastic.co/u/Hari_Shankar)
#### Post date: [July 2, 2011, 2:47pm UTC](https://discuss.elastic.co/t/java-api/4756/5 "2011-07-02T14:47:23Z")

</div>

Hi,

Do what it says.. delete the ")" bracket, there is a bracket mismatch! I am  
also new to es, and it is true that there could be more documentation of the  
Java API, and I too struggled a bit initially with it, but it is actually  
not that difficult to figure it out, knowing that the REST API internally  
uses the Java API. Just compare the Java API examples side-by-side with the  
corresponding REST API and you'll see the pattern.

Hari

On Sat, Jul 2, 2011 at 5:31 PM, nachiket bhagwat  
[nachiketbhagwat@gmail.com](mailto:nachiketbhagwat@gmail.com)wrote:

> Ok I tried QueryBuilders.termQuery and it worked. But now it is  
> showing a different error.
> 
> SearchResponse response = client.prepareSearch("test")  
> .setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
> .setQuery(QueryBuilders.termQuery( "user" , "new"))  
> .setFrom(0).setSize(60).setExplain(true)) \<\<\<- Error here.  
> Syntax error on token ")", delete this token  
> .execute()  
> .actionGet();
> 
> On Jul 2, 4:52 pm, nachiket bhagwat [nachiketbhag...@gmail.com](mailto:nachiketbhag...@gmail.com) wrote:
> 
> > Hi David. I have tried using the query you gave reference of. But it  
> > is also not working. What I cant understand is how termQuery is  
> > working without being part of any class. If it is part of a class how  
> > termQuery("multi", "test") is running without initializing termquery  
> > first.
> > 
> > On Jul 2, 4:36 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> > 
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/java-api/search.html)
> > 
> > > Show a working example
> > 
> > > David 😉
> > 
> > > Le 2 juil. 2011 à 13:31, nachiket bhagwat [nachiketbhag...@gmail.com](mailto:nachiketbhag...@gmail.com)  
> > > a écrit :
> > 
> > > > Hi. There is very less documentation on Java api. I could not figure  
> > > > out even how to build simple queries like termQuery. Can somebody  
> > > > help ??

---

<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, 4:02am UTC](https://discuss.elastic.co/t/java-api/4756/6 "2017-07-06T04:02:01Z")

</div>


