Elasticsearch-PHP出现No alive nodes found in your cluster in
<?php
namespace App\Http\Controllers\Home;
use App\Http\Controllers\Controller;
use Elasticsearch\ClientBuilder;
class HomeController extends Controller {
public $client = null;
public function __construct() {
$this-> client = ClientBuilder::create()->build();
}
//创建
public function index(){
$params = [
'index' => 'my_index',
'type' => 'my_type',
'id' => 'my_id',
'body' => ['testField' => 'abc']
];
$response = $this->client->index($params);
print_r($response);
}
}
运行出现 :No alive nodes found in your cluster in
解决: 需要指定节点的ip和端口号
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Elasticsearch\ClientBuilder;
class TestController extends Controller
{
public $client = null;
public $host=['127.0.0.1:9200'];
public function __construct() {
$this->client = ClientBuilder::create()->setHosts($this->host)->build();
}
//创建
public function index(){
$params = [
'index' => 'my_liming',
'type' => 'my_type',
'id' => 'my_id',
'body' => ['testField' => 'abc']
];
$response = $this->client->index($params);
print_r($response);
}
}