API Reference / API Parameters / length
Type: integer
Engine default: null (no offset)
Parameter syntax
'length' => number_of_records

Can be used in these methods:

About this parameter

Set the number of hits to retrieve (used only with offset).

In most cases, page and hitsPerPage is the recommended method for pagination. This setting is part of an alternative paging approach.

Usage notes

  • 1000 is the maximum.
  • If offset is omitted, length is ignored.
  • If offset is specified but length omitted, the number of records returned is equal to hitsPerPage. Using offset requires that you specify length as well; otherwise, it defaults to page-based pagination.

Impact on the response:

  • Page-based pagination (page and hitsPerPage):

    1
    2
    3
    4
    5
    6
    7
    
    {
      ...
      "page": 1,
      "nbPages": 20,
      "hitsPerPage": 10,
      ...
    }
    
  • With offset / length:

    1
    2
    3
    4
    5
    6
    
     {
       ...
       "offset": 5,
       "length": 10,
       ...
     }
    

Examples

Get n results

1
2
3
$results = $index->search('query', [
  'length' => 4
]);
Did you find this page helpful?