Commit e965f9e5 authored by 赵威's avatar 赵威

add printer

parent 803ec69a
package com.gmei.up.utils package com.gmei.up.utils
import scala.collection.mutable.ListBuffer import scala.collection.mutable.ListBuffer
import scala.util.Try
import com.sksamuel.elastic4s.ElasticClient import com.sksamuel.elastic4s.ElasticClient
import com.sksamuel.elastic4s.http.JavaClient import com.sksamuel.elastic4s.http.JavaClient
import org.apache.http.HttpHost import org.apache.http.HttpHost
...@@ -11,6 +12,7 @@ import org.elasticsearch.client.RestClient ...@@ -11,6 +12,7 @@ import org.elasticsearch.client.RestClient
import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback
import com.sksamuel.elastic4s.requests.searches.{ SearchRequest, SearchResponse } import com.sksamuel.elastic4s.requests.searches.{ SearchRequest, SearchResponse }
import com.sksamuel.elastic4s.ElasticDsl._ import com.sksamuel.elastic4s.ElasticDsl._
import com.sksamuel.elastic4s.{ HitReader, Hit }
import org.json4s.JsonDSL._ import org.json4s.JsonDSL._
import org.json4s.jackson.JsonMethods._ import org.json4s.jackson.JsonMethods._
import org.json4s.JObject import org.json4s.JObject
...@@ -40,17 +42,20 @@ object ESClient { ...@@ -40,17 +42,20 @@ object ESClient {
} }
object ES { 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) = { def test(diaryQuery: String, tractateQuery: String) = {
// TODO read from config // TODO read from config
val client: ElasticClient = ESClient.create("172.16.52.33", 9200, "elastic", "gengmei!@#") val client: ElasticClient = ESClient.create("172.16.52.33", 9200, "elastic", "gengmei!@#")
val a = multi( // TODO remove await
search("gm-dbmw-diary-read").source(diaryQuery),
search("gm-dbmw-tractate-read").source(tractateQuery)
)
println(a.toString())
val resp = client val resp = client
.execute( .execute(
multi( multi(
...@@ -61,6 +66,13 @@ object ES { ...@@ -61,6 +66,13 @@ object ES {
.await .await
// println(resp) // println(resp)
val a = resp.result.to[Character]
println("%%%%%%%%%%%")
a.foreach(x => println(x.id))
println("%%%%%%%%%%%")
resp 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