# Search JAVA search API not working

**URL:** <https://discuss.elastic.co/t/search-java-search-api-not-working/16534>\
**Category:** Elasticsearch\
**Created:** [March 21, 2014, 9:13pm UTC](https://discuss.elastic.co/t/search-java-search-api-not-working/16534 "2014-03-21T21:13:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohit\_Anchlia](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@Mohit\_Anchlia](https://discuss.elastic.co/u/Mohit_Anchlia)\
**Post date:** [March 21, 2014, 9:13pm UTC](https://discuss.elastic.co/t/search-java-search-api-not-working/16534/1 "2014-03-21T21:13:01Z")

</div>

The below code doesn't seem to match the document for some reason. Same  
query when run directly using REST API works. Am I doing something wrong in  
the code?

queryString="fields.field1:value1";

searchResponse = client.prepareSearch()  
.setQuery(QueryBuilders.queryString(queryString)).execute()  
.actionGet();

Doc that I expect to match  
'{  
"namespace": "ns1",  
"id": "3",  
"fastId": "f1",  
"version": 1393443298027,  
"lang": "en",  
"opType": "create",  
"fields": {  
"field2": "value2",  
"field1": "value1"  
},  
"arrayFields": {}  
}'

--  
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/CAOT3TWoSGTpNQpHBUUNpa0qQr0X8rm7pZXoqxYqcb-349xkrmA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAOT3TWoSGTpNQpHBUUNpa0qQr0X8rm7pZXoqxYqcb-349xkrmA%40mail.gmail.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 21, 2014, 9:18pm UTC](https://discuss.elastic.co/t/search-java-search-api-not-working/16534/2 "2014-03-21T21:18:33Z")

</div>

Are you just searching in your code or indexing as well?  
Could it be caused because you did not refresh before searching?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 21 mars 2014 à 22:13, Mohit Anchlia [mohitanchlia@gmail.com](mailto:mohitanchlia@gmail.com) a écrit :

The below code doesn't seem to match the document for some reason. Same query when run directly using REST API works. Am I doing something wrong in the code?

queryString="fields.field1:value1";

```
		searchResponse = client.prepareSearch()
				.setQuery(QueryBuilders.queryString(queryString)).execute()
				.actionGet();

```

Doc that I expect to match  
'{  
"namespace": "ns1",  
"id": "3",  
"fastId": "f1",  
"version": 1393443298027,  
"lang": "en",  
"opType": "create",  
"fields": {  
"field2": "value2",  
"field1": "value1"  
},  
"arrayFields": {}  
}'

