'No alive nodes. All the 1 nodes seem to be down

I am trying to use Elasticsearch 8.1 using laravel. My elasticsearch instance is running at port 9200. https://localhost:9200 returns me

{
  "name" : "node-1",
  "cluster_name" : "my-application",
  "cluster_uuid" : "7wIGGqhBS5OXfV0E4J53GQ",
  "version" : {
    "number" : "8.0.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "801d9ccc7c2ee0f2cb121bbe22ab5af77a902372",
    "build_date" : "2022-02-24T13:55:40.601285296Z",
    "build_snapshot" : false,
    "lucene_version" : "9.0.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

Inside Laravel, I have following lines of code.

$hosts = [
    'http://127.0.0.1:9200',
];
$client = ClientBuilder::create()
    ->setSSLVerification(false)
    ->setHosts($hosts)
    ->build();

$params = [
    'index' => 'sample_index',
    'id' => 'sample_id',
    'body' => [
        'name' => 'Sample Product',
        'description' => 'My description...',
        'price' => '3400',
        'stock' => '150',
    ]
];
$response = $client->index($params);
dump($response);

The $response I get is No alive nodes. All the 1 nodes seem to be down. From the dump command above this is request made which is not requesting 9200 (not sure if this is correct or not).

Request made to elastic



Solution 1:[1]

I had the same problem. Everything worked fine from python but it always gave this error from the php code. Then google around let me to following article where a person had similar problem

https://github.com/elastic/elasticsearch-php/issues/1120

And the helper finally pointed him that your httpd need to be allowed to connect to the network and following solution page was referenced:

CURL permission denied via browser, works on ssh

The solution mentioned was to add following line in the php.ini file

setsebool -P httpd_can_network_connect 1

However, for me it worked when I executed this command with sudo on the command line.

Hope it works for you as well

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Qadeer