在您的群集中找不到活动节点

时间:2017-02-03 14:34:54

标签: elasticsearch php-7 elasticsearch-plugin

我安装了elasticsearch with the help of this link

require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;

$client = ClientBuilder::create()->setHosts(["localhost:9200"])->build();  
$response = ''; 
try{
    $params = [
        'index' => 'my_index',
        'type' => 'my_type',
        'id' => 'my_id',
        'body' => ['testField' => 'abc']
    ]; 
    $response = $client->indices()->create($params);        
}catch(Exception $e){
    echo "Exception : ".$e->getMessage();
}
print_r($response);
die('End : Elastic Search');

它返回群集中找不到活动节点。 当我将端口更改为80

$client = ClientBuilder::create()->setHosts(["localhost:80"])->build();
它给了我以下错误。

不允许的方法。 URL / my_index不允许使用请求的方法PUT。

5 个答案:

答案 0 :(得分:1)

您是否尝试重新启动elasticsearch守护程序?像:

systemctl restart elasticsearch

然后,检查它是否正在运行:

systemctl status elasticsearch

如果没有,请检查日志文件是否有异常。

答案 1 :(得分:0)

您在索引和文档创建之间混合,首先需要创建索引(如常规关系数据库中的表),然后立即插入文档

require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;

$indexParams = [
    'index' => 'my_index',
    'body' => [
        'settings' => [
            'number_of_shards' => 5,
            'number_of_replicas' => 1
        ]
    ]
];

$docParams = [
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => 'my_id',
    'body' => ['testField' => 'abc']
];    

$client = ClientBuilder::create()->setHosts(["localhost:9200"])->build();  
$response = ''; 
try {
    /* Create the index */
    $response = $client->indices()->create($indexParams);
    print_r($response);

    /* put doc in the index */
    $response = $client->index($docParams);
    print_r($response);

} catch(Exception $e) {
    echo "Exception : ".$e->getMessage();
}
die('End : Elastic Search');

答案 2 :(得分:0)

如果您在docker中使用Elasticsearch服务器作为文档https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

但它使用不同的网络(网络: - esnet)与其他服务,它无法与应用程序网络通信。删除网络设置后,它运行良好。

答案 3 :(得分:0)

在方法CurlHandler :: __ invokeAsArray上的vendor \ guzzlehttp \ ringphp \ src \ Client \ CurlHandler.php上设置breackpoint并查看$response 也使用

$client = ClientBuilder::create()->setHosts([['host' =>self::$CONF['elasticSearchHost'],'port' => '80','scheme'=>'http']])->build();

答案 4 :(得分:0)

检查您的网络是否正在监视弹性服务的IP(如果使用的是docker),在编写容器之前,请通过Shell在Web应用程序服务器内部检查是否正在监视服务的IP并将IP添加到.env文件中然后再次执行docker compose。 在其他情况下,请检查您的vps o开发环境是否在ping o o观看弹性服务的IP

相关问题