Example of using ES elastic4s with CaseMapper macros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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