Have you tried setting no fields to be returned or the explicit
setNoFields() method?

http://jenkins.elasticsearch.org/job/Elasticsearch%20Master%20Branch%20Javadoc/Elasticsearch_API_Documentation/org/elasticsearch/action/search/SearchRequestBuilder.html#setNoFields()

-- 
Ivan

On Thu, Oct 16, 2014 at 2:45 AM, Ilija Subasic <subasic.il...@gmail.com>
wrote:

> Is there a way in elasticsearch using JAVA API to get only the ids of the
> documents returned for a give query.
>
>     SearchResponse sr =
>  esClient.prepareSearch(index).setSize(resultSize).setQuery(q).setScroll(new
> TimeValue(10000)).setQuery(fqb).setFetchSource(false).get();
>
> but I get empty hits (`sr.getHits().hits[].length == 0`) althouh the total
> count of returned hits is 0 (`sr.getHits().getTotalHits == 2`). I
> understand that nothing is returned by elasticsearch because I set fetch
> source to false, but the ids should somehow be available. My current
> solution is:
>
>     SearchResponse sr =
>  esClient.prepareSearch(index).setSize(resultSize).setQuery(q).setScroll(new
> TimeValue(10000)).setQuery(fqb).srb.setFetchSource("_id", null).get();
>
> However I think that gets the _id field from source, and for speed I would
> like to avoid this if possible.
>
> Thanks,
> Ilija
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/089b670f-763c-4795-859a-720767d24a81%40googlegroups.com
> <https://groups.google.com/d/msgid/elasticsearch/089b670f-763c-4795-859a-720767d24a81%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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCYskSm7WyTDX5LVCrcL%2BR5y%2B2e9fUBTH0Z8iamu06OBg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to