我尝试运行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
}程序会正确打印结果,但不会自行退出。我不知道我的代码或环境是否有问题。
发布于 2014-12-23 22:22:34
尝试使用shutdown。shutdown实际上将委托给prepareNodesShutdown,这是ClusterAdminClient的一种方法,用于关闭节点。不带任何参数的shutdown将关闭本地节点。
编辑:添加代码和javadoc链接
下面的代码对我来说是有效的,并且与预期的elastic4s 1.4.0一起工作(即main被终止)
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
}https://stackoverflow.com/questions/27603676
复制相似问题