我无法在 sksamuel/elastic4s 中找到使用 Scala 的 ElasticSearch 5.1.1 的好例子。文档不是很有帮助,并且该站点都没有任何好的示例。即使是创建索引、放置数据和搜索的简单示例也会有所帮助。
问问题
820 次
1 回答
1
elastic4s 自述文件包含您入门所需的所有示例。诚然,它对高级用例很轻,但对于简单的例子来说,有很多。
例如,阅读快速入门指南。
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)
}
于 2017-03-02T01:32:33.497 回答