Sergey Karp
Sergey Karp

Reputation: 31

ElasticSearch and Laravel can't be friends(Error: No alive nodes found in your cluster )

I have a Docker container with ElasticSearch and when I go to localhost: 9200 I see the following

{
  "name" : "16ea4fe71ce8",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "_na_",
  "version" : {
    "number" : "7.0.1",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "e4efcb5",
    "build_date" : "2019-04-29T12:56:03.145736Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.7.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

Ok, i think my elastic container is working. Next, I install these 2 packages https://github.com/elastic/elasticsearch-php https://github.com/cviebrock/laravel-elasticsearch

In the .env file, I set the environment variables

ELASTICSEARCH_HOST=localhost
ELASTICSEARCH_PORT=9200
ELASTICSEARCH_SCHEME=http
ELASTICSEARCH_USER=
ELASTICSEARCH_PASS=

And I write a simple method to check what I did there

public function esSearch() {
    $data = [
        'body' => [
            'testField' => 'abc'
        ],
        'index' => 'my_index',
        'type' => 'my_type',
        'id' => 'my_id',
    ];

    $client = ClientBuilder::create()->build();
    $return = $client->index($data);
    dd($return);
}

As a result, I get the error No alive nodes found in your cluster

Please tell me how to make friends ElasticSearch and Laravel 8? I tried to use different packages from GitHub, but most of them do not support Laravel 8. Maybe there are some guides on how to work with ES and Laravel?

Upvotes: 1

Views: 1174

Answers (1)

Amit
Amit

Reputation: 32376

This issue is due to running docker containers, which have their own networs. Localhost would not work and instead you should create a network which both the conatiner should use, that way lavarel container would be able to connect to ES conatiner.

Upvotes: 2

Related Questions