Skip to content

Instantly share code, notes, and snippets.

@fancellu
Last active Aug 29, 2015
Embed
What would you like to do?
Example of using ES elastic4s with CaseMapper macros
package es
import com.sksamuel.elastic4s.ElasticClient
import com.sksamuel.elastic4s.ElasticDsl._
import scala.concurrent._
import ExecutionContext.Implicits.global
import scala.concurrent.duration._
object e4s1 extends App {
val client = ElasticClient.remote("localhost",9300)
val outF=client execute {
search in "automobiles"->"transactions" query { term("price"->80000) } sourceInclude("color", "make","sold")
}
val out = Await.result(outF, 10 seconds)
import com.felstar.caseMapper.CaseMapper._
case class Transaction(sold:String, color:String, make:String)
val hits=(out.getHits.hits)
import scala.collection.JavaConversions._
val sources=hits.map(_.getSource)
val scalaMaps=sources.map(mapAsScalaMap)
scalaMaps.foreach(println)
scalaMaps.map(fromMap[Transaction](_)).foreach(println)
}
Map(sold -> 2014-01-01, color -> red, make -> bmw)
Transaction(2014-01-01,red,bmw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment