Commit 8a66d74f authored by 赵威's avatar 赵威

get service id

parent 6c60bd03
...@@ -45,8 +45,9 @@ object Main extends LazyLogging { ...@@ -45,8 +45,9 @@ object Main extends LazyLogging {
"172.16.44.25:9092,172.16.44.31:9092,172.16.44.45:9092" "172.16.44.25:9092,172.16.44.31:9092,172.16.44.45:9092"
) )
// TODO remove test
val kafkaConsumer = new FlinkKafkaConsumer[UserInfo]( val kafkaConsumer = new FlinkKafkaConsumer[UserInfo](
"gm-portrait-update-device", "gm-portrait-update-device-test",
new UserInfoDeserializationSchema, new UserInfoDeserializationSchema,
kafkaConsumerProperties kafkaConsumerProperties
) )
......
package com.gmei.up.utils package com.gmei.up.utils
case class Content(id: Long, index: String, projects: String) case class Content(id: Long, index: String, serviceId: Some[Long], projects: String)
...@@ -57,7 +57,10 @@ object ES { ...@@ -57,7 +57,10 @@ object ES {
implicit object ContentHitReader extends HitReader[Content] { implicit object ContentHitReader extends HitReader[Content] {
override def read(hit: Hit): Try[Content] = { override def read(hit: Hit): Try[Content] = {
val source = hit.sourceAsMap val source = hit.sourceAsMap
Try(Content(source("id").toString.toLong, hit.index, source("tags_v3").toString)) val serviceId = source.get("service.id").asInstanceOf[Some[Long]]
Try(
Content(source("id").toString.toLong, hit.index, serviceId, source("tags_v3").toString)
)
} }
} }
...@@ -66,6 +69,11 @@ object ES { ...@@ -66,6 +69,11 @@ object ES {
def request(req: SearchRequest): Either[Throwable, Future[IndexedSeq[Content]]] = { def request(req: SearchRequest): Either[Throwable, Future[IndexedSeq[Content]]] = {
val client: ElasticClient = ESClient.create("172.16.52.33", 9200, "elastic", "gengmei!@#") val client: ElasticClient = ESClient.create("172.16.52.33", 9200, "elastic", "gengmei!@#")
// println(req.show) // println(req.show)
client.execute(req).map { resp =>
val a = resp.result.to[Content]
a.foreach(x => println(x.id, x.index, x.serviceId))
}
try { try {
Right(client.execute(req).map(resp => resp.result.to[Content])) Right(client.execute(req).map(resp => resp.result.to[Content]))
} catch { } catch {
......
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