es_controller.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package web_hook
  2. import (
  3. "eta/eta_mini_ht_api/common/component/es"
  4. "eta/eta_mini_ht_api/controllers"
  5. "strings"
  6. )
  7. type ESController struct {
  8. controllers.WebHookController
  9. }
  10. func elastic() *es.ESClient {
  11. return es.GetInstance()
  12. }
  13. type DeleteIndex struct {
  14. IndexName string `json:"indexName"`
  15. Source string `json:"source"`
  16. Ids string `json:"ids"`
  17. }
  18. // DeleteEsData 删除es数据
  19. // @Summary 删除es数据
  20. // @Description 删除es数据
  21. // @Success 200 {object} controllers.BaseResponse
  22. // @router /es/delete/ [post]
  23. func (h *ESController) DeleteEsData() {
  24. controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) {
  25. result = h.InitWrapData("删除成功")
  26. req := new(DeleteIndex)
  27. h.GetPostParams(req)
  28. //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}
  29. var idsStr []string
  30. //for _, id := range req.Ids {
  31. // idsStr = append(idsStr, strconv.Itoa(id))
  32. //}
  33. idsStr = strings.Split(req.Ids, ",")
  34. query := map[string]interface{}{
  35. "query": map[string]interface{}{
  36. "bool": map[string]interface{}{
  37. "must": []map[string]interface{}{
  38. {"match": map[string]interface{}{"source": req.Source}},
  39. },
  40. "must_not": []map[string]interface{}{
  41. {"terms": map[string]interface{}{"_id": idsStr}},
  42. },
  43. },
  44. },
  45. }
  46. elastic().Delete(req.IndexName, query)
  47. h.SuccessResult("success", nil, result)
  48. return
  49. })
  50. }