Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect return typehint when using async requests / futures #902

Closed
crispygoth opened this issue Jun 25, 2019 · 1 comment · Fixed by #905
Closed

Incorrect return typehint when using async requests / futures #902

crispygoth opened this issue Jun 25, 2019 · 1 comment · Fixed by #905
Assignees
Labels
Milestone

Comments

@crispygoth
Copy link

Summary of problem or feature request

The return typehint on Elasticsearch\Client::performRequest() is incorrect for async requests as these return a FutureArrayInterface

Code snippet of problem

In the below code $aAddressBatch is an array of 100 documents to send to ES for indexing:

$oESClientBuilder = Elasticsearch\ClientBuilder::create();
$oESClientBuilder->setHosts(['192.168.0.114', '192.168.0.115']);

$oDefaultHandler = Elasticsearch\ClientBuilder::defaultHandler(['max_handles' => 5]);
$oESClientBuilder->setHandler($oDefaultHandler);
        
$oESClient = $oESClientBuilder->build();

$aESBody = [];
foreach ($aAddressBatch as $aAddress)
{
    $aESBody[] = [
        'index' => [
            '_index' => $this->sIndexName,
        ]
    ];
    $aESBody[] = $aAddress;
}

$aParams = [
    'client' => [
        'future' => 'lazy',
    ],
    'body' => $aESBody
];

$aResponse =  $oESClient->bulk($aParams),

Exception details

Exception thrown: TypeError: Return value of Elasticsearch\Client::performRequest() must be of the type array, object returned

Backtrace:

  • Elasticsearch\Client->performRequest (…/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Client.php:742)
    array(1)
    0: object: Elasticsearch\Endpoints\Bulk

  • Elasticsearch\Client->bulk

System details

  • Operating System: Debian 8 (jessie)
  • PHP Version: 7.1 (from packages.sury.org)
  • ES-PHP client version: 7.0.1
  • Elasticsearch version: 7.1.1
@ezimuel
Copy link
Contributor

ezimuel commented Jun 28, 2019

Thanks @crispygoth for reporting the issue. I've created PR #905 for fixing the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants