弹性搜索CreateIndex()没有足够的参数 [英] Elasticsearch CreateIndex() not enough arguments

查看:280
本文介绍了弹性搜索CreateIndex()没有足够的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Elasticsearch GO与这个着名的 repo

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

但是,当我尝试创建一个索引 docs ,并给出了一个例子 here ):

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:


没有足够的参数调用client.CreateIndex(events)。

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

为什么?我想念什么?

推荐答案

IndicesCreateService.Do()函数需要一个 context.Context 要通过

所以,你需要导入golang.org/x/net/context / code>,然后更改您的电话:

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

您还可以查看 indices_create_test.go 测试用例,以查看它是如何完成。

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

这篇关于弹性搜索CreateIndex()没有足够的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