Skip to content

Commit

Permalink
Add support for query parameter search_after to paginate over large…
Browse files Browse the repository at this point in the history
… datasets
  • Loading branch information
lubosdz committed Oct 25, 2024
1 parent 498a28d commit d16b78e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Yii Framework 2 Elasticsearch extension Change Log

- Bug #344: Disabled JSON pretty print for ElasticSearch bulk API (rhertogh)
- Bug #350: Remove deprecated code, set $pagination->totalCount (lav45)
- Bug #352: Add support for query parameter `search_after` to paginate over large datasets (lubosdz)


2.1.4 May 22, 2023
Expand Down
6 changes: 6 additions & 0 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ class Query extends Component implements QueryInterface
* @since 2.0.5
*/
public $explain;
/**
* @var array Allows pagination on larget datasets.
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after
* @since 2.1.5
*/
public $search_after = [];


/**
Expand Down
3 changes: 3 additions & 0 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public function build($query)
if (!empty($query->collapse)) {
$parts['collapse'] = $query->collapse;
}
if ($query->search_after) {
$parts['search_after'] = $query->search_after;
}

$sort = $this->buildOrderBy($query->orderBy);
if (!empty($sort)) {
Expand Down

0 comments on commit d16b78e

Please sign in to comment.