# Not getting results from java search api

**URL:** <https://discuss.elastic.co/t/not-getting-results-from-java-search-api/16583>\
**Category:** Elasticsearch\
**Created:** [March 25, 2014, 12:19pm UTC](https://discuss.elastic.co/t/not-getting-results-from-java-search-api/16583 "2014-03-25T12:19:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bagui](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bagui/32/960_2.png) [@bagui](https://discuss.elastic.co/u/bagui)\
**Post date:** [March 25, 2014, 12:19pm UTC](https://discuss.elastic.co/t/not-getting-results-from-java-search-api/16583/1 "2014-03-25T12:19:03Z")

</div>

Hi,

I'm using the below method to get results from ES. But search hit result is  
0. Please let me know the correct way to get results,

public static SearchResponse searchIndex(Client client, Node node)  
{  
SearchRequestBuilder srequest =  
client.prepareSearch("testindex").setTypes("testtype")  
.setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
.setQuery(QueryBuilders.termQuery("author", "shay"))  
.setSize(1);  
SearchResponse sresp = srequest.execute().actionGet();  
return sresp;  
}

data ==\>

- "\_source":{
  - "tags":[
    - "elasticsearch"  
],

  - "content":"ElasticSearch provides the Java API",
  - "author":"Shay Banon",
  - "title":"ElasticSearch: Java API",
  - "postDate":"2014-03-21T09:32:34.782Z"  
}

Thanks,  
Subhadip

--  
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/293d28fb-5aaa-40cf-a77a-c7966c37536d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/293d28fb-5aaa-40cf-a77a-c7966c37536d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [March 25, 2014, 1:30pm UTC](https://discuss.elastic.co/t/not-getting-results-from-java-search-api/16583/2 "2014-03-25T13:30:53Z")

</div>

Have to tried matchQuery instead of termQuery?

Jörg

On Tue, Mar 25, 2014 at 1:19 PM, Subhadip Bagui [i.bagui@gmail.com](mailto:i.bagui@gmail.com) wrote:

> Hi,
> 
> I'm using the below method to get results from ES. But search hit result  
> is 0. Please let me know the correct way to get results,
> 
> public static SearchResponse searchIndex(Client client, Node node)  
> {  
> SearchRequestBuilder srequest =  
> client.prepareSearch("testindex").setTypes("testtype")  
> .setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
> .setQuery(QueryBuilders.termQuery("author", "shay"))  
> .setSize(1);  
> SearchResponse sresp = srequest.execute().actionGet();  
> return sresp;  
> }
> 
> data ==\>
> 
> - "\_source":{
> - "tags":[
> - "elasticsearch"  
> ],
> 
> - "content":"Elasticsearch provides the Java API",
> - "author":"Shay Banon",
> - "title":"Elasticsearch: Java API",
> - "postDate":"2014-03-21T09:32:34.782Z"  
> }
> 
> Thanks,  
> Subhadip
> 
> --  
> 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/293d28fb-5aaa-40cf-a77a-c7966c37536d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/293d28fb-5aaa-40cf-a77a-c7966c37536d%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/293d28fb-5aaa-40cf-a77a-c7966c37536d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/293d28fb-5aaa-40cf-a77a-c7966c37536d%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/CAKdsXoGCGGk6dG%3Dbps0Bg7hYktt0E%3DCio44Ga2BeVwmL-c-guQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoGCGGk6dG%3Dbps0Bg7hYktt0E%3DCio44Ga2BeVwmL-c-guQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![bagui](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bagui/32/960_2.png) [@bagui](https://discuss.elastic.co/u/bagui)\
**Post date:** [March 25, 2014, 2:19pm UTC](https://discuss.elastic.co/t/not-getting-results-from-java-search-api/16583/3 "2014-03-25T14:19:53Z")

</div>

I changed the SearchType as SearchType.QUERY\_AND\_FETCH and its giving  
correct response now.  
Thanks...

--  
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/0bb84d71-9c83-45a2-b4ff-00c775fdb598%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0bb84d71-9c83-45a2-b4ff-00c775fdb598%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, 1:40am UTC](https://discuss.elastic.co/t/not-getting-results-from-java-search-api/16583/4 "2017-07-06T01:40:47Z")

</div>


