Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elastic4s does not exit

I tried to run an example code of elastic4s, as follows,

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
}

The program correctly prints the results, but it does not exit itself. I don't know if there are problems with my code or environment.

like image 937
Fei Jiang Avatar asked May 19 '26 18:05

Fei Jiang


1 Answers

Try using shutdown. shutdown will actually delegate to prepareNodesShutdown, which is a method of ClusterAdminClient and shutdowns a node. shutdown without any argument will shutdown the local node.

EDIT: added code and javadoc link

The following did work for me and worked as expected with elastic4s 1.4.0 (i.e. main is terminated)

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
}
like image 139
edi Avatar answered May 22 '26 08:05

edi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!