• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Ekman / es-pagination / 3d30d0e2-2ab7-43eb-898f-16cee41c973d

pending completion
3d30d0e2-2ab7-43eb-898f-16cee41c973d

push

circleci

GitHub
Test PHP 8.2

19 of 103 relevant lines covered (18.45%)

0.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/CursorFactories/EsScrollCursorFactory.php
1
<?php
2

3
namespace Nekman\EsPagination\CursorFactories;
4

5
use Elasticsearch\Client;
6
use Nekman\EsPagination\EsUtility;
7

8
/**
9
 * Deep paginate an ES search by using scroll
10
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#scroll-search-results
11
 */
12
final class EsScrollCursorFactory extends BaseCursorFactory
13
{
14
    private Client $client;
15
    private int $pageSize;
16
    private string $scrollDuration;
17

18
    public function __construct(
19
        Client $client,
20
        int $pageSize = EsUtility::DEFAULT_PAGE_SIZE,
×
21
        string $scrollDuration = "1m"
22
    ) {
23
        $this->client = $client;
×
24
        $this->pageSize = $pageSize;
×
25
        $this->scrollDuration = $scrollDuration;
×
26
    }
27

28
    public function responses(array $params = []): iterable
29
    {
30
        $params = array_merge($params, [
×
31
            "scroll" => $params["scroll"] ?? $this->scrollDuration,
×
32
            "size" => $params["size"] ?? $this->pageSize,
×
33
        ]);
×
34

35
        yield $response = $this->client->search($params);
×
36
        $scrollId = $response["_scroll_id"];
×
37

38
        try {
39
            while (EsUtility::countHits($response) >= $params["size"]) {
×
40
                yield $response = $this->client->scroll([
×
41
                    "scroll" => $params["scroll"] ?? $this->scrollDuration,
×
42
                    "body" => [
×
43
                        "scroll_id" => $scrollId,
×
44
                    ],
×
45
                ]);
×
46
            }
47
        } finally {
48
            @$this->client->clearScroll([
×
49
                "body" => [
×
50
                    "scroll_id" => $scrollId,
×
51
                ]
×
52
            ]);
×
53
        }
54
    }
55
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc