Browse Source

增加索引切换

xufei 4 years ago
parent
commit
df0d754abb

+ 237 - 189
src/main/scala/com/winhc/bigdata/spark/jobs/judicial/JudicialCaseRelationPreNew.scala

@@ -2,7 +2,8 @@ package com.winhc.bigdata.spark.jobs.judicial
 
 import com.winhc.bigdata.spark.udf.{BaseFunc, CaseReasonAggs, CompanyMapping, CourtRank, NameAggs}
 import com.winhc.bigdata.spark.utils.BaseUtil.isWindows
-import com.winhc.bigdata.spark.utils.{BaseUtil, LoggingUtils, SparkUtils}
+import com.winhc.bigdata.spark.utils.EsQueryUtils.updateAliases
+import com.winhc.bigdata.spark.utils.{BaseUtil, EsQueryUtils, LoggingUtils, SparkUtils}
 import org.apache.commons.lang3.StringUtils
 import org.apache.spark.sql.SparkSession
 
@@ -44,6 +45,8 @@ object JudicialCaseRelationPreNew {
     c match {
       case "calc" => r.calc()
       case "precalc" => r.precalc()
+      case "updateIndex" => r.updateIndex()
+      case "createIndex" => r.createIndex()
     }
 
     spark.stop()
@@ -322,186 +325,186 @@ case class JudicialCaseRelationPreNew(s: SparkSession, project: String, ds: Stri
     val t5_ds = BaseUtil.getPartion(t5, spark) //映射表分区
 
     //替换司法案件id
-    sql(
-      s"""
-         |INSERT ${if (isWindows) "INTO" else "OVERWRITE"} TABLE $project.$t3 partition (ds = '$t1_ds')
-         |SELECT
-         |   judicase_id
-         |   ,flag
-         |   ,title
-         |   ,case_type
-         |   ,case_reason
-         |   ,case_no
-         |   ,court_name
-         |   ,case_stage
-         |   ,lable
-         |   ,map_2_json(${getStrToMap(cols)}) as detail
-         |   ,yg_name
-         |   ,bg_name
-         |   ,date
-         |   ,detail_id
-         |   ,case_amt
-         |FROM
-         |(
-         |   SELECT  COALESCE(b.judicase_id,a.new_judicase_id) judicase_id
-         |           ,a.flag
-         |           ,a.title
-         |           ,a.case_type
-         |           ,a.case_reason
-         |           ,case_no_trim(a.case_no) as case_no
-         |           ,a.court_name
-         |           ,a.case_stage
-         |           ,case_label(a.flag) lable
-         |           ,a.yg_name
-         |           ,a.bg_name
-         |           ,a.date
-         |           ,a.detail_id
-         |           ,a.case_amt
-         |           ,a.bg_name as name
-         |   FROM    (
-         |     SELECT
-         |        judicase_id
-         |        ,flag
-         |        ,title
-         |        ,case_type
-         |        ,case_reason
-         |        ,case_no_trim(case_no) as case_no
-         |        ,court_name
-         |        ,case_stage
-         |        ,replace_char(yg_name) as yg_name
-         |        ,replace_char(bg_name) as bg_name
-         |        ,date
-         |        ,detail_id
-         |        ,case_amt
-         |        ,md5(CLEANUP(case_no_trim(case_no))) as new_judicase_id
-         |     FROM $project.$t2
-         |     WHERE ds= '$t2_ds' and tn not in ('wenshu','zxr','zxr_person','company_dishonest_info','company_dishonest_info_person')
-         |           and case_no_trim(case_no) is not null
-         |           and date is not null and length(date) = 19
-         |   ) a
-         |   LEFT JOIN (
-         |     SELECT case_no_trim(case_no) as case_no,max(judicase_id) judicase_id
-         |     FROM $project.$t2
-         |     WHERE ds = '$t2_ds' and tn in ('wenshu','zxr','zxr_person','company_dishonest_info','company_dishonest_info_person')
-         |     and case_no_trim(case_no) is not null
-         |     GROUP BY case_no
-         |   ) b
-         |   ON  CLEANUP(a.case_no) = CLEANUP(b.case_no)
-         |   UNION ALL
-         |   SELECT   judicase_id
-         |           ,flag
-         |           ,title
-         |           ,case_type
-         |           ,case_reason
-         |           ,case_no_trim(case_no) as case_no
-         |           ,court_name
-         |           ,case_stage
-         |           ,case_label(flag) lable
-         |           ,replace_char(yg_name) as yg_name
-         |           ,replace_char(bg_name) as bg_name
-         |           ,date
-         |           ,detail_id
-         |           ,case_amt
-         |           ,replace_char(bg_name) as name
-         |   FROM $project.$t2
-         |   WHERE ds = '$t2_ds' and tn in ('wenshu','zxr','zxr_person','company_dishonest_info','company_dishonest_info_person')
-         |         and case_no_trim(case_no) is not null
-         |         and date is not null and length(date) = 19
-         |)
-         |""".stripMargin).show(10, false)
+        sql(
+          s"""
+             |INSERT ${if (isWindows) "INTO" else "OVERWRITE"} TABLE $project.$t3 partition (ds = '$t1_ds')
+             |SELECT
+             |   judicase_id
+             |   ,flag
+             |   ,title
+             |   ,case_type
+             |   ,case_reason
+             |   ,case_no
+             |   ,court_name
+             |   ,case_stage
+             |   ,lable
+             |   ,map_2_json(${getStrToMap(cols)}) as detail
+             |   ,yg_name
+             |   ,bg_name
+             |   ,date
+             |   ,detail_id
+             |   ,case_amt
+             |FROM
+             |(
+             |   SELECT  COALESCE(b.judicase_id,a.new_judicase_id) judicase_id
+             |           ,a.flag
+             |           ,a.title
+             |           ,a.case_type
+             |           ,a.case_reason
+             |           ,case_no_trim(a.case_no) as case_no
+             |           ,a.court_name
+             |           ,a.case_stage
+             |           ,case_label(a.flag) lable
+             |           ,a.yg_name
+             |           ,a.bg_name
+             |           ,a.date
+             |           ,a.detail_id
+             |           ,a.case_amt
+             |           ,a.bg_name as name
+             |   FROM    (
+             |     SELECT
+             |        judicase_id
+             |        ,flag
+             |        ,title
+             |        ,case_type
+             |        ,case_reason
+             |        ,case_no_trim(case_no) as case_no
+             |        ,court_name
+             |        ,case_stage
+             |        ,replace_char(yg_name) as yg_name
+             |        ,replace_char(bg_name) as bg_name
+             |        ,date
+             |        ,detail_id
+             |        ,case_amt
+             |        ,md5(CLEANUP(case_no_trim(case_no))) as new_judicase_id
+             |     FROM $project.$t2
+             |     WHERE ds= '$t2_ds' and tn not in ('wenshu','zxr','zxr_person','company_dishonest_info','company_dishonest_info_person')
+             |           and case_no_trim(case_no) is not null
+             |           and date is not null and length(date) = 19
+             |   ) a
+             |   LEFT JOIN (
+             |     SELECT case_no_trim(case_no) as case_no,max(judicase_id) judicase_id
+             |     FROM $project.$t2
+             |     WHERE ds = '$t2_ds' and tn in ('wenshu','zxr','zxr_person','company_dishonest_info','company_dishonest_info_person')
+             |     and case_no_trim(case_no) is not null
+             |     GROUP BY case_no
+             |   ) b
+             |   ON  CLEANUP(a.case_no) = CLEANUP(b.case_no)
+             |   UNION ALL
+             |   SELECT   judicase_id
+             |           ,flag
+             |           ,title
+             |           ,case_type
+             |           ,case_reason
+             |           ,case_no_trim(case_no) as case_no
+             |           ,court_name
+             |           ,case_stage
+             |           ,case_label(flag) lable
+             |           ,replace_char(yg_name) as yg_name
+             |           ,replace_char(bg_name) as bg_name
+             |           ,date
+             |           ,detail_id
+             |           ,case_amt
+             |           ,replace_char(bg_name) as name
+             |   FROM $project.$t2
+             |   WHERE ds = '$t2_ds' and tn in ('wenshu','zxr','zxr_person','company_dishonest_info','company_dishonest_info_person')
+             |         and case_no_trim(case_no) is not null
+             |         and date is not null and length(date) = 19
+             |)
+             |""".stripMargin).show(10, false)
 
-    //name 替换 cid
-    sql(
-      s"""
-         |INSERT ${if (isWindows) "INTO" else "OVERWRITE"} TABLE $project.$t6 partition (ds = '$t1_ds')
-         |SELECT
-         |        a.judicase_id
-         |        ,flag
-         |        ,title
-         |        ,case_type
-         |        ,case_reason
-         |        ,case_no
-         |        ,court_name
-         |        ,case_stage
-         |        ,lable
-         |        ,detail
-         |        ,yg_name
-         |        ,bg_name
-         |        ,DATE
-         |        ,detail_id
-         |        ,case_amt
-         |        ,coalesce(b.cids,'') AS cids
-         |FROM    (
-         |        SELECT  *
-         |        FROM    $project.$t3
-         |        WHERE   ds = '$t1_ds'
-         |        ) a
-         |LEFT JOIN (
-         |        SELECT
-         |                judicase_id
-         |                ,sort(concat_ws(',',collect_set(cid)),',') cids
-         |        FROM    (
-         |                SELECT
-         |                        e.judicase_id
-         |                        ,f.new_cid cid
-         |                FROM    (
-         |                        SELECT  *
-         |                        FROM    (
-         |                                SELECT
-         |                                        yg_name AS names
-         |                                        ,judicase_id
-         |                                FROM    $project.$t3
-         |                                WHERE   ds = '$t1_ds' AND length(cleanup(yg_name)) >4
-         |                                UNION ALL
-         |                                SELECT
-         |                                        bg_name AS names
-         |                                        ,judicase_id
-         |                                FROM    $project.$t3
-         |                                WHERE   ds = '$t1_ds' AND length(cleanup(bg_name)) >4
-         |                                ) a
-         |                        LATERAL VIEW explode(split(names,',')) t AS name
-         |                        ) e
-         |                JOIN (
-         |                        SELECT
-         |                                cname
-         |                                ,concat_ws(',',collect_set(new_cid)) AS new_cid
-         |                        FROM    $project.$t5
-         |                        WHERE   ds = '$t5_ds' AND length(cleanup(cname)) >4 AND company_type not in ('2','8') AND deleted = '0'
-         |                        GROUP BY cname
-         |                     ) f
-         |                ON      cleanup(e.name) = cleanup(f.cname)
-         |                )
-         |        GROUP BY judicase_id
-         |          ) b
-         |ON      a.judicase_id = b.judicase_id
-         |""".stripMargin)
+        //name 替换 cid
+        sql(
+          s"""
+             |INSERT ${if (isWindows) "INTO" else "OVERWRITE"} TABLE $project.$t6 partition (ds = '$t1_ds')
+             |SELECT
+             |        a.judicase_id
+             |        ,flag
+             |        ,title
+             |        ,case_type
+             |        ,case_reason
+             |        ,case_no
+             |        ,court_name
+             |        ,case_stage
+             |        ,lable
+             |        ,detail
+             |        ,yg_name
+             |        ,bg_name
+             |        ,DATE
+             |        ,detail_id
+             |        ,case_amt
+             |        ,coalesce(b.cids,'') AS cids
+             |FROM    (
+             |        SELECT  *
+             |        FROM    $project.$t3
+             |        WHERE   ds = '$t1_ds'
+             |        ) a
+             |LEFT JOIN (
+             |        SELECT
+             |                judicase_id
+             |                ,sort(concat_ws(',',collect_set(cid)),',') cids
+             |        FROM    (
+             |                SELECT
+             |                        e.judicase_id
+             |                        ,f.new_cid cid
+             |                FROM    (
+             |                        SELECT  *
+             |                        FROM    (
+             |                                SELECT
+             |                                        yg_name AS names
+             |                                        ,judicase_id
+             |                                FROM    $project.$t3
+             |                                WHERE   ds = '$t1_ds' AND length(cleanup(yg_name)) >4
+             |                                UNION ALL
+             |                                SELECT
+             |                                        bg_name AS names
+             |                                        ,judicase_id
+             |                                FROM    $project.$t3
+             |                                WHERE   ds = '$t1_ds' AND length(cleanup(bg_name)) >4
+             |                                ) a
+             |                        LATERAL VIEW explode(split(names,',')) t AS name
+             |                        ) e
+             |                JOIN (
+             |                        SELECT
+             |                                cname
+             |                                ,concat_ws(',',collect_set(new_cid)) AS new_cid
+             |                        FROM    $project.$t5
+             |                        WHERE   ds = '$t5_ds' AND length(cleanup(cname)) >4 AND company_type not in ('2','8') AND deleted = '0'
+             |                        GROUP BY cname
+             |                     ) f
+             |                ON      cleanup(e.name) = cleanup(f.cname)
+             |                )
+             |        GROUP BY judicase_id
+             |          ) b
+             |ON      a.judicase_id = b.judicase_id
+             |""".stripMargin)
 
     val second_ds = getSecondLastPartitionOrElse(t6, "0")
     println(s"calc ds: $t2_ds, par ds : $t1_ds, second_ds : $second_ds")
 
     //找出增量数据
-    sql(
-      s"""
-         |INSERT ${if (isWindows) "INTO" else "OVERWRITE"} TABLE $project.$t4
-         |SELECT  coalesce(a.judicase_id,b.judicase_id)judicase_id
-         |        ,CASE WHEN a.judicase_id IS NULL THEN 1 ELSE 0 END
-         |FROM    (
-         |            SELECT  judicase_id
-         |                    ,md5(concat_ws('', sort(concat_ws(',',collect_set(concat_ws('',flag,detail_id))),','), sort(concat_ws(',',collect_set(cids)),','))) r1
-         |            FROM    $project.$t6
-         |            WHERE   ds = '$t1_ds'
-         |            GROUP BY judicase_id
-         |        ) a
-         |FULL JOIN (
-         |              SELECT  judicase_id
-         |                      ,md5(concat_ws('', sort(concat_ws(',',collect_set(concat_ws('',flag,detail_id))),','), sort(concat_ws(',',collect_set(cids)),','))) r2
-         |              FROM    $project.$t6
-         |              WHERE   ds = '$second_ds'
-         |              GROUP BY judicase_id
-         |          ) b
-         |ON  r1 = r2
-         |WHERE   r1 IS NULL OR r2 IS NULL
-         |""".stripMargin)
+    //    sql(
+    //      s"""
+    //         |INSERT ${if (isWindows) "INTO" else "OVERWRITE"} TABLE $project.$t4
+    //         |SELECT  coalesce(a.judicase_id,b.judicase_id)judicase_id
+    //         |        ,CASE WHEN a.judicase_id IS NULL THEN 1 ELSE 0 END
+    //         |FROM    (
+    //         |            SELECT  judicase_id
+    //         |                    ,md5(concat_ws('', sort(concat_ws(',',collect_set(concat_ws('',flag,detail_id))),','), sort(concat_ws(',',collect_set(cids)),','))) r1
+    //         |            FROM    $project.$t6
+    //         |            WHERE   ds = '$t1_ds'
+    //         |            GROUP BY judicase_id
+    //         |        ) a
+    //         |FULL JOIN (
+    //         |              SELECT  judicase_id
+    //         |                      ,md5(concat_ws('', sort(concat_ws(',',collect_set(concat_ws('',flag,detail_id))),','), sort(concat_ws(',',collect_set(cids)),','))) r2
+    //         |              FROM    $project.$t6
+    //         |              WHERE   ds = '$second_ds'
+    //         |              GROUP BY judicase_id
+    //         |          ) b
+    //         |ON  r1 = r2
+    //         |WHERE   r1 IS NULL OR r2 IS NULL
+    //         |""".stripMargin)
 
     //司法案件主表
     sql(
@@ -522,7 +525,7 @@ case class JudicialCaseRelationPreNew(s: SparkSession, project: String, ds: Stri
          |    case_amt    ,
          |    date        ,
          |    court_level ,
-         |    y.deleted     ,
+         |    0 deleted   ,
          |    cids
          |FROM
          |(
@@ -546,16 +549,16 @@ case class JudicialCaseRelationPreNew(s: SparkSession, project: String, ds: Stri
          |                   SELECT  judicase_id,flag,title,case_type,case_reason,case_no,court_name,case_stage,lable,yg_name,bg_name,date,case_amt,cids
          |                   ,court_level(court_name) court_level
          |                   FROM    $project.$t6
-         |                   WHERE   ds >= '$second_ds'
+         |                   WHERE   ds = '$t1_ds'
          |                ) a
          |        )
          |GROUP BY judicase_id
          |)x
-         |JOIN
-         |(
-         |   select *
-         |   from $project.$t4
-         |) y on x.judicase_id = y.judicase_id
+         |-- JOIN
+         |-- (
+         |--    select *
+         |--    from $project.$t4
+         |-- ) y on x.judicase_id = y.judicase_id
          |""".stripMargin).show(20, false)
 
     //明细表
@@ -576,7 +579,7 @@ case class JudicialCaseRelationPreNew(s: SparkSession, project: String, ds: Stri
          |    name_aggs['yg_name'] yg_name,
          |    name_aggs['bg_name'] bg_name,
          |    last_date   ,
-         |    y.deleted
+         |    0 deleted
          |FROM
          |(
          |SELECT  md5(concat_ws('',concat_ws('',judicase_id,${t1_ds.substring(2)}),CLEANUP(case_no))) id
@@ -598,19 +601,64 @@ case class JudicialCaseRelationPreNew(s: SparkSession, project: String, ds: Stri
          |        FROM    (
          |                   SELECT  *
          |                   FROM    $project.$t6
-         |                   WHERE   ds >= '$second_ds' AND length(lable) > 0
+         |                   WHERE   ds = '$t1_ds' AND length(lable) > 0
          |                )a
          |)
          |GROUP BY judicase_id
          |         ,case_no
          |) x
-         |JOIN
-         |(
-         |   select *
-         |   from $project.$t4
-         |) y on x.judicase_id = y.judicase_id
+         |-- JOIN
+         |-- (
+         |--    select *
+         |--    from $project.$t4
+         |-- ) y on x.judicase_id = y.judicase_id
          |""".stripMargin).show(10, false)
 
+    //建表
+    createIndex()
+
+  }
+
+  def createIndex(i1: String = "judicial_case_v", i2: String = "judicial_case_detail_v"): Unit = {
+    val bizdate = BaseUtil.getYesterday()
+    val index1 = s"$i1$bizdate"
+    val index2 = s"$i2$bizdate"
+    val client = EsQueryUtils.getClient()
+    //建表
+    EsQueryUtils.createTable(index1, EsQueryUtils.judicial_case, client)
+    EsQueryUtils.createTable(index2, EsQueryUtils.judicial_case_detail, client)
+    client.close()
+  }
+
+  def updateIndex(pre: String = "winhc_", i1: String = "judicial_case_v", i2: String = "judicial_case_detail_v"): Unit = {
+    val bizdate = BaseUtil.getYesterday()
+    val aliases1 = s"${pre}${i1.replace("_v","")}"
+    val aliases2 = s"${pre}${i2.replace("_v","")}"
+    val index1 = s"$i1$bizdate"
+    val index2 = s"$i2$bizdate"
+    val client = EsQueryUtils.getClient()
+
+    if(!EsQueryUtils.tableExists(index1,client) || !EsQueryUtils.tableExists(index2,client)){
+      println(s"index not exists $index1 -- $index2 ...")
+      sys.exit(-1)
+    }
+    //获取index
+    val list1 = EsQueryUtils.getAliases(aliases1, client)
+    val list2 = EsQueryUtils.getAliases(aliases2, client)
+    //移除索引
+    list1.foreach(updateAliases(_, aliases1, "remove", client))
+    list2.foreach(updateAliases(_, aliases2, "remove", client))
+    //新增索引
+    updateAliases(index1, aliases1, "add", client)
+    updateAliases(index2, aliases2, "add", client)
+    val list3 = EsQueryUtils.getIndexs(index1.substring(0, index1.indexOf("2")), client)
+    val list4 = EsQueryUtils.getIndexs(index2.substring(0, index1.indexOf("2")), client)
+    //删除多余索引
+    if (list3.size > 2 && list4.size > 2) {
+      EsQueryUtils.deleteIndex(list3.head, client)
+      EsQueryUtils.deleteIndex(list4.head, client)
+    }
+    client.close()
   }
 
 }

