Setting size parameter ES laravel

- 1 answer

Ad

I have a simple part of code in laravel Elasticquent:

    $laws = Law::searchByQuery([
        'multi_match' => [
            'query' => Input::get('query', ''),
            'fields' => [ "law_name", "law_year", "law_raw_content"],
        ],
    ]);

I want to set a size parameter. I tried:

    $laws = Law::searchByQuery([
        'multi_match' => [
            'query' => Input::get('query', ''),
            'fields' => [ "law_name", "law_year", "law_raw_content"],
            'size' => 100,
        ],
    ]);

But no luck. Can anyone help?

Ad

Answer

Ad

From the Elasticquent documentation, the searchByQuery function takes the following parameters (see source here):

  • query - Your ElasticSearch Query
  • aggregations - The Aggregations you wish to return.
  • sourceFields - Limits returned set to the selected fields only
  • limit - Number of records to return
  • offset - Sets the record offset (use for paging results)
  • sort - Your sort query

In your call, you simply need to include the $limit parameter (fourth parameter) in addition to your query (first parameter). Do it like this instead:

$laws = Law::searchByQuery([
    'multi_match' => [
        'query' => Input::get('query', ''),
        'fields' => [ "law_name", "law_year", "law_raw_content"]
    ],
], null, null, 100);
                ^
                |
        add the size here
Ad
source: stackoverflow.com
Ad