API Reference / API Parameters / offset
Jan. 14, 2019
Type: integer
Engine default: null (no offset)
Parameter syntax
'offset' => record_number

Can be used in these methods:

About this parameter

Specify the offset of the first hit to return.

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

Offset is the position in the dataset of a particular record. By specifying offset, you retrieve a subset of records starting with the offset value. Offset normally works with length, which determines how many records to retrieve starting from the offset.

Usage notes:

  • Offset is zero-based: the 10th record is at offset 9.

  • If you omit length, the number of records returned is equal to the hitsPerPage. In fact, using offset requires that you specify length as well; otherwise, it defaults to page-based pagination.

  • If offset is specified, page is ignored.

  • Usage: If you have 100 records in your result set, and you want to retrieve records 50 to 80, you will need to use offset=49 and length = 30.

Impact on the response:

  • Page-based pagination (page / 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 results starting at the nth hit

1
2
3
$results = $index->search('query', [
  'offset' => 4
]);

Did you find this page helpful?