Not getting results from java search api


(bagui) #1

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/293d28fb-5aaa-40cf-a77a-c7966c37536d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Jörg Prante) #2

Have to tried matchQuery instead of termQuery?

Jörg

On Tue, Mar 25, 2014 at 1:19 PM, Subhadip Bagui 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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/293d28fb-5aaa-40cf-a77a-c7966c37536d%40googlegroups.comhttps://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.

--
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.
To view this discussion on the web visit 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.


(bagui) #3

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/0bb84d71-9c83-45a2-b4ff-00c775fdb598%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #4