opensearch-project / opensearch-php

Official PHP Client for OpenSearch
Other
91 stars 54 forks source link

[BUG] Scrolling triggers deprecation error #163

Open magikid opened 11 months ago

magikid commented 11 months ago

What is the bug?

When using a OpenSearch\Helper\Iterators\SearchResponseIterator, the deprecation error 'A scroll id can be quite large and should be specified as part of the body' is thrown.

How can one reproduce the bug?

$iterator = new SearchResponseIterator($client, $parameters);
foreach ($pageIterator as $page) {
    echo 'Error occurs here';
}

What is the expected behavior?

I would expect the iterator to use the scroll API properly without throwing a deprecation.

What is your host/environment?

Debian GNU/Linux 11 (bullseye)

Do you have any screenshots?

Nope

Do you have any additional context?

None that I can think of but I'm happy to answer questions about this.

imdhemy commented 3 months ago

Hi 👋

I tried the following code with PHPUnit and it passed:

Item Version
OpenSearch v2
PHP v8.3
opensearch-php main
public function integration_test(): void
    {
        $client = ClientBuilder::create()
            ->setHosts([Utility::getHost()])
            ->setLogger(new ArrayLogger())
            ->setSSLVerification(false)->build();

        // unique index name
        $index = "test_index_".time();

        // populate index with 100 documents
        for ($i = 0; $i < 100; $i++) {
            $client->index(
                [
                    'index' => $index,
                    'body' => [
                        'test_field' => 'test_value'
                    ]
                ]
            );
        }

        // refresh the index for testing
        $client->indices()->refresh(['index' => $index]);

        // test the iterator
        $search_params = [
            'scroll'      => '5m',
            'index'       => $index,
            'size'        => 10,
            'body'        => [
                'query' => [
                    'match_all' => new stdClass()
                ]
            ]
        ];
        $pages = new SearchResponseIterator($client, $search_params);
        $count = 0;

        // iterate over the pages and count the documents
        foreach ($pages as $page) {
            $count += count($page['hits']['hits']);
            $documents = $page['hits']['hits'];
            foreach ($documents as $document) {
                // check if the document is accessible
                $this->assertEquals('test_value', $document['_source']['test_field']);
            }
        }

        $this->assertEquals(100, $count);
    }

I'm willing to fix this bug if it exists. Did I miss something?