戈朗错误"not enough arguments in call"



我是Golang的新手。试图实施Golang的批量上传到Elasticsearch。我正在使用Golang库 -> https://github.com/olivere/lastic与Elasticsearch进行通信。

另外,我正在尝试但要遵循错误的示例代码...

suresh@BLR-245:~/Desktop/tools/golang/src$ go install github.com/crazyheart/elastic-bulk-upload
# github.com/crazyheart/elastic-bulk-upload
github.com/crazyheart/elastic-bulk-upload/main.go:29: not enough arguments in call to bulkRequest.Do
    have ()
    want ("golang.org/x/net/context".Context)
suresh@BLR-245:~/Desktop/tools/golang/src$ 

我的golang代码(main.go)

package main
import (
    "fmt"
    "gopkg.in/olivere/elastic.v5"
    "strconv"
)
type Tweet struct {
    User    string `json:"user"`
    Message string `json:"message"`
}
func main() {
    client, err := elastic.NewClient()
    if err != nil {
        fmt.Println("%v", err)
    }
    n := 0
    for i := 0; i < 1000; i++ {
        bulkRequest := client.Bulk()
        for j := 0; j < 10000; j++ {
            n++
            tweet := Tweet{User: "olivere", Message: "Package strconv implements conversions to and from string representations of basic data types. " + strconv.Itoa(n)}
            req := elastic.NewBulkIndexRequest().Index("twitter").Type("tweet").Id(strconv.Itoa(n)).Doc(tweet)
            bulkRequest = bulkRequest.Add(req)
        }
        bulkResponse, err := bulkRequest.Do()
        if err != nil {
            fmt.Println(err)
        }
        if bulkResponse != nil {
        }
        fmt.Println(i)
    }
}

任何人,帮助我了解该错误的含义&amp;如何解决这些?

您需要将上下文传递给bulkrequest.do()。

来自Olivere/弹性Github页面(缩写);

// Create a context ctx := context.Background() bulkRequest.Do(ctx)

相关内容

最新更新