Oto mój docker-compose.yml
Nie można połączyć się Elasticsearch PHP wewnątrz Döcker
nginx:
build: ./nginx/
ports:
- 80:80
links:
- php
volumes_from:
- app
php:
image: php:7.0-fpm
expose:
- 9000
volumes_from:
- app
links:
- elastic
app:
image: php:7.0-fpm
volumes:
- .:/var/www/html
command: "true"
elastic:
image: elasticsearch:2.3
volumes:
- ./elasticsearch/data:/usr/share/elasticsearch/data
- ./elasticsearch/logs:/usr/share/elasticsearch/logs
expose:
- "9200"
ports:
- "9200:9200"
Kiedy próbuję uzyskać dostęp Elasticsearch przechodząc do localhost:9200
to działa.
Ale gdy próbuję utworzyć indeks za pomocą PHP pojawia się następujący błąd:
Fatal error: Uncaught Elasticsearch\Common\Exceptions\NoNodesAvailableException: No alive nodes found in your cluster in
Oto kod klienta:
<?php
namespace App\Elasticsearch;
use Elasticsearch\ClientBuilder;
class Client
{
public static function getClient()
{
return ClientBuilder::create()
->build();
}
}
Kod instancję obiektu Elasticsearch:
<?php
require 'vendor/autoload.php';
use App\Elasticsearch\Client;
use App\Elasticsearch\Indices\UserIndex;
$es = Client::getClient();
Jeśli I var_dump($es)
, zrzuca obiekt klienta Elasticsearch.
Ale kiedy próbuję utworzyć indeks, generuje błąd.
<?php
namespace App\Elasticsearch\Indices;
use App\Elasticsearch\Indices\AbstractIndex;
use Elasticsearch\Client;
class UserIndex extends AbstractIndex
{
public function __construct(Client $client)
{
$this->client = $client;
}
}
// Create User Index
$userIndex = new UserIndex($es);
var_dump($userIndex->createIndex('users'));
Aktualizacja
Od enter link description here
tej stronie. Próbowałem
$es = Client::getClient();
try {
// Create User Index
$userIndex = new UserIndex($es);
var_dump($userIndex->createIndex('users'));
} catch (Exception $e) {
var_dump($es->transport->getLastConnection()->getLastRequestInfo());
}
a teraz pokazuje mi błąd Curl tj
["curl"] array(2) { ["error"] "Failed to connect to localhost port 9200: Connection refused" ["errno"] 7
Wygląda na numerze portu rzeczywiście (trochę jak w https://github.com/elastic/elasticsearch-php/issues/408#issuecomment -207045443) – VonC
Również trochę jak https://github.com/elastic/elasticsearch-php/issues/425#issuecomment-231548912 – VonC
jak uzyskać dostęp do elastycznego z php? – opHASnoNAME