dongyi9082 2016-11-15 13:14
浏览 262
已采纳

Elasticsearch CreateIndex()参数不足

I am trying to use Elasticsearch for GO with this well-known repo

However, when I am trying to create an index (docs, and also given as an example here):

    // Define an elastic client 
    client, err := elastic.NewClient(elastic.SetURL("host1"))
    if err != nil {
        client, err := elastic.NewClient(elastic.SetURL("host2"))
        if err != nil {
            fmt.Println("Error when connecting Elasticsearch host");    
        }
    }

    // Create an index
    _, err = client.CreateIndex("events").Do()
    if err != nil {
        fmt.Println("Error when creating Elasticsearch index"); 
        panic(err)
    }

I got the following error, which I do not understand:

not enough arguments in call to client.CreateIndex("events").Do

Why is that? What do I miss here?

  • 写回答

1条回答 默认 最新

  • douyanzhou1450 2016-11-15 13:22
    关注

    The IndicesCreateService.Do() function expects a context.Context to be passed.

    So, you need to import "golang.org/x/net/context" and then change your call to this:

    import (
        ... your other imports...    
        "golang.org/x/net/context"
    )
    ...
    _, err := client.CreateIndex("events").Do(context.TODO())
                                                    ^
                                                    |
                                                 add this
    

    You can also check the indices_create_test.go test case in order to see how it's done.

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

报告相同问题?

悬赏问题

  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线