# Is there a ping function available?

**URL:** <https://discuss.elastic.co/t/is-there-a-ping-function-available/17151>\
**Category:** Elasticsearch\
**Created:** [April 23, 2014, 3:47pm UTC](https://discuss.elastic.co/t/is-there-a-ping-function-available/17151 "2014-04-23T15:47:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stefan\_Kruse](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Stefan\_Kruse](https://discuss.elastic.co/u/Stefan_Kruse)\
**Post date:** [April 23, 2014, 3:47pm UTC](https://discuss.elastic.co/t/is-there-a-ping-function-available/17151/1 "2014-04-23T15:47:09Z")

</div>

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.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/34326dc6-55bf-482e-8e64-f5a78f0590b1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/34326dc6-55bf-482e-8e64-f5a78f0590b1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [April 23, 2014, 6:32pm UTC](https://discuss.elastic.co/t/is-there-a-ping-function-available/17151/2 "2014-04-23T18:32:29Z")

</div>

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!

Brian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5bbb27ac-ead7-444a-ad35-ac807b604139%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5bbb27ac-ead7-444a-ad35-ac807b604139%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [April 23, 2014, 6:42pm UTC](https://discuss.elastic.co/t/is-there-a-ping-function-available/17151/3 "2014-04-23T18:42:54Z")

</div>

Just issue a HTTP HEAD request against port 9200 of the host you want to  
connect to and check for status 200

curl -I -XHEAD localhost:9200  
HTTP/1.1 200 OK  
Content-Type: text/plain; charset=UTF-8  
Content-Length: 0

Or, if you want version information, use a HTTP GET request

curl -XGET localhost:9200  
{  
"status" : 200,  
"name" : "Human Fly",  
"version" : {  
"number" : "1.1.0",  
"build\_hash" : "2181e113dea80b4a9e31e58e9686658a2d46e363",  
"build\_timestamp" : "2014-03-25T15:59:51Z",  
"build\_snapshot" : false,  
"lucene\_version" : "4.7"  
},  
"tagline" : "You Know, for Search"  
}

Jörg

On Wed, Apr 23, 2014 at 5:47 PM, Stefan Kruse  
[info@all-around-shipping.de](mailto:info@all-around-shipping.de)wrote:

> 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.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/34326dc6-55bf-482e-8e64-f5a78f0590b1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/34326dc6-55bf-482e-8e64-f5a78f0590b1%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/34326dc6-55bf-482e-8e64-f5a78f0590b1%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/34326dc6-55bf-482e-8e64-f5a78f0590b1%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEoJkA%2B4ris9RpBdCDO4OQdK-28HpxEK%2Bu--y6724237w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEoJkA%2B4ris9RpBdCDO4OQdK-28HpxEK%2Bu--y6724237w%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:33am UTC](https://discuss.elastic.co/t/is-there-a-ping-function-available/17151/4 "2017-07-06T01:33:59Z")

</div>


