Commit e965f9e5 authored by 赵威's avatar 赵威

add printer

parent 803ec69a
package com.gmei.up.utils
import scala.collection.mutable.ListBuffer
import scala.util.Try
import com.sksamuel.elastic4s.ElasticClient
import com.sksamuel.elastic4s.http.JavaClient
import org.apache.http.HttpHost
......@@ -11,6 +12,7 @@ import org.elasticsearch.client.RestClient
import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback
import com.sksamuel.elastic4s.requests.searches.{ SearchRequest, SearchResponse }
import com.sksamuel.elastic4s.ElasticDsl._
import com.sksamuel.elastic4s.{ HitReader, Hit }
import org.json4s.JsonDSL._
import org.json4s.jackson.JsonMethods._
import org.json4s.JObject
......@@ -40,17 +42,20 @@ object ESClient {
}
object ES {
case class Character(id: String)
implicit object CharacterHitReader extends HitReader[Character] {
override def read(hit: Hit): Try[Character] = {
val source = hit.sourceAsMap
Try(Character(source("id").toString))
}
}
def test(diaryQuery: String, tractateQuery: String) = {
// TODO read from config
val client: ElasticClient = ESClient.create("172.16.52.33", 9200, "elastic", "gengmei!@#")
val a = multi(
search("gm-dbmw-diary-read").source(diaryQuery),
search("gm-dbmw-tractate-read").source(tractateQuery)
)
println(a.toString())
// TODO remove await
val resp = client
.execute(
multi(
......@@ -61,6 +66,13 @@ object ES {
.await
// println(resp)
val a = resp.result.to[Character]
println("%%%%%%%%%%%")
a.foreach(x => println(x.id))
println("%%%%%%%%%%%")
resp
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment