Elastic4s客户端批量操作错误

时间:2015-02-11 08:42:25

标签: scala elastic4s

我正在尝试使用scala elstic4s客户端将新文档索引到我的elasticsearch集群中,但我遇到了类型的编译问题。按照Web中的文档和示例,语法如下:

客户端实例化:

val settings = ImmutableSettings.settingsBuilder().put("cluster.name", Configuration.elasticsearchClusterName).build()    
val uri = ElasticsearchClientUri("elasticsearch://" + Configuration.elasticsearchUri)
val client = ElasticClient.remote(settings, uri)

我想把它写成:

def writeToElasticsearch(bulkList: List[EventMessage]) {
   val ops = for (message <- bulkList) yield index into indexDcp ttl 7.days.toMillis doc StringDocumentSource(message.toJSon()) 
   client.execute(bulk(ops: _*)).await
 }    

我在批量操作中遇到编译错误:

Multiple markers at this line
- type mismatch; found : List[com.sksamuel.elastic4s.IndexDefinition] required: 
 Seq[Int]

任何人都可以告诉我如何转换类型以使其工作?谢谢!

1 个答案:

答案 0 :(得分:0)

我不确定你为什么会收到错误,可能是你错过了代码示例中的错误,但是这个版本的代码对我来说很好。

object Test extends App {

  val client = ElasticClient.local
  val indexDcp = "myindex/mytype"

  import scala.concurrent.duration._
  import ElasticDsl._

  def writeToElasticsearch(bulkList: List[EventMessage]) {
    val ops = for (message <- bulkList) yield { index into indexDcp ttl 7.days.toMillis doc StringDocumentSource(message.toJSon()) }
    client.execute(bulk(ops: _*)).await
  }

  trait EventMessage {
    def toJSon(): String
  }
}