Elastic4s客户端批量操作报错

Elastic4s client bulk operation error

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

客户端实例化:

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]

谁能告诉我如何转换类型才能完成这项工作?谢谢!

我不确定您为什么会收到错误,可能是您在代码示例中遗漏了一些内容,但您的代码版本对我来说编译得很好。

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
  }
}