elastic4s不会退出

时间:2014-12-22 13:28:05

标签: scala elasticsearch elastic4s

我尝试运行elastic4s的示例代码,如下所示,

import com.sksamuel.elastic4s.ElasticClient
import com.sksamuel.elastic4s.ElasticDsl._

object hw extends App {
  val client = ElasticClient.local
  client.execute(create index "bands")
  client.execute { index into "bands/artists" fields "name"->"coldplay" }.await
  val resp = client.execute { search in "bands/artists" query "coldplay" }.await
  println(resp)
  client.close
}

程序正确打印结果,但不会自行退出。我不知道我的代码或环境是否存在问题。

1 个答案:

答案 0 :(得分:2)

尝试使用shutdownshutdown实际上会委托给prepareNodesShutdown shutdown,这是ClusterAdminClient的方法并关闭节点。没有任何参数的import com.sksamuel.elastic4s.ElasticClient import com.sksamuel.elastic4s.ElasticDsl._ object Main extends App { val client = ElasticClient.local client.execute(create index "bands") client.execute { index into "bands/artists" fields "name"->"coldplay" }.await val resp = client.execute { search in "bands/artists" query "coldplay" }.await println(resp) client.close() client.shutdown } 将关闭本地节点。

编辑:添加了代码和javadoc链接

以下对我有用,并且按照预期的方式使用elastic4s 1.4.0(即主要终止)

{{1}}