Search code examples
ruby-on-railselasticsearchchewy-gem

Getting more than 10 results with Chewy Gem - ElasticSearch & Rails


With chewy gem, if I run:

MyIndex.filter{attribute1?}.count

It will always return 10 occurences.

I know this is an ElasticSearch default and I have read this question, which says I should set the param size on the URL to a big number, to get all occurrences.

The problem is that I can't seem to find where to set URL params for a request to the elasticSearch server on chewy gem, so that it would do a get request like this one, internally:

localhost:9200/foo/_search?size=500000...

UPDATE:

Well... Minutes after I've posted my question, I seem to have found a solution. If I use the limit function like this:

MyIndex.filter{attribute1?}.limit(100000000).count

I seem to get the number of occurences I was expecting. Now I ask, is it the right way?


Solution

  • You can confirm the default limit and find more information by referring to the docs on Elasticsearch's from and size params.

    If you are wondering whether there is a way to retrieve all results matching a particular query without specifying an arbitrary large constant, I do not think there is.

    Looking at the chewy gem's github repo and the examples they have in the README, using .limit(s) and .offset(f) is the correct way of getting the from and size params in the actual Elasticsearch request that chewy will ultimately make.