Gogo
Gogo

Reputation: 603

Setting size parameter ES laravel

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?

Upvotes: 0

Views: 361

Answers (1)

Val
Val

Reputation: 217544

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

Upvotes: 2

Related Questions