+ 374 - 0
src/main/scala/com/winhc/bigdata/spark/utils/EsQueryUtils.scala

@@ -0,0 +1,374 @@
+package com.winhc.bigdata.spark.utils
+
+import java.util.Collections
+
+import com.alibaba.fastjson.JSON
+import com.winhc.bigdata.spark.const.EnvConst
+import org.apache.http.HttpHost
+import org.apache.http.auth.{AuthScope, UsernamePasswordCredentials}
+import org.apache.http.entity.ContentType
+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.apache.spark.internal.Logging
+import org.elasticsearch.client.{RestClient, RestClientBuilder}
+
+/**
+ * @Description:
+ * @author π
+ * @date 2020/12/5 11:14
+ */
+object EsQueryUtils extends Logging {
+  def getClient(): RestClient = {
+    val credentialsProvider = new BasicCredentialsProvider();
+    credentialsProvider.setCredentials(AuthScope.ANY,
+      new UsernamePasswordCredentials("elastic", "elastic_168"))
+    // 单击所创建的Elasticsearch实例ID,在基本信息页面获取公网地址,即为HOST。
+    val restClient = RestClient.builder(new HttpHost(EnvConst.getEnv().getValue("es.nodes"), 9200))
+      .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
+        override def customizeHttpClient(httpClientBuilder: HttpAsyncClientBuilder): HttpAsyncClientBuilder = httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)
+      }).build()
+    restClient
+  }
+
+  def createTable(index: String, query: String, client: RestClient): Unit = {
+    if (!tableExists(index, client)) {
+      logInfo(query)
+      try {
+        val entity = new NStringEntity(query, ContentType.APPLICATION_JSON)
+        val indexResponse = client.performRequest(
+          "PUT",
+          index,
+          Collections.emptyMap[String, String](),
+          entity)
+        val res = EntityUtils.toString(indexResponse.getEntity)
+        println(s"create table $index success .")
+      } catch {
+        case e: Exception => {
+          println(s"create table $index error .")
+          logError(e.getMessage, e)
+        }
+      }
+    }
+  }
+
+  def tableExists(index: String, client: RestClient): Boolean = {
+    try {
+      val entity = new NStringEntity("{\"size\":1}", ContentType.APPLICATION_JSON)
+      val indexResponse = client.performRequest(
+        "GET",
+        index,
+        Collections.emptyMap[String, String](),
+        entity)
+      val res = EntityUtils.toString(indexResponse.getEntity)
+      println(res)
+      println(s"tableExists $index true .")
+      true
+    } catch {
+      case e: Exception => {
+        println(s"tableExists $index false .")
+        //logError(e.getMessage, e)
+        false
+      }
+    }
+  }
+
+  def getAliases(index: String, client: RestClient) = {
+    try {
+      import scala.collection.JavaConverters._
+      val indexResponse1 = client.performRequest("GET", s"/$index/_alias/*")
+      val list = JSON.parseObject(EntityUtils.toString(indexResponse1.getEntity)).keySet().asScala.toList.sorted
+      println(s"getAliases $index success .")
+      list
+    } catch {
+      case e: Exception => {
+        println(s"getAliases $index error .")
+        logError(e.getMessage, e)
+        List()
+      }
+    }
+  }
+
+  def getIndexs(index: String, client: RestClient) = {
+    try {
+      val indexResponse1 = client.performRequest("GET", s"_cat/indices/$index*?h=index")
+      val res = EntityUtils.toString(indexResponse1.getEntity)
+      val list = res.split("\\n", -1).filter(_.length > 0).toList.sorted
+      println(s"getIndexs $index success .")
+      list
+    } catch {
+      case e: Exception => {
+        println(s"getIndexs $index error .")
+        logError(e.getMessage, e)
+        List()
+      }
+    }
+  }
+
+  def deleteIndex(index: String, client: RestClient) = {
+    try {
+      val indexResponse1 = client.performRequest("DELETE", index)
+      println(EntityUtils.toString(indexResponse1.getEntity))
+      println(s"deleteIndex $index success .")
+    } catch {
+      case e: Exception => {
+        println(s"deleteIndex $index error .")
+        logError(e.getMessage, e)
+      }
+    }
+  }
+
+  def updateAliases(index: String, aliases: String, aliasesType: String, client: RestClient) = {
+    val query =
+      s"""
+         |{
+         |  "actions": [
+         |    {
+         |      "$aliasesType": {
+         |        "index": "$index",
+         |        "alias": "$aliases"
+         |      }
+         |    }
+         |  ]
+         |}
+         |""".stripMargin
+
+    try {
+      val entity = new NStringEntity(query, ContentType.APPLICATION_JSON)
+      val indexResponse = client.performRequest(
+        "POST",
+        "/_aliases/",
+        Collections.emptyMap[String, String](),
+        entity)
+      println(query)
+      println(s"updateAliases $index success .")
+    } catch {
+      case e: Exception => {
+        println(s"updateAliases $index error .")
+        logError(e.getMessage, e)
+      }
+    }
+  }
+
+  lazy val judicial_case_detail: String =
+    """
+      |{
+      |  "settings": {
+      |    "number_of_shards": 20,
+      |    "number_of_replicas": 0,
+      |    "index": {
+      |      "mapping": {
+      |        "nested_fields": {
+      |          "limit": "300"
+      |        }
+      |      },
+      |      "analysis": {
+      |        "analyzer": {
+      |          "ik_analyzer": {
+      |            "tokenizer": "ik_max_tokenizer"
+      |          }
+      |        },
+      |        "tokenizer": {
+      |          "ik_max_tokenizer": {
+      |            "type": "ik_max_word"
+      |          }
+      |        }
+      |      }
+      |    }
+      |  },
+      |  "mappings": {
+      |    "judicial": {
+      |      "properties": {
+      |         "judicase_id": {
+      |          "type": "keyword"
+      |        },
+      |        "title": {
+      |          "type": "text",
+      |          "fields": {
+      |            "keyword": {
+      |              "type": "keyword",
+      |              "ignore_above": 256
+      |            }
+      |          },"analyzer": "ik_analyzer"
+      |        },
+      |        "case_type": {
+      |          "type": "keyword"
+      |        },
+      |        "case_reason": {
+      |          "type": "keyword"
+      |        },
+      |        "case_no": {
+      |          "type": "keyword"
+      |        },
+      |        "court_name": {
+      |          "type": "keyword"
+      |        },
+      |        "case_stage": {
+      |          "type": "keyword"
+      |        },
+      |        "lable": {
+      |          "type": "keyword"
+      |        },
+      |        "detail": {
+      |          "properties": {
+      |            "flag": {
+      |              "type": "keyword"
+      |            },
+      |            "detail_id": {
+      |              "type": "keyword"
+      |            },
+      |            "date": {
+      |              "type": "date",
+      |              "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd"
+      |            },
+      |            "name": {
+      |              "type": "keyword"
+      |            }
+      |          }
+      |        },
+      |         "yg_name": {
+      |          "type": "text",
+      |          "fields": {
+      |            "keyword": {
+      |              "type": "keyword",
+      |              "ignore_above": 256
+      |            }
+      |          },"analyzer": "ik_analyzer"
+      |        },
+      |        "bg_name": {
+      |          "type": "text",
+      |          "fields": {
+      |            "keyword": {
+      |              "type": "keyword",
+      |              "ignore_above": 256
+      |            }
+      |          },"analyzer": "ik_analyzer"
+      |        },
+      |        "last_date": {
+      |          "type": "date",
+      |          "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd"
+      |        },
+      |        "deleted": {
+      |          "type": "integer"
+      |        }
+      |      }
+      |    }
+      |  }
+      |}
+      |""".stripMargin
+
+  lazy val judicial_case: String =
+    """
+      |{
+      |  "settings": {
+      |    "number_of_shards": 20,
+      |    "number_of_replicas": 0,
+      |    "index": {
+      |      "mapping": {
+      |        "nested_fields": {
+      |          "limit": "300"
+      |        }
+      |      },
+      |      "analysis": {
+      |        "analyzer": {
+      |          "ik_analyzer": {
+      |            "tokenizer": "ik_max_tokenizer"
+      |          }
+      |        },
+      |        "tokenizer": {
+      |          "ik_max_tokenizer": {
+      |            "type": "ik_max_word"
+      |          }
+      |        }
+      |      }
+      |    }
+      |  },
+      |  "mappings": {
+      |    "judicial": {
+      |      "properties": {
+      |        "title": {
+      |          "type": "text",
+      |          "fields": {
+      |            "keyword": {
+      |              "type": "keyword",
+      |              "ignore_above": 256
+      |            }
+      |          },
+      |          "analyzer": "ik_analyzer"
+      |        },
+      |        "case_type": {
+      |          "type": "keyword"
+      |        },
+      |        "case_reason": {
+      |          "type": "keyword"
+      |        },
+      |        "case_no": {
+      |          "type": "text",
+      |          "fields": {
+      |            "keyword": {
+      |              "type": "keyword",
+      |              "ignore_above": 256
+      |            }
+      |          },
+      |          "analyzer": "ik_analyzer"
+      |        },
+      |        "court_name": {
+      |          "type": "keyword"
+      |        },
+      |        "case_stage": {
+      |          "type": "keyword"
+      |        },
+      |        "lable": {
+      |          "type": "keyword"
+      |        },
+      |        "yg_name": {
+      |          "type": "text",
+      |          "fields": {
+      |            "keyword": {
+      |              "type": "keyword",
+      |              "ignore_above": 256
+      |            }
+      |          },
+      |          "analyzer": "ik_analyzer"
+      |        },
+      |        "bg_name": {
+      |          "type": "text",
+      |          "fields": {
+      |            "keyword": {
+      |              "type": "keyword",
+      |              "ignore_above": 256
+      |            }
+      |          },
+      |          "analyzer": "ik_analyzer"
+      |        },
+      |        "case_amt": {
+      |          "type": "double"
+      |        },
+      |        "date": {
+      |          "type": "date",
+      |          "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd"
+      |        },
+      |        "court_level": {
+      |          "type": "keyword"
+      |        },
+      |        "deleted": {
+      |          "type": "integer"
+      |        },
+      |        "cids": {
+      |          "type": "keyword"
+      |        }
+      |      }
+      |    }
+      |  }
+      |}
+      |""".stripMargin
+
+  def main(args: Array[String]): Unit = {
+    val client = EsQueryUtils.getClient()
+    deleteIndex("xf_test02", client)
+    //    updateAliases("xf_test02", "xf_test", "add", client)
+    //    println(getAliases("xf_test", client))
+    //EsQueryUtils.createTable("test05", EsQueryUtils.judicial_case_detail, client)
+  }
+}