From 2f80e0485d7ef83cc08cbfaceeaf346171c44835 Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期五, 26 七月 2019 13:38:37 +0800
Subject: [PATCH] add GetDbpersonsId

---
 EsApi.go |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/EsApi.go b/EsApi.go
index 850fdf5..246b57a 100644
--- a/EsApi.go
+++ b/EsApi.go
@@ -300,4 +300,53 @@
         capturetable = append(capturetable, source["id"].(string))
     }
     return capturetable
+}
+
+//鑾峰彇搴曞簱浜哄憳ID
+func GetDbpersonsId(compareArgs  protomsg.CompareArgs,indexName string, serverIp string, serverPort string) (source map[string][]string) {
+    queryStr := ""
+    queryBody := compareArgs.InputValue
+    //妫�绱㈡
+    if queryBody != "" {
+        queryStr = "\"must\":[{\"multi_match\":{\"query\":\"" + queryBody + "\",\"fields\":[\"personName^1.5\",\"age^1.5\",\"idCard^1.5\",\"phoneNum^1.5\",\"sex^2.0\",\"reserved^2.0\"]," +
+            "\"type\":\"cross_fields\",\"operator\":\"OR\",\"slop\":0,\"prefix_length\":0,\"max_expansions\":50,\"zero_terms_query\":\"NONE\",\"auto_generate_synonyms_phrase_query\":true,\"fuzzy_transpositions\":true,\"boost\":1}}],"
+    }
+    //鍒ゆ柇搴撹〃ID
+    tableId := compareArgs.Tabs
+    esTableId := ""
+    esTableIdStr := ""
+    if tableId != nil && len(tableId) > 0 {
+        esTableId = strings.Replace(strings.Trim(fmt.Sprint(tableId), "[]"), " ", "\",\"", -1)
+        esTableIdStr = "{\"terms\":{\"tableId\":[\"" + esTableId + "\"]}}"
+    }
+
+    prama := "{" +
+        "\"size\":\"100000000\"," +
+        "\"query\":{\"bool\":{" + queryStr +
+        "\"filter\":[" +
+        esTableIdStr +
+        "]}}," +
+        "\"_source\":[\"id\",\"tableId\"]" +
+        "}"
+
+    url := "http://" + serverIp + ":" + serverPort +
+        "/" + indexName + "/_search?search_type=dfs_query_then_fetch"
+    fmt.Println(url)
+    fmt.Println(prama)
+    buf, err := EsReq("POST", url,[]byte(prama))
+    if err != nil {
+        fmt.Println("http request videoUrlInfo info is err!")
+        return
+    }
+    sources, err := Sourcelist(buf)
+    if err != nil {
+        return
+    }
+    tabsource := make(map[string][]string)
+    for _, source := range  sources{
+        tableId := source["tableId"].(string)
+        id := source["id"].(string)
+        tabsource[tableId] = append(tabsource[tableId], id)
+    }
+    return tabsource
 }
\ No newline at end of file

--
Gitblit v1.8.0