我找不到在sksamuel / elastic4s中使用Scala的ElasticSearch 5.1.1的良好示例。文档不是很有帮助,该站点都没有很好的例子。即使是创建索引,放置数据和搜索的简单示例也将有所帮助。
最佳答案
elastic4s自述文件包含了您需要入门的所有示例。诚然,它只适用于高级用例,但是对于简单的示例来说,有很多。
例如,阅读quick start guide。
import com.sksamuel.elastic4s.TcpClient
import com.sksamuel.elastic4s.ElasticDsl._
object Test extends App {
// Here we create an instance of the TCP client
val client = TcpClient.transport(ElasticsearchClientUri(host, port))
// await is a helper method to make this operation synchronous instead of async
// You would normally avoid doing this in a real program as it will block your thread
client.execute {
indexInto("bands" / "artists") fields ("name" -> "coldplay") refresh(RefreshPolicy.IMMEDIATE)
}.await
// now we can search for the document we just indexed
val resp = client.execute {
search("bands" / "artists") query "coldplay"
}.await
println(resp)
}
关于scala - 是否有使用sksamuel/elastic4s或其他任何工具的ElasticSearch 5.1.1 Scala API的好示例?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41240906/