gpt4 book ai didi

Elasticsearch CreateIndex() 参数不足

转载 作者:数据小太阳 更新时间:2023-10-29 03:43:15 26 4
gpt4 key购买 nike

我正在尝试将 Elasticsearch for GO 与这个著名的 repo 结合使用

但是,当我尝试创建一个 index(docs,并作为示例给出 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)
}

我收到以下错误,我不明白:

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

这是为什么呢?我在这里想念什么?

最佳答案

IndicesCreateService.Do() function期望传递 context.Context

因此,您需要导入 "golang.org/x/net/context" 然后将调用更改为:

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

您还可以检查 indices_create_test.go测试用例以了解它是如何完成的。

关于Elasticsearch CreateIndex() 参数不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40610757/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com