Golang error “not enough arguments in call”

(sandeep kumar) #1

Hi all, I’m new to golang. Trying to implement a bulk upload to Elasticsearch by golang. I’m using golang library -> https://github.com/olivere/elastic for communication with Elasticsearch.

Also, a piece of sample code which I’m trying but getting following error…

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)

My Golang Code(main.go)

package main

import (

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++ {
            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 {
        if bulkResponse != nil {


Anybody, help me to understand what that error means & how to solve those?

(Curtis Allyn Green) #2

As the error message tells you, the Do method on your Bulk service requires a context.Context parameter.

You can read about context.Context here:

GoDoc is an incredibly useful tool that has documentation on nearly every package you’ll come across. It will help you out of the those tight spots.