Php client can't connect to different port localhost


(Roman Taranenko) #1

I've installed last ElasticSearch version (2.2.0) to my vagrant, ant forwarded ports like 62000 host goes to 9200 guest, and everything works fine, localhost:62000 on my host machine returns me default information about ES, after setting CORS to enabled and node set as master, even my ElasticHQ now easily connects to it, but. But Elastic'a throws exception Couldn't connect to host, Elasticsearch down?

My test php code is:

$client = new Client([
    'host' => 'localhost',
    'port' => 62000
]);
$index = $client->getIndex('test');
$index->create(array(), true);
$type = $index->getType('test');
$type->addDocument(new Document(1, array('username' => 'ruflin')));
$index->refresh();

$query = array(
    'query' => array(
        'query_string' => array(
            'query' => 'ruflin',
        )
    )
);

$path = $index->getName() . '/' . $type->getName() . '/_search';

$response = $client->request($path, Request::GET, $query);
$responseArray = $response->getData();

I've also tried 127.0.0.1 instead of localhost, but no luck.

Update

Tried native elasticsearch php client as:

$hosts = [
    'http://127.0.0.1:62000',
];
$client = Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();
$client->search([]);

Getting Uncaught Elasticsearch\Common\Exceptions\NoNodesAvailableException: No alive nodes found in your cluster

elasticsearch.yml edits:

node.master: true
network.host: _non_loopback_
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"

What am i doing wrong?


(Roman Taranenko) #2

If i change

network.host: _non_loopback_

to

network.host: 127.0.0.1

i can connect to ES like this

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

but cannot reach it via 62000 port


(system) #3