Skip to content

Error: Cannot use object of type Elasticsearch\Common\Exceptions\Missing404Exception as array #831

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

Closed
yochanan-gurovich opened this issue Jan 13, 2019 · 9 comments

Comments

@yochanan-gurovich
Copy link

yochanan-gurovich commented Jan 13, 2019

Trying to get a document by an ID that does not exist.
Code is in a try / catch block, and is caught.
The above error is thrown still.

Code snippet (username, password and host are masked):

        try {
            $hosts = [
                'https://username:password@host:port'
            ];
            $client = Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();
            $params = [
                'index' => 'products',
                'type' => 'default',
                'id' => 'non_existant_id'
            ];
            $response = $client->get($params);
            var_dump($response);
        } catch (\Exception $e) {
            echo $e->getMessage();
        }
  • Operating System: Ubuntu 18.04
  • PHP Version: 7.2
  • ES-PHP client version: 6.1.0
  • Elasticsearch version: 6.5.4 (Elastic Cloud)
@polyfractal
Copy link
Contributor

Can you paste the full exception stack, so I can see where it's originating from?

@yochanan-gurovich
Copy link
Author

yochanan-gurovich commented Jan 15, 2019

#0 /home/forge/6day.store/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(279): Elasticsearch\Connections\Connection->process4xxError(Array, Array, Array)
#1 /home/forge/6day.store/vendor/react/promise/src/FulfilledPromise.php(25): Elasticsearch\Connections\Connection->Elasticsearch\Connections\{closure}(Array)
#2 /home/forge/6day.store/vendor/guzzlehttp/ringphp/src/Future/CompletedFutureValue.php(55): React\Promise\FulfilledPromise->then(Object(Closure), NULL, NULL)
#3 /home/forge/6day.store/vendor/guzzlehttp/ringphp/src/Core.php(341): GuzzleHttp\Ring\Future\CompletedFutureValue->then(Object(Closure), NULL, NULL)
#4 /home/forge/6day.store/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(299): GuzzleHttp\Ring\Core::proxy(Object(GuzzleHttp\Ring\Future\CompletedFutureArray), Object(Closure))
#5 /home/forge/6day.store/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(177): Elasticsearch\Connections\Connection->Elasticsearch\Connections\{closure}(Array, Object(Elasticsearch\Connections\Connection), Object(Elasticsearch\Transport), Array)
#6 /home/forge/6day.store/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Transport.php(110): Elasticsearch\Connections\Connection->performRequest('GET', '/products/defau...', Array, NULL, Array, Object(Elasticsearch\Transport))
#7 /home/forge/6day.store/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Client.php(1553): Elasticsearch\Transport->performRequest('GET', '/products/defau...', Array, NULL, Array)
#8 /home/forge/6day.store/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Client.php(191): Elasticsearch\Client->performRequest(Object(Elasticsearch\Endpoints\Get))
#9 /home/forge/6day.store/app/routes/web.php(188): Elasticsearch\Client->get(Array)
#10 [internal function]: Closure->{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#11 /home/forge/6day.store/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(41): call_user_func(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#12 /home/forge/6day.store/vendor/slim/slim/Slim/Route.php(356): Slim\Handlers\Strategies\RequestResponse->__invoke(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#13 /home/forge/6day.store/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(117): Slim\Route->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#14 /home/forge/6day.store/vendor/slim/slim/Slim/Route.php(334): Slim\Route->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#15 /home/forge/6day.store/vendor/slim/slim/Slim/App.php(515): Slim\Route->run(Object(Slim\Http\Request), Object(Slim\Http\Response))
#16 /home/forge/6day.store/app/src/Middleware/SetAppData.php(110): Slim\App->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#17 [internal function]: App\Middleware\SetAppData->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\App))
#18 /home/forge/6day.store/vendor/slim/slim/Slim/DeferredCallable.php(43): call_user_func_array(Object(App\Middleware\SetAppData), Array)
#19 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\App))
#20 /home/forge/6day.store/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\App))
#21 /home/forge/6day.store/vendor/akrabat/ip-address-middleware/src/IpAddress.php(113): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response))
#22 [internal function]: RKA\Middleware\IpAddress->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#23 /home/forge/6day.store/vendor/slim/slim/Slim/DeferredCallable.php(43): call_user_func_array(Object(RKA\Middleware\IpAddress), Array)
#24 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#25 /home/forge/6day.store/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#26 /home/forge/6day.store/vendor/slim/csrf/src/Guard.php(171): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response))
#27 [internal function]: Slim\Csrf\Guard->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#28 /home/forge/6day.store/vendor/slim/slim/Slim/DeferredCallable.php(43): call_user_func_array(Object(Slim\Csrf\Guard), Array)
#29 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#30 /home/forge/6day.store/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#31 /home/forge/6day.store/app/middleware.php(33): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response))
#32 [internal function]: Closure->{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#33 /home/forge/6day.store/vendor/slim/slim/Slim/DeferredCallable.php(43): call_user_func_array(Object(Closure), Array)
#34 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#35 /home/forge/6day.store/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#36 /home/forge/6day.store/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(117): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response))
#37 /home/forge/6day.store/vendor/slim/slim/Slim/App.php(406): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#38 /home/forge/6day.store/vendor/slim/slim/Slim/App.php(314): Slim\App->process(Object(Slim\Http\Request), Object(Slim\Http\Response))
#39 /home/forge/6day.store/public/index.php(16): Slim\App->run()
#40 {main}

