Search code examples
rubyelasticsearchsearchkick

Passing `limit` `offset` options to searchkick advanced search body object


I am trying to do an Advanced search with SearchKick on Ruby like the following:

Product.search(body: search_body, load: false)

def search_body
  {
    _source: true,
    query: {
      bool: {
        must: [
          {
            match: {
              name: {
                query: product.name,
                fuzziness: 'auto',
                operator: 'and',
              },
            },
          },
        ],
      },
    },
  }
end

I am now trying to pass limit: 10, offset: 15 options to my search. Where or how do i pass the limit: 10, offset: 15 options?

The examples given here are with the query: option - but using the body: option behaves differently as it disregards any other option i pass to .search().


Solution

  • You'll need to use the Elasticsearch docs for advanced search.

    def search_body
      {
        size: 10,
        from: 15,
        query: { ... }
      }
    end