golang 操作es批量删除 NewDeleteByQueryService
var Client *elastic.Client var host = "http://XXX.XX.XX.XXX:9200" type ES struct { Index string Type string } // 初始化 func init() { errorLog := log.New(os.Stdout, "APP", log.LstdFlags) var err error Client, err = elastic.NewClient(elastic.SetErrorLog(errorLog), elastic.SetURL(host)) if err != nil { log.Fatalf("请检查是否连接vpn"+"\n", err) } info, code, err := Client.Ping(host).Do(context.Background()) if err != nil { panic(err) } log.Printf("Elasticsearch returned with code %d and version %s\n", code, info.Version.Number) esVersion, err := Client.ElasticsearchVersion(host) if err != nil { panic(err) } log.Printf("Elasticsearch version %s\n", esVersion) } func delData() { es := tool.ES{ Index: "XXXX.XX.XX", Type: "XXXXXXXXX", } var delQuery elastic.Query delQuery = elastic.NewMatchPhraseQuery("tradeDate", "2019-06-05") res, err := elastic.NewDeleteByQueryService(Client). Index(es.Index). Type(es.Type). Query(delQuery). Do(context.Background()) if err != nil { println(err.Error()) return } fmt.Printf(string(res.Total)) }