I am looking for the Java API pendant to
curl -XGET http://localhost:9200
With a Result like:
{
  "ok" : true, 
  "status" : 200,
  "name" : "Kierrok",
  "version" : {
    "number" : "0.90.7",
    "build_hash" : "36897d07dadcb70886db7f149e645ed3d44eb5f2",
    "build_timestamp" : "2013-11-13T12:06:54Z",
    "build_snapshot" : false,
    "lucene_version" : "4.5.1"
  },
  "tagline" : "You Know, for Search"
}
I expect it somewhere in the admin() part of the java api? I can't find it.
I found this Solution(Scala Code but Java API)
case class GetEsVersionQuery(esClient: Client) {
  lazy val p = promise[NodesInfoResponse]()
  esClient
    .admin()
    .cluster()
    .prepareNodesInfo()
    .all()
    .execute()
    .addListener(new ActionListener[NodesInfoResponse] {
    def onFailure(e: Throwable) = {
      p failure e
    }
    def onResponse(response: NodesInfoResponse) = p success response
  })
  def execute: Future[NodesInfoResponse] = p.future
}
def testElasticsearchVersion: Future[Boolean] = {
    GetEsVersionQuery(esClient).execute map {
      esVersion => {
        val nodes = esVersion.iterator().toList
        nodes forall(node => node.getVersion.after(Version.V_0_90_5))
      }
    } recover {
      case e: Throwable => false
    }
  }
}
Credits to David Pilato from the elasticsearch usergroup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With