@hazrat84
Copy link

I am also facing this type of issue.
Error: Cannot use object of type Elasticsearch\Common\Exceptions\Missing404Exception as array in
/var/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Transport.php
on line 122

Please any help?

@ERajkumar
Copy link

I hope , This will helps, @hazrat84 and @yochanan-gurovich

I find out temporary solution, go to this file vendor/elasticsearch/elasticsearch/src/Elasticsearch/Transport.php line Number 122
Change Convert response object to arrays $response = (array)$response;

   function ($response) {
	      $response = (array)$response;
	        // Ignore 400 level errors, as that means the server responded just fine
	        if (!(isset($response['code']) && $response['code'] >=400 && $response['code'] < 500)) {
	            // Otherwise schedule a check
	            $this->connectionPool->scheduleCheck();
	        }
	    }

@Thomblin
Copy link

Thomblin commented Mar 4, 2019

I have the same problem here, is a patch available?

@ezimuel
Copy link
Contributor

ezimuel commented Aug 13, 2019

@yochanan-gurovich, @Thomblin, @ERajkumar, @hazrat84 I just tested the following code with PHP 7.2.17, elasticsearch-php 6.1.0 and Elastic Cloud 6.5.4 and works just fine.

require 'vendor/autoload.php';

use Elasticsearch\ClientBuilder;

try {
    $hosts = [
        'https://elastic:password@xxx.europe-west1.gcp.cloud.es.io:9243'
    ];
    $client = ClientBuilder::create()->setHosts($hosts)->build();
    $params = [
        'index' => 'products',
        'type' => 'default',
        'id' => 'non_existant_id'
    ];
    $response = $client->get($params);
    var_dump($response);
} catch (\Exception $e) {
    echo $e->getMessage(); 
}

I have this message output from the catch:

{
  "error": {
    "root_cause": [
      {
        "type": "index_not_found_exception",
        "reason": "no such index",
        "resource.type": "index_expression",
        "resource.id": "products",
        "index_uuid": "_na_",
        "index": "products"
      }
    ],
    "type": "index_not_found_exception",
    "reason": "no such index",
    "resource.type": "index_expression",
    "resource.id": "products",
    "index_uuid": "_na_",
    "index": "products"
  },
  "status": 404
}

Can you try on your side and let me know? Thanks!

@ezimuel
Copy link
Contributor

