package elastic import ( "context" "eta/eta_index_lib/models" "eta/eta_index_lib/utils" "fmt" ) // EsAddOrEditEdbInfoData 新增/修改es中的指标数据 func EsAddOrEditEdbInfoData(indexName, docId string, item *models.EdbInfoList) (err error) { defer func() { if err != nil { fmt.Println("EsAddOrEditData Err:", err.Error()) } }() client := utils.EsClient if err != nil { return } resp, err := client.Index().Index(indexName).Id(docId).BodyJson(item).Do(context.Background()) if err != nil { fmt.Println("新增失败:", err.Error()) return err } fmt.Println(resp) if resp.Status == 0 { fmt.Println("新增成功", resp.Result) err = nil } else { fmt.Println("AddData", resp.Status, resp.Result) } return } // EsAddOrEditDataSourceIndex 新增/修改es中的数据源指标 func EsAddOrEditDataSourceIndex(indexName, docId string, item *models.SearchDataSource) (err error) { fmt.Println("索引名:", indexName) 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).Refresh("true").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 }