raagavan
raagavan

Reputation: 981

How to get all the values from an search result

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??

Upvotes: 9

Views: 13199

Answers (3)

AabinGunz
AabinGunz

Reputation: 12347

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.

Upvotes: 0

matthias
matthias

Reputation: 721

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();

Upvotes: 4

skaffman
skaffman

Reputation: 403451

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.

Upvotes: 16

Related Questions