我正在尝试对索引进行扫描和滚动操作,如示例所示:
$client = ClientBuilder::create()->setHosts([MYESHOST])->build();
$params = [
"search_type" => "scan", // use search_type=scan
"scroll" => "30s", // how long between scroll requests. should be small!
"size" => 50, // how many results *per shard* you want back
"index" => "my_index",
"body" => [
"query" => [
"match_all" => []
]
]
];
$docs = $client->search($params); // Execute the search
$scroll_id = $docs['_scroll_id']; // The response will contain no results, just a _scroll_id
// Now we loop until the scroll "cursors" are exhausted
while ('true) {
// Execute a Scroll request
$response = $client->scroll([
"scroll_id" => $scroll_id, //...using our previously obtained _scroll_id
"scroll" => "30s" // and the same timeout window
]
);
// Check to see if we got any search hits from the scroll
if (count($response['hits']['hits']) > 0) {
// If yes, Do Work Here
// Get new scroll_id
// Must always refresh your _scroll_id! It can change sometimes
$scroll_id = $response['_scroll_id'];
} else {
// No results, scroll cursor is empty. You've exported all the data
break;
}
}
第一个$client->search($params)
API调用执行良好,我能够获得滚动id。但是$client->scroll()
API失败,我得到例外:"Elasticsearch'Common'Exceptions'NoNodesAvailableException在你的集群中没有发现活节点"
我正在使用Elasticsearch 1.7.1和PHP 5.6.11
请帮
我发现elasticsearch的php驱动程序充满了问题,我的解决方案是通过php使用curl实现RESTful API,一切都工作得更快,调试也更容易
我猜这个示例与您正在使用的版本不一致(您提供的链接指向2.0,而您使用的是1.7.1)。只需在循环内添加:
try {
$response = $client->scroll([
"scroll_id" => $scroll_id, //...using our previously obtained _scroll_id
"scroll" => "30s" // and the same timeout window
]
);
}catch (Elasticsearch'Common'Exceptions'NoNodesAvailableException $e) {
break;
}
检查您的服务器是否运行以下命令。
service elasticsearch status
我遇到了同样的问题,并解决了它。
我已经添加了script.disable_dynamic: true
到elasticsearch。在Digitalocan教程https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-elasticsearch-on-ubuntu-14-04中解释的yml
所以elasticsearch服务器没有启动。
我从elasticsearch.yml中删除了以下行
script.disable_dynamic: true
重新启动弹性搜索服务,设置网络主机为本地"127.0.0.1"
我建议直接使用php curl lib进行elasticsearch查询。我发现它比任何其他elasticsearch客户端库更容易使用,您可以使用cli curl模拟任何查询,您可以在互联网上找到许多示例,文档和讨论。
也许您应该尝试在您的机器上远程登录telnet [your_es_host] [your_es_ip]
查看是否可以访问。
如果没有,请尝试打开该端口或禁用您的机器的防火墙。
这个错误基本上意味着它找不到你的集群,可能是由于客户端或服务器端的配置错误。
我有滚动相同的问题,它是与某些索引工作,但不与其他。在我将elasticsearch/elasticsearch包从2.1.3更新到2.2.0之后,它就消失了
取消elasticsearch.yml:
network.host:198....
并设置为:
127.0.0.1
:
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 127.0.0.1
#
# Set a custom port for HTTP:
#
# http.port: 9200
#
我使用Elasticsearch 2.2在Magento 2在LXC容器下
我在docker中设置Elasticsearch服务器作为doc, https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html
但是它使用不同的网络(networks: - esnet),它不能与应用程序网络通信。删除网络设置后,它运行良好
如果你在docker中设置Elasticsearch服务器作为doc, https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html
但是它使用与其他服务不同的网络(networks: - esnet),并且它不能与应用程序网络通信。删除网络设置后,它运行良好
尝试:
- 如果elasticsearch服务已经在运行,请停止
-
通过终端进入你的elasticsearch目录,运行:
> ./bin/elasticsearch