package elastic import ( "context" dataSourceModel "eta/eta_task/models/data_source" "eta/eta_task/utils" "fmt" ) // EsAddOrEditDataSourceIndex 新增/修改es中的数据源指标 func EsAddOrEditDataSourceIndex(indexName, docId string, item *dataSourceModel.SearchDataSource) (err error) { defer func() { if err != nil { tips := fmt.Sprintf("EsAddOrEditDataSourceIndex err: %v", err) utils.FileLog.Info(tips) } }() client := utils.EsClient resp, e := client.Index().Index(indexName).Id(docId).BodyJson(item).Do(context.Background()) if e != nil { err = fmt.Errorf("resp err, %v", e) return } if resp.Status != 0 { err = fmt.Errorf("result err, status: %d, result: %s", resp.Status, resp.Result) return } err = nil fmt.Println("data source write to es success", resp.Result) return }