dongmu3269 2017-03-13 07:30
浏览 25
已采纳

Golang错误“通话中参数不足”

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)
suresh@BLR-245:~/Desktop/tools/golang/src$ 

My Golang Code(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)
    }
}

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

  • 写回答

1条回答 默认 最新

  • douding_1073 2017-03-13 07:36
    关注

    You need to pass a context to bulkRequest.Do().

    From the olivere/elastic Github page (abbreviated);

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?