ezimuel commented Sep 3, 2019

Closing due to inactivity. I'll reopen it if needed

@ezimuel ezimuel closed this as completed Sep 3, 2019
@StasToken
Copy link

It seems the bug is not fixed

"elasticsearch/elasticsearch": "^7.2"

Elasticsearch\Common\Exceptions\Missing404Exception - {"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index [xml_fullnames]","resource.type":"index_or_alias","resource.id":"xml_fullnames","index_uuid":"na","index":"xml_fullnames"}],"type":"index_not_found_exception","reason":"no such index [xml_fullnames]","resource.type":"index_or_alias","resource.id":"xml_fullnames","index_uuid":"na","index":"xml_fullnames"},"status":404}

I also ran into this error today

@emaillenin
Copy link

emaillenin commented Aug 15, 2020

I'm facing this error after upgrading to 7.8 from 5.6:

Error: Cannot use object of type Elasticsearch\Common\Exceptions\Missing404Exception as array in /var/www/development/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Transport.php on line 122

Call Stack:
    0.0001     387936   1. {main}() /var/www/development/bin/cake.php:0
    0.1159    3072320   2. Cake\Console\CommandRunner->run() /var/www/development/bin/cake.php:12
    0.2652    8891792   3. Cake\Console\CommandRunner->runShell() /var/www/development/vendor/cakephp/cakephp/src/Console/CommandRunner.php:168
    0.2652    8891792   4. App\Shell\SeedShell->runCommand() /var/www/development/vendor/cakephp/cakephp/src/Console/CommandRunner.php:354
    0.2709    9122832   5. App\Shell\SeedShell->seedElasticsearchData() /var/www/development/vendor/cakephp/cakephp/src/Console/Shell.php:496
    0.5576   13951328   6. App\Shell\SeedShell->recreateIndex() /var/www/development/src/Shell/SeedShell.php:42
    2.6267   16827400   7. App\Shell\Helper\ElasticSearchIngestionHelper->createIndexIfRequired() /var/www/development/src/Shell/SeedShell.php:60
    2.6267   16827400   8. App\Service\ElasticSearchClient->createIndex() /var/www/development/src/Shell/Helper/ElasticSearchIngestionHelper.php:151
    2.6267   16827776   9. App\Service\ElasticSearchClient->indexExists() /var/www/development/src/Service/ElasticSearchClient.php:65
    2.6267   16828152  10. Elasticsearch\Namespaces\IndicesNamespace->exists() /var/www/development/src/Service/ElasticSearchClient.php:312
    2.6267   16829240  11. Elasticsearch\Namespaces\BooleanRequestWrapper::performRequest() /var/www/development/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Namespaces/IndicesNamespace.php:302
    2.6267   16829304  12. Elasticsearch\Transport->performRequest() /var/www/development/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Namespaces/BooleanRequestWrapper.php:38
    2.6309   16860096  13. React\Promise\RejectedPromise->then() /var/www/development/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Transport.php:126
    2.6309   16860096  14. Elasticsearch\Transport->Elasticsearch\{closure}() /var/www/development/vendor/react/promise/src/RejectedPromise.php:28
Operating System: Ubuntu 18.04
PHP Version: 7.2
ES-PHP client version: v7.8.0
Elasticsearch version: 7.8.1

Temporarily fixed using this patch:

//onFailure
function ($response) {
    // Ignore 400 level errors, as that means the server responded just fine
    if ($response instanceof Exceptions\Missing404Exception) {
        if ($response->getCode() >= 400 && $response->getCode() < 500) {
            // Otherwise schedule a check
            $this->connectionPool->scheduleCheck();
        }
    } else {
        if (!(isset($response['code']) && $response['code'] >= 400 && $response['code'] < 500)) {
            // Otherwise schedule a check
            $this->connectionPool->scheduleCheck();
        }
    }
}

Looks like this is a regression of #676.

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

Successfully merging a pull request may close this issue.

8 participants