9

I am new to Elastic Search. Is there any way to get all the search results for a search keyword? Elastic Search is limited to 10 or else we can set the size but we need to get the size??

Ramaraj Karuppusamy
  • 2,350
  • 5
  • 24
  • 35
raagavan
  • 951
  • 3
  • 12
  • 16
  • 1
    I would recoment to use scroll search for fetching all records(like paging). http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-scroll.html – Emil Jun 25 '14 at 11:09

3 Answers3

16

Yes, the default number of search results is 10.

You need to set the size parameter on the query.

I don't think you an say "all results", though, there must always be a size limit.

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • @raagavan: Total size of what? – skaffman Feb 14 '11 at 10:13
  • @skaffman see if i search an keyword `example` if it is in 200 document i need to display the 200 results .. – raagavan Feb 14 '11 at 10:24
  • is there is any way to make field collapase like solr `http://blog.jteam.nl/2009/10/20/result-grouping-field-collapsing-with-solr/` – raagavan Feb 14 '11 at 10:43
  • @raagavan no. but you could look into chield parent stuff: http://www.elasticsearch.org/guide/reference/query-dsl/has-child-filter.html – Karussell Jun 27 '11 at 21:34
  • @raagavan if you need allways all documents (why would you??) consider scan search: http://www.elasticsearch.org/blog/2011/03/24/new-search-types.html – Karussell Jun 27 '11 at 21:36
  • what's the max accepted value for size? can't find it in the docs and the c# int.MaxValue fails with brio. – lnaie Dec 12 '14 at 15:15
4

If you use the JAVA API you can simple get the total hit number from the SearchResponse

SearchRequestBuilder srb = ..
SearchResponse sr = srb.execute().actionGet();
long totalHits = sr.getHits().getTotalHits();
matthias
  • 711
  • 4
  • 15
0

You can do this in couple of steps using some code

  1. Fix a size say 1000 and get all 1000 records.
  2. Identify from hits.total whether size is smaller than 1000. (if small then you got all the records :) )
  3. Otherwise use from and size to provide 1001 in from and total as size from previous query to get full result.
AabinGunz
  • 12,109
  • 54
  • 146
  • 218