# Java API

**URL:** https://discuss.elastic.co/t/java-api/4496
**Category:** Elasticsearch
**Created:** [May 28, 2011, 8:45pm UTC](https://discuss.elastic.co/t/java-api/4496 "2011-05-28T20:45:33Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)
#### Post date: [May 28, 2011, 8:45pm UTC](https://discuss.elastic.co/t/java-api/4496/1 "2011-05-28T20:45:33Z")

</div>

Hi,  
I'm a newbie in the elasticsearch and trying to make simple test,  
create an index and the search for it, but i get 0 hits, here the  
sample:

```
Node node = nodeBuilder().client(true).node();
		Client client = node.client();
		IndexResponse indexRes = client.prepareIndex("test", "contacts",

```

"1")  
.setSource(jsonBuilder()  
.startObject()  
.field("Name", "Test\_Name")  
.field("BirthDate", new Date())  
.field("Email", "test@test.com")  
.endObject()).execute().actionGet();

```
		SearchRequestBuilder searchRequestBuilder =

```

client.prepareSearch("test");  
searchRequestBuilder.setTypes("contacts");

searchRequestBuilder.setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH);  
searchRequestBuilder.setQuery(termQuery("Name", "Test\_Name"));  
searchRequestBuilder.setFrom(0).setSize(60).setExplain(true);  
SearchResponse response =  
searchRequestBuilder.execute().actionGet();

```
                  node.close();

```

Please , tell me what I'm doing wrong.

Thank You and Best Regards.  
Slava.

---

<div class="post-metadata">

### Author: ![dpilato](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dpilato/32/2449_2.png) [@dpilato](https://discuss.elastic.co/u/dpilato)
#### Post date: [May 28, 2011, 8:52pm UTC](https://discuss.elastic.co/t/java-api/4496/2 "2011-05-28T20:52:16Z")

</div>

Test\_Name has been tokenized to Test and Name.  
So, searching Test\_Name can not work.

You should search test or name to find something.

Hope this helps,  
David

---

<div class="post-metadata">

### Author: ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)
#### Post date: [May 28, 2011, 9:06pm UTC](https://discuss.elastic.co/t/java-api/4496/3 "2011-05-28T21:06:25Z")

</div>

Changed to "Test" - same result - 0 hits:

Node node = nodeBuilder().client(true).node();  
Client client = node.client();  
IndexResponse indexRes = client.prepareIndex("test", "contacts",  
"1")  
.setSource(jsonBuilder()  
.startObject()  
.field("Name", "Test")  
.field("BirthDate", new Date())  
.field("Email", "[test@test.com](mailto:test@test.com)")  
.endObject()  
)  
.execute()  
.actionGet();

```
		SearchRequestBuilder searchRequestBuilder =

```

client.prepareSearch("test");  
[//searchRequestBuilder.setTypes](https://searchRequestBuilder.setTypes)("contacts");

searchRequestBuilder.setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH);  
searchRequestBuilder.setQuery(termQuery("Name", "Test"));  
searchRequestBuilder.setFrom(0).setSize(60).setExplain(false);  
SearchResponse response =  
searchRequestBuilder.execute().actionGet();

```
		node.close();

```

Thank You and Best Regards.

On May 28, 11:52 pm, dpilato [david.pil...@douane.finances.gouv.fr](mailto:david.pil...@douane.finances.gouv.fr)  
wrote:

