Skip to content

Incorrect return typehint when using async requests / futures #902

@crispygoth

Description

@crispygoth

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions