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
}
