Olivere软件包中的BulkIndexer用于Golang替换Elastigo

时间:2018-11-22 05:26:53

标签: elasticsearch go insert

我注意到,如果要将数据批量发送到elasticsearch中,可以使用BulkIndexer。如Elastigo文档中所述

  

批量索引器创建goroutine,并创建通道,用于使用缓冲区批量连接数据并将数据发送到elasticsearch。

elastigo中的代码以批量插入

var c_es = elastigo.NewConn()
var indexer = c_es.NewBulkIndexer(50)

func insertInBulkElastic(){
    //Create a custom error function when inserting data into elasticsearch 
   //in bulk
    indexer.Sender = func(buf *bytes.Buffer) error {
    // @buf is the buffer of docs about to be written
    respJson, err := c_es.DoCommand("POST", "/_bulk", nil, buf)
    if err != nil {
        // handle it better than this

        fmt.Println("Error", string(respJson)) // 

        fmt.Println("Error", err)
    }

    if err == nil {
        fmt.Println("The data was inserted successfullly to elastic search")
    }
    return err
  }



}

有人知道如何使用Olivere发送Golang批量请求吗?

谢谢

1 个答案:

答案 0 :(得分:2)

这是在Go中使用const BbDescriptionDictionary = ['AAA' , 'BBB', 'CCC',] this.boardBasisOptionsWithDescriptions = this.boardBasisOptions.map((key, index) => ({ key, value: BbDescriptionDictionary[index] }) 的有效示例。您可以了解有关BulkProcessor here

的更多信息

希望获得帮助:)

olivere