0

私はscala 2.11.11、elastic4s 5.4.5、elastic4s-circe 5.4.5を使用しています

import com.sksamuel.elastic4s.ElasticDsl._
import com.sksamuel.elastic4s.TcpClient
import com.sksamuel.elastic4s.circe._
import io.circe.generic.auto._

object Test {

  val client: TcpClient = ???

  case class Something(a: Map[AnotherThing, Int])
  case class AnotherThing(b: Int)

  val smth = Something(Map.empty)

  client.execute {
    indexInto("index" / "type").doc(smth)
  }

}

これはコンパイルされません:

could not find implicit value for evidence parameter of type com.sksamuel.elastic4s.Indexable[net.lizeo.bd4m.storage.Test.Something]
indexInto("index" / "type").doc(smth)

ドキュメントによると:

選択したライブラリのインポートを以下に追加するだけで、それらの暗黙的なスコープを使用して、任意のタイプを doc に渡すことができ、Indexable が自動的に派生します。

Elastic4s -circimport io.circe.generic.auto._ありおよびimport com.sksamuel.elastic4s.circe._用。

私は何が欠けていますか?

4

2 に答える 2

0

オブジェクトcase classesのスコープの外側、つまりクラスの外側を定義する必要があります。それらを個別のクラスとして定義することもできます。TestTest

だから正しい方法は

import com.sksamuel.elastic4s.ElasticDsl._
import com.sksamuel.elastic4s.TcpClient
import com.sksamuel.elastic4s.circe._
import io.circe.generic.auto._

object Test {

  val client: TcpClient = ???

  val smth = Something(Map.empty)

  client.execute {
    indexInto("index" / "type").doc(smth)
  }

}

case class Something(a: Map[AnotherThing, Int])
case class AnotherThing(b: Int)
于 2017-06-19T14:16:58.430 に答える