Quellcode durchsuchen

fix: es返回省市区名字

许家凯 vor 4 Jahren
Ursprung
Commit
65720a490a
1 geänderte Dateien mit 12 neuen und 5 gelöschten Zeilen
  1. 12 5
      src/main/scala/com/winhc/bigdata/spark/utils/EsRestUtils.scala

+ 12 - 5
src/main/scala/com/winhc/bigdata/spark/utils/EsRestUtils.scala

@@ -11,9 +11,7 @@ import org.apache.http.impl.client.BasicCredentialsProvider
 import org.apache.http.impl.nio.client.HttpAsyncClientBuilder
 import org.apache.http.nio.entity.NStringEntity
 import org.apache.http.util.EntityUtils
-import org.elasticsearch.client.{RestClient, RestClientBuilder}
-
-import scala.util.parsing.json.JSON;
+import org.elasticsearch.client.{RestClient, RestClientBuilder};
 
 /**
  * @Author: XuJiakai
@@ -28,7 +26,7 @@ object EsRestUtils {
   }
 
   def getIndexResult(json: String): List[Map[String, Any]] = {
-    regJson(JSON.parseFull(json))("hits").asInstanceOf[Map[String, Any]]("hits").asInstanceOf[List[Map[String, Any]]]
+    regJson(scala.util.parsing.json.JSON.parseFull(json))("hits").asInstanceOf[Map[String, Any]]("hits").asInstanceOf[List[Map[String, Any]]]
   }
 
   def getRestClient(): RestClient = {
@@ -48,7 +46,7 @@ object EsRestUtils {
       s"""
          |{
          |  "_source": {
-         |     "includes": [ "_id","reg_status","province_code","city_code","county_code","reg_location","estiblish_time","category_code","reg_capital","phones","emails" ]
+         |     "includes": [ "_id","reg_status","province_code","city_code","county_code","province_name","city_name","county_name","reg_location","estiblish_time","category_code","category_first","category_second","category_third","reg_capital","phones","emails" ]
          |   },
          |  "query": {
          |    "term": {
@@ -74,6 +72,9 @@ object EsRestUtils {
 
     val en = indexResponse.getEntity
     val res = EntityUtils.toString(en)
+//    val id = JSONPath.eval(JSON.parseObject(res), "$.hits.hits[0]._id").asInstanceOf[String]
+//    println(id)
+
     val list = getIndexResult(res)
     if (list.nonEmpty) {
       val v = list.head
@@ -82,11 +83,17 @@ object EsRestUtils {
         "cid" -> v("_id").asInstanceOf[String]
         , "reg_status" -> map("reg_status")
         , "province_code" -> map("province_code")
+        , "province_name" -> map("province_name")
         , "city_code" -> map("city_code")
+        , "city_name" -> map("city_name")
         , "county_code" -> map("county_code")
+        , "county_name" -> map("county_name")
         , "reg_location" -> map("reg_location")
         , "estiblish_time" -> map("estiblish_time")
         , "category_code" -> map("category_code")
+        , "category_first" -> map("category_first")
+        , "category_second" -> map("category_second")
+        , "category_third" -> map("category_third")
         , "reg_capital" -> map("reg_capital")
         , "phones" -> map("phones").asInstanceOf[Seq[String]].mkString(",")
         , "emails" -> map("emails").asInstanceOf[Seq[String]].mkString(",")