PHPackages                             nekman/es-pagination - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. nekman/es-pagination

AbandonedArchivedLibrary[Search &amp; Filtering](/categories/search)

nekman/es-pagination
====================

Deep pagination for the Elasticsearch client

2.0.0(3y ago)12.6kMITPHPPHP ^7.4||^8.0

Since Nov 5Pushed 3y agoCompare

[ Source](https://github.com/Ekman/es-pagination)[ Packagist](https://packagist.org/packages/nekman/es-pagination)[ RSS](/packages/nekman-es-pagination/feed)WikiDiscussions master Synced today

READMEChangelog (8)Dependencies (4)Versions (12)Used By (0)

Elasticsearch pagination
========================

[](#elasticsearch-pagination)

[![Build Status](https://camo.githubusercontent.com/e42e326be7d1f3c896b1e5391a393f38add6a5abe68f75f84e9825e14235f790/68747470733a2f2f636972636c6563692e636f6d2f67682f456b6d616e2f65732d706167696e6174696f6e2e7376673f7374796c653d737667)](https://app.circleci.com/pipelines/github/Ekman/es-pagination)[![Coverage Status](https://camo.githubusercontent.com/074a900f25f13d540fd35da4cb272bee0b52088518e31ac15deb7e42097c2d1c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f456b6d616e2f65732d706167696e6174696f6e2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Ekman/es-pagination?branch=master)

A library to deep paginate an Elasticsearch search operation. There are [three ways to paginate](https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html):

1. [Scroll](#scroll)
2. [From](#from)
3. [Search after](#search-after)

Which one to use depends on the context, [read more in the Elasticsearch documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html).

The library will get `pageSize` amount of hits in memory at the same time, which means a lower amount will result in less memory used but more requests to Elasticsearch (and the opposite). Never will it fully exhaust an index before returning the results.

Usage
-----

[](#usage)

The first step is to construct an `$elasticsearchClient` (instance of `Elasticsearch\Client`) which you can read more about in the [Elasticsearch official PHP driver](https://github.com/elastic/elasticsearch-php).

### Scroll

[](#scroll)

```
use Nekman\EsPagination\CursorFactories\EsScrollCursorFactory;

$cursorFactory = new EsScrollCursorFactory(
    $elasticsearchClient,
    $pageSize = 1000,
    $scrollDuration = "1m"
);

$params = [
    /*
     * Same params as a normal Elasticsearch search operation.
     * See Elasticsearch documentation for more information.
     */
];

$cursor = $cursorFactory->hits($params);

foreach ($cursor as $hit) {
    echo "Hit {$hit['_id']}";
}
```

### From

[](#from)

```
use Nekman\EsPagination\CursorFactories\EsFromCursorFactory;

$cursorFactory = new EsFromCursorFactory(
    $elasticsearchClient,
    $pageSize = 1000
);

$params = [
    /*
     * Same params as a normal Elasticsearch search operation.
     * See Elasticsearch documentation for more information.
     */
];

$cursor = $cursorFactory->hits($params);

foreach ($cursor as $hit) {
    echo "Hit {$hit['_id']}";
}
```

### Search after

[](#search-after)

```
use Nekman\EsPagination\CursorFactories\EsSearchAfterCursorFactory;

$cursorFactory = new EsSearchAfterCursorFactory(
    $elasticsearchClient,
    $pageSize = 1000
);

$params = [
    /*
     * Same params as a normal Elasticsearch search operation.
     * See Elasticsearch documentation for more information.
     */
];

$cursor = $cursorFactory->hits($params);

foreach ($cursor as $hit) {
    echo "Hit {$hit['_id']}";
}
```

### Point in time (PIT)

[](#point-in-time-pit)

Elasticsearch pit (point in time) is a lightweight view into the state of the data as it existed when initiated. Create a cursor factory and decorate it with PIT:

```
use \Nekman\EsPagination\CursorFactories\EsPitCursorFactory;

$cursorFactory = /* Create cursor factory, see above */;

$pitCursorFactory = new EsPitCursorFactory(
	$cursorFactory,
	$elasticsearchFactory,
	$pitKeepAlive = "1m"
);

$params = [
    /*
     * Same params as a normal Elasticsearch search operation.
     * See Elasticsearch documentation for more information.
     */
];

$cursor = $cursorFactory->hits($params);

foreach ($cursor as $hit) {
    echo "Hit {$hit['_id']}";
}
```

Versioning
----------

[](#versioning)

This project complies with [Semantic Versioning](https://semver.org/).

Changelog
---------

[](#changelog)

For a complete list of changes, and how to migrate between major versions, see [releases page](https://github.com/Ekman/es-pagination/releases).

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity65

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~58 days

Recently: every ~134 days

Total

11

Last Release

1430d ago

Major Versions

0.0.5 → 1.0.02020-12-17

1.1.1 → 2.0.02022-06-09

PHP version history (2 changes)0.0.1PHP ^7.4

1.0.1PHP ^7.4||^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/568019?v=4)[Nils](/maintainers/NEkman)[@nekman](https://github.com/nekman)

---

Tags

cursorcursor-paginationcursorselasticsearchpaginate

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/nekman-es-pagination/health.svg)

```
[![Health](https://phpackages.com/badges/nekman-es-pagination/health.svg)](https://phpackages.com/packages/nekman-es-pagination)
```

###  Alternatives

[ruflin/elastica

Elasticsearch Client

2.3k50.4M202](/packages/ruflin-elastica)[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[ongr/elasticsearch-dsl

Elasticsearch DSL library

46411.9M46](/packages/ongr-elasticsearch-dsl)[matchish/laravel-scout-elasticsearch

Search among multiple models with ElasticSearch and Laravel Scout

7431.6M2](/packages/matchish-laravel-scout-elasticsearch)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[ongr/elasticsearch-bundle

Elasticsearch bundle for Symfony.

3151.1M15](/packages/ongr-elasticsearch-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
