kobe6258 4 ماه پیش
والد
کامیت
f267b8bcd8
3فایلهای تغییر یافته به همراه55 افزوده شده و 5 حذف شده
  1. 9 5
      common/component/es/es.go
  2. 45 0
      controllers/web_hook/es_controller.go
  3. 1 0
      routers/router.go

+ 9 - 5
common/component/es/es.go

@@ -646,11 +646,15 @@ func (es *ESClient) Update(indexName string, id int, doc interface{}) bool {
 // indexName 索引名
 // id es的id
 // */
-func (es *ESClient) Delete(indexName string, id int) bool {
-	req := esapi.DeleteRequest{
-		Index:      indexName,
-		DocumentID: strconv.Itoa(id),
-		Refresh:    "true",
+func (es *ESClient) Delete(indexName string, query interface{}) bool {
+	jsonQuery, _ := json.Marshal(query)
+	refresh := new(bool)
+	*refresh = true
+	logger.Info("查询语句: %s", string(jsonQuery))
+	req := esapi.DeleteByQueryRequest{
+		Index:   []string{indexName},
+		Body:    strings.NewReader(string(jsonQuery)),
+		Refresh: refresh,
 	}
 	res, err := req.Do(context.Background(), es.es())
 	defer res.Body.Close()

+ 45 - 0
controllers/web_hook/es_controller.go

@@ -0,0 +1,45 @@
+package web_hook
+
+import (
+	"eta/eta_mini_ht_api/common/component/es"
+	"eta/eta_mini_ht_api/controllers"
+)
+
+type ESController struct {
+	controllers.WebHookController
+}
+
+func elastic() *es.ESClient {
+	return es.GetInstance()
+}
+
+//// DeleteEsData  删除es数据
+//// @Summary 删除es数据
+//// @Description 删除es数据
+//// @Success 200 {object} controllers.BaseResponse
+//// @router /es/delete/ [post]
+//func (h *ESController) DeleteEsData() {
+//	controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) {
+//		result = h.InitWrapData("删除成功")
+//		ids := []int{10605, 10636, 10637, 10638, 10648, 10794, 10839, 10899, 10903, 11002, 11082, 11127, 11276, 11277, 11279, 11280, 11281, 11283, 11284, 11285, 11286, 11287, 11288, 11290, 11291, 11292, 11293, 11303, 11308, 11313, 11314, 11315, 11316, 11321, 11322, 11323, 11328, 11348, 11357, 11395, 11396, 11408, 11409, 11410, 11411, 11419, 11420, 11441, 11452, 11453, 11458, 11459, 11460, 11463, 11464, 11465, 11466, 11474, 11484, 11486, 11487, 11489, 11490, 11494, 11496, 11500, 11501, 11502, 11504, 11505, 11510, 11511, 11512, 11513, 11514, 11517, 11518, 11519, 11521, 11522, 11523, 11524, 11525, 11528, 11529, 11530, 11531, 11532, 11533, 11534, 11536, 11537, 11540, 11542, 11544, 11545, 11546, 11547, 11548, 11549, 11550, 11551, 11552, 11556, 11558, 11559, 11560, 11561, 11563, 11568, 11569, 11570, 11571, 11574, 11575, 11577, 11579, 11583, 11584, 11589, 11592, 11594, 11600, 11601, 11602, 11603, 11604, 11605, 11606, 11607, 11608, 11609, 11610, 11612, 11613, 11614, 11615, 11616, 11621, 11623, 11624, 11626, 11629, 11630, 11631, 11633, 11634, 11635, 11636, 11639, 11640, 11641, 11642, 11648, 11659, 11660, 11667, 11670, 11671, 11672, 11685, 11687, 11688, 11701, 11705, 11707, 11709, 11710, 11711, 11712, 11713, 11714, 11715, 11716, 11717, 11722, 11724, 11725, 11729, 11730, 11735, 11736, 11737, 11738, 11739, 11741, 11742, 11743}
+//		var idsStr []string
+//		for _, id := range ids {
+//			idsStr = append(idsStr, strconv.Itoa(id))
+//		}
+//		query := map[string]interface{}{
+//			"query": map[string]interface{}{
+//				"bool": map[string]interface{}{
+//					"must": []map[string]interface{}{
+//						{"match": map[string]interface{}{"source": "ETA"}},
+//					},
+//					"must_not": []map[string]interface{}{
+//						{"terms": map[string]interface{}{"_id": idsStr}},
+//					},
+//				},
+//			},
+//		}
+//		elastic().Delete("ht_test_report_v1", query)
+//		h.SuccessResult("success", nil, result)
+//		return
+//	})
+//}

+ 1 - 0
routers/router.go

@@ -71,6 +71,7 @@ func init() {
 			web.NSInclude(
 				&web_hook.HTFuturesAccountController{},
 				&web_hook.HTFuturesTradeController{},
+				&web_hook.ESController{},
 			),
 		),
 		web.NSNamespace("/product",