> Test\_Name has been tokenized to Test and Name.  
> So, searching Test\_Name can not work.
> 
> You should search test or name to find something.
> 
> Hope this helps,  
> David
> 
> --  
> View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/Java-API-tp2997083p29](http://elasticsearch-users.115913.n3.nabble.com/Java-API-tp2997083p29)...  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

### Author: ![dpilato](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dpilato/32/2449_2.png) [@dpilato](https://discuss.elastic.co/u/dpilato)
#### Post date: [May 28, 2011, 9:09pm UTC](https://discuss.elastic.co/t/java-api/4496/4 "2011-05-28T21:09:22Z")

</div>

What about test in lowercase ?

---

<div class="post-metadata">

### Author: ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)
#### Post date: [May 28, 2011, 9:13pm UTC](https://discuss.elastic.co/t/java-api/4496/5 "2011-05-28T21:13:00Z")

</div>

Cool 🙂 10x it's works,  
But is it means that all data should be lower case ? What are the  
rules for that ?  
Is there any document explains all such restrictions ?

Thank You and Best Regards.

On May 29, 12:09 am, dpilato [david.pil...@douane.finances.gouv.fr](mailto:david.pil...@douane.finances.gouv.fr)  
wrote:

> What about test in lowercase ?
> 
> --  
> View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/Java-API-tp2997083p29](http://elasticsearch-users.115913.n3.nabble.com/Java-API-tp2997083p29)...  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

### Author: ![dpilato](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dpilato/32/2449_2.png) [@dpilato](https://discuss.elastic.co/u/dpilato)
#### Post date: [May 28, 2011, 10:18pm UTC](https://discuss.elastic.co/t/java-api/4496/6 "2011-05-28T22:18:03Z")

</div>

Term request is case sensitive. querystring query should work.

Here is a good starting URL : [http://www.elasticsearch.org/guide/reference/query-dsl/](http://www.elasticsearch.org/guide/reference/query-dsl/)

Cheers  
David

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [May 29, 2011, 5:58am UTC](https://discuss.elastic.co/t/java-api/4496/7 "2011-05-29T05:58:12Z")

</div>

Or, better yet in 0.16.1, text queries (though it has a bug in it for the Java API that will be fixed in 0.16.2).

On Sunday, May 29, 2011 at 1:18 AM, dpilato wrote:

> Term request is case sensitive. querystring query should work.
> 
> Here is a good starting URL :  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/)
> 
> Cheers  
> David
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Java-API-tp2997083p2997407.html](http://elasticsearch-users.115913.n3.nabble.com/Java-API-tp2997083p2997407.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com) ([http://Nabble.com](http://Nabble.com)).

---

<div class="post-metadata">

### Author: ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)
#### Post date: [May 29, 2011, 8:02am UTC](https://discuss.elastic.co/t/java-api/4496/8 "2011-05-29T08:02:26Z")

</div>

Thank You, I'll look on it,  
Btw, is there any sample for text queries in Java API ?

Thank You.

On May 29, 8:58 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Or, better yet in 0.16.1, text queries (though it has a bug in it for the Java API that will be fixed in 0.16.2).
> 
> On Sunday, May 29, 2011 at 1:18 AM, dpilato wrote:
> 
> > Term request is case sensitive. querystring query should work.
> 
> > Here is a good starting URL :  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/)
> 
> > Cheers  
> > David
> 
> > --  
> > View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/Java-API-tp2997083p29](http://elasticsearch-users.115913.n3.nabble.com/Java-API-tp2997083p29)...  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com) ([http://Nabble.com](http://Nabble.com)).

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [May 29, 2011, 3:01pm UTC](https://discuss.elastic.co/t/java-api/4496/9 "2011-05-29T15:01:31Z")

</div>

replace QueryBuilders#term with QueryBuilders#text, pretty basic stuff.

On Sunday, May 29, 2011 at 11:02 AM, slavag wrote:

> Thank You, I'll look on it,  
> Btw, is there any sample for text queries in Java API ?
> 
> Thank You.
> 
> On May 29, 8:58 am, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> 
> > Or, better yet in 0.16.1, text queries (though it has a bug in it for the Java API that will be fixed in 0.16.2).
> > 
> > On Sunday, May 29, 2011 at 1:18 AM, dpilato wrote:
> > 
> > > Term request is case sensitive. querystring query should work.
> > 
> > > Here is a good starting URL :  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/)
> > 
> > > Cheers  
> > > David
> > 
> > > --  
> > > View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/Java-API-tp2997083p29](http://elasticsearch-users.115913.n3.nabble.com/Java-API-tp2997083p29)...  
> > > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com) ([http://Nabble.com](http://Nabble.com)).

---

<div class="post-metadata">

### Author: ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)
#### Post date: [May 29, 2011, 5:28pm UTC](https://discuss.elastic.co/t/java-api/4496/10 "2011-05-29T17:28:53Z")

</div>

Thank You.  
As I said - started to use elasticsearch last night 🙂

On May 29, 6:01 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> replace QueryBuilders#term with QueryBuilders#text, pretty basic stuff.
> 
> On Sunday, May 29, 2011 at 11:02 AM, slavag wrote:
> 
> > Thank You, I'll look on it,  
> > Btw, is there any sample for text queries in Java API ?
> 
> > Thank You.
> 
> > On May 29, 8:58 am, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > 
> > > Or, better yet in 0.16.1, text queries (though it has a bug in it for the Java API that will be fixed in 0.16.2).
> 
> > > On Sunday, May 29, 2011 at 1:18 AM, dpilato wrote:
> > > 
> > > > Term request is case sensitive. querystring query should work.
> 
> > > > Here is a good starting URL :  
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/)
> 
> > > > Cheers  
> > > > David
> 
> > > > --  
> > > > View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/Java-API-tp2997083p29](http://elasticsearch-users.115913.n3.nabble.com/Java-API-tp2997083p29)...  
> > > > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com) ([http://Nabble.com](http://Nabble.com)).

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [May 29, 2011, 5:39pm UTC](https://discuss.elastic.co/t/java-api/4496/11 "2011-05-29T17:39:48Z")

</div>

Great :), there are some samples here: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/java-api/query-dsl.html). And basically, all the queries that you can use exists in the QueryBuilders static factory, and all the filters are in FilterBuilders.

On Sunday, May 29, 2011 at 8:28 PM, slavag wrote:

> Thank You.  
> As I said - started to use elasticsearch last night 🙂
> 
> On May 29, 6:01 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> 
> > replace QueryBuilders#term with QueryBuilders#text, pretty basic stuff.
> > 
> > On Sunday, May 29, 2011 at 11:02 AM, slavag wrote:
> > 
> > > Thank You, I'll look on it,  
> > > Btw, is there any sample for text queries in Java API ?
> > 
> > > Thank You.
> > 
> > > On May 29, 8:58 am, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > 
> > > > Or, better yet in 0.16.1, text queries (though it has a bug in it for the Java API that will be fixed in 0.16.2).
> > 
> > > > On Sunday, May 29, 2011 at 1:18 AM, dpilato wrote:
> > > > 
> > > > > Term request is case sensitive. querystring query should work.
> > 
> > > > > Here is a good starting URL :  
> > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/)
> > 
> > > > > Cheers  
> > > > > David
> > 
> > > > > --  
> > > > > View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/Java-API-tp2997083p29](http://elasticsearch-users.115913.n3.nabble.com/Java-API-tp2997083p29)...  
> > > > > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com) ([http://Nabble.com](http://Nabble.com)).

---

<div class="post-metadata">

### Author: ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)
#### Post date: [May 29, 2011, 6:12pm UTC](https://discuss.elastic.co/t/java-api/4496/12 "2011-05-29T18:12:27Z")

</div>

10x for advise.

On May 29, 8:39 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Great :), there are some samples here:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/java-api/query-dsl.html). And basically, all the queries that you can use exists in the QueryBuilders static factory, and all the filters are in FilterBuilders.
> 
> On Sunday, May 29, 2011 at 8:28 PM, slavag wrote:
> 
> > Thank You.  
> > As I said - started to use elasticsearch last night 🙂
> 
> > On May 29, 6:01 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > 
> > > replace QueryBuilders#term with QueryBuilders#text, pretty basic stuff.
> 
> > > On Sunday, May 29, 2011 at 11:02 AM, slavag wrote:
> > > 
> > > > Thank You, I'll look on it,  
> > > > Btw, is there any sample for text queries in Java API ?
> 
> > > > Thank You.
> 
> > > > On May 29, 8:58 am, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > 
> > > > > Or, better yet in 0.16.1, text queries (though it has a bug in it for the Java API that will be fixed in 0.16.2).
> 
> > > > > On Sunday, May 29, 2011 at 1:18 AM, dpilato wrote:
> > > > > 
> > > > > > Term request is case sensitive. querystring query should work.
> 
> > > > > > Here is a good starting URL :  
> > > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/)
> 
> > > > > > Cheers  
> > > > > > David
> 
> > > > > > --  
> > > > > > View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/Java-API-tp2997083p29](http://elasticsearch-users.115913.n3.nabble.com/Java-API-tp2997083p29)...  
> > > > > > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com) ([http://Nabble.com](http://Nabble.com)).

---

<div class="post-metadata">

### Author: ![fashionalwallet](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@fashionalwallet](https://discuss.elastic.co/u/fashionalwallet)
#### Post date: [June 10, 2011, 3:42am UTC](https://discuss.elastic.co/t/java-api/4496/13 "2011-06-10T03:42:55Z")

</div>

- deleted -

---

<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:04am UTC](https://discuss.elastic.co/t/java-api/4496/14 "2017-07-06T04:04:01Z")

</div>


