ElasticSearch 5.1.1 Scala API 使用 sksamuel/elastic4s 或其他任何东西有什么好的例子吗?
Is there any good example for ElasticSearch 5.1.1 Scala API using sksamuel/elastic4s or anything else?
我无法在 sksamuel/elastic4s 中找到使用 Scala 的 ElasticSearch 5.1.1 的好示例。文档不是很有用,该站点的 none 有很好的示例。即使是创建索引、放置数据和搜索的简单示例也会有所帮助。
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)
}
我无法在 sksamuel/elastic4s 中找到使用 Scala 的 ElasticSearch 5.1.1 的好示例。文档不是很有用,该站点的 none 有很好的示例。即使是创建索引、放置数据和搜索的简单示例也会有所帮助。
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)
}