Hi, does the PHP API Version a PING Function has included? I know the PING
Function from Solar, its to check if the server is available and if not you
can make a Fallback. Or how is the best way to check if the elasticsearch
server is reachable? Regards and thanks Stefan.
If the TransportClient or NodeClient is set up as needed, then you can
easily wait for the cluster to be ready to use and let Elasticsearch do the
per-server discovery itself. At a high level (assuming this is part of some
class that includes private Client client;). Error reporting is minimal;
that can be easily adjusted depending on your needs:
public void waitForYellowStatus(TimeValue timeout, boolean waitForNode)
throws MyException
{
long startTime = System.currentTimeMillis();
TimeValue sleepTime = new TimeValue(2000);
for (;
{
try
{
client.admin().cluster().prepareHealth().setTimeout(timeout)
.setWaitForYellowStatus().execute().actionGet();
return;
}
catch (NoNodeAvailableException e)
{
if ((!waitForNode)
|| ((System.currentTimeMillis() - startTime) >
timeout.getMillis()))
throw new MyException("Cluster is not available: " + e);
sleep(sleepTime);
}
catch (ElasticsearchException e)
{
throw new MyException("Cluster is not ready: " + e);
}
}
}
Anyway, this works well for me. Hope it helps you!
Hi, does the PHP API Version a PING Function has included? I know the PING
Function from Solar, its to check if the server is available and if not you
can make a Fallback. Or how is the best way to check if the elasticsearch
server is reachable? Regards and thanks Stefan.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.