--  
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/CAOT3TWoSGTpNQpHBUUNpa0qQr0X8rm7pZXoqxYqcb-349xkrmA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAOT3TWoSGTpNQpHBUUNpa0qQr0X8rm7pZXoqxYqcb-349xkrmA%40mail.gmail.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/0772CCDA-1515-4B40-8808-FA701E358327%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/0772CCDA-1515-4B40-8808-FA701E358327%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Mohit\_Anchlia](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@Mohit\_Anchlia](https://discuss.elastic.co/u/Mohit_Anchlia)\
**Post date:** [March 21, 2014, 9:24pm UTC](https://discuss.elastic.co/t/search-java-search-api-not-working/16534/3 "2014-03-21T21:24:37Z")

</div>

oh, I forgot refresh. Let me try that. By default it's 1 sec right?

On Fri, Mar 21, 2014 at 2:18 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Are you just searching in your code or indexing as well?  
> Could it be caused because you did not refresh before searching?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 21 mars 2014 à 22:13, Mohit Anchlia [mohitanchlia@gmail.com](mailto:mohitanchlia@gmail.com) a écrit :
> 
> The below code doesn't seem to match the document for some reason. Same  
> query when run directly using REST API works. Am I doing something wrong in  
> the code?
> 
> queryString="fields.field1:value1";
> 
> searchResponse = client.prepareSearch()  
> .setQuery(QueryBuilders.queryString(queryString)).execute()  
> .actionGet();
> 
> Doc that I expect to match  
> '{  
> "namespace": "ns1",  
> "id": "3",  
> "fastId": "f1",  
> "version": 1393443298027,  
> "lang": "en",  
> "opType": "create",  
> "fields": {  
> "field2": "value2",  
> "field1": "value1"  
> },  
> "arrayFields": {}  
> }'
> 
> --  
> 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/CAOT3TWoSGTpNQpHBUUNpa0qQr0X8rm7pZXoqxYqcb-349xkrmA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAOT3TWoSGTpNQpHBUUNpa0qQr0X8rm7pZXoqxYqcb-349xkrmA%40mail.gmail.com)[https://groups.google.com/d/msgid/elasticsearch/CAOT3TWoSGTpNQpHBUUNpa0qQr0X8rm7pZXoqxYqcb-349xkrmA%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAOT3TWoSGTpNQpHBUUNpa0qQr0X8rm7pZXoqxYqcb-349xkrmA%40mail.gmail.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/0772CCDA-1515-4B40-8808-FA701E358327%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/0772CCDA-1515-4B40-8808-FA701E358327%40pilato.fr)[https://groups.google.com/d/msgid/elasticsearch/0772CCDA-1515-4B40-8808-FA701E358327%40pilato.fr?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/0772CCDA-1515-4B40-8808-FA701E358327%40pilato.fr?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/CAOT3TWoEuUrsy1j-i\_yTcQxoRyCR-nsYyDTQwvw\_QT-6dsYTnQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAOT3TWoEuUrsy1j-i_yTcQxoRyCR-nsYyDTQwvw_QT-6dsYTnQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Mohit\_Anchlia](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@Mohit\_Anchlia](https://discuss.elastic.co/u/Mohit_Anchlia)\
**Post date:** [March 21, 2014, 9:34pm UTC](https://discuss.elastic.co/t/search-java-search-api-not-working/16534/4 "2014-03-21T21:34:57Z")

</div>

Thanks! refresh was the issue. Is there a easy way to find how many  
documents are in index using Java API?

On Fri, Mar 21, 2014 at 2:24 PM, Mohit Anchlia [mohitanchlia@gmail.com](mailto:mohitanchlia@gmail.com)wrote:

> oh, I forgot refresh. Let me try that. By default it's 1 sec right?
> 
> On Fri, Mar 21, 2014 at 2:18 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > Are you just searching in your code or indexing as well?  
> > Could it be caused because you did not refresh before searching?
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 21 mars 2014 à 22:13, Mohit Anchlia [mohitanchlia@gmail.com](mailto:mohitanchlia@gmail.com) a écrit :
> > 
> > The below code doesn't seem to match the document for some reason. Same  
> > query when run directly using REST API works. Am I doing something wrong in  
> > the code?
> > 
> > queryString="fields.field1:value1";
> > 
> > searchResponse = client.prepareSearch()  
> > .setQuery(QueryBuilders.queryString(queryString)).execute()  
> > .actionGet();
> > 
> > Doc that I expect to match  
> > '{  
> > "namespace": "ns1",  
> > "id": "3",  
> > "fastId": "f1",  
> > "version": 1393443298027,  
> > "lang": "en",  
> > "opType": "create",  
> > "fields": {  
> > "field2": "value2",  
> > "field1": "value1"  
> > },  
> > "arrayFields": {}  
> > }'
> > 
> > --  
> > 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/CAOT3TWoSGTpNQpHBUUNpa0qQr0X8rm7pZXoqxYqcb-349xkrmA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAOT3TWoSGTpNQpHBUUNpa0qQr0X8rm7pZXoqxYqcb-349xkrmA%40mail.gmail.com)[https://groups.google.com/d/msgid/elasticsearch/CAOT3TWoSGTpNQpHBUUNpa0qQr0X8rm7pZXoqxYqcb-349xkrmA%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAOT3TWoSGTpNQpHBUUNpa0qQr0X8rm7pZXoqxYqcb-349xkrmA%40mail.gmail.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/0772CCDA-1515-4B40-8808-FA701E358327%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/0772CCDA-1515-4B40-8808-FA701E358327%40pilato.fr)[https://groups.google.com/d/msgid/elasticsearch/0772CCDA-1515-4B40-8808-FA701E358327%40pilato.fr?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/0772CCDA-1515-4B40-8808-FA701E358327%40pilato.fr?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/CAOT3TWoev84CMWigQJMkBEaW\_KsGpYc%2BWCA9qaHPQxXUt2sr8A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAOT3TWoev84CMWigQJMkBEaW_KsGpYc%2BWCA9qaHPQxXUt2sr8A%40mail.gmail.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 22, 2014, 3:53am UTC](https://discuss.elastic.co/t/search-java-search-api-not-working/16534/5 "2014-03-22T03:53:02Z")

</div>

client.prepareCount()

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 21 mars 2014 à 22:34, Mohit Anchlia [mohitanchlia@gmail.com](mailto:mohitanchlia@gmail.com) a écrit :

Thanks! refresh was the issue. Is there a easy way to find how many documents are in index using Java API?

> On Fri, Mar 21, 2014 at 2:24 PM, Mohit Anchlia [mohitanchlia@gmail.com](mailto:mohitanchlia@gmail.com) wrote:  
> oh, I forgot refresh. Let me try that. By default it's 1 sec right?
> 
> > On Fri, Mar 21, 2014 at 2:18 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
> > Are you just searching in your code or indexing as well?  
> > Could it be caused because you did not refresh before searching?
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 21 mars 2014 à 22:13, Mohit Anchlia [mohitanchlia@gmail.com](mailto:mohitanchlia@gmail.com) a écrit :
> > 
> > The below code doesn't seem to match the document for some reason. Same query when run directly using REST API works. Am I doing something wrong in the code?
> > 
> > queryString="fields.field1:value1";
> > 
> > ```
> > searchResponse = client.prepareSearch()
> > .setQuery(QueryBuilders.queryString(queryString)).execute()
> > .actionGet();
> > 
> > ```
> > 
> > Doc that I expect to match  
> > '{  
> > "namespace": "ns1",  
> > "id": "3",  
> > "fastId": "f1",  
> > "version": 1393443298027,  
> > "lang": "en",  
> > "opType": "create",  
> > "fields": {  
> > "field2": "value2",  
> > "field1": "value1"  
> > },  
> > "arrayFields": {}  
> > }'
> > 
> > ## -- 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/CAOT3TWoSGTpNQpHBUUNpa0qQr0X8rm7pZXoqxYqcb-349xkrmA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAOT3TWoSGTpNQpHBUUNpa0qQr0X8rm7pZXoqxYqcb-349xkrmA%40mail.gmail.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/0772CCDA-1515-4B40-8808-FA701E358327%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/0772CCDA-1515-4B40-8808-FA701E358327%40pilato.fr).  
> > 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/CAOT3TWoev84CMWigQJMkBEaW\_KsGpYc%2BWCA9qaHPQxXUt2sr8A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAOT3TWoev84CMWigQJMkBEaW_KsGpYc%2BWCA9qaHPQxXUt2sr8A%40mail.gmail.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/BC821437-7504-46BB-9F24-1B0DC42F086D%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/BC821437-7504-46BB-9F24-1B0DC42F086D%40pilato.fr).  
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, 1:41am UTC](https://discuss.elastic.co/t/search-java-search-api-not-working/16534/6 "2017-07-06T01:41:27Z")

</div>


