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?