Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Elasticsearch Version with Java API [closed]

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.

like image 474
MeiSign Avatar asked Oct 02 '22 08:10

MeiSign


1 Answers

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.

like image 56
MeiSign Avatar answered Oct 10 '22 00:10

MeiSign