简体   繁体   English

具有多个主机的elasticsearch php API

[英]elasticsearch php api with multiple hosts

I followed this link to create an elasticsearch 2 nodes cluster on Azure: this link 我按照此链接在Azure上创建了Elasticsearch 2节点群集: 此链接

the installation and configuring went good. 安装和配置顺利。

When i started to check the cluster i found a strange behaviour from the php client. 当我开始检查群集时,我从php客户端发现了一个奇怪的行为。

I declared 2 hosts in the client: 我在客户端中声明了2个主机:

$ELSEARCH_SERVER = array("dns1:9200","dns2:9200");
$params = array();
$params['hosts'] = $ELSEARCH_SERVER;
$dstEl = new Elasticsearch\Client($params);

the excpected behaviour is that it will try to insert the documents to "dns1" and if it fails it will automatically change to "dns2". 预期的行为是它将尝试将文档插入“ dns1”,如果失败,它将自动更改为“ dns2”。 but, for some reason when one of the servers is down on insertion the php client throws an exception that it couldn't connect to host and only. 但是,由于某些原因,其中一台服务器在插入时出现故障时,php客户端会抛出一个异常,表明它无法仅连接到主机。

Is there any way to cause the client automatically choose an online server? 有什么方法可以使客户端自动选择在线服务器?

thnx n

Solution: After debugging the the elasticsearch php client I found a retry mechansim that allows the client to jump to the next server from the pool if the previous is down. 解决方案:调试了elasticsearch php客户端后,我发现了一个重试机制,如果前一个服务器已关闭,则该机制可让该客户端从池中跳到下一个服务器。 this mechanism is disabled by default 默认情况下禁用此机制

to enable this mechanism you need to initialize the Client with a parameter called retries: 要启用此机制,您需要使用称为retries的参数初始化Client:

$params = array();
$params['hosts'] = $ELSEARCH_SERVER;    
$params['retries'] = count($ELSEARCH_SERVER);
$dstEl = new Elasticsearch\Client($params);

Hope it will help you guys 希望对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM