gpt4 book ai didi

elasticsearch - 在 google go 中使用 olivere/elastic 更新 ElasticSearch 中的记录

转载 作者:IT王子 更新时间:2023-10-29 01:16:41 27 4
gpt4 key购买 nike

我正在使用 go 在 Elasticsearch 中插入一条记录,如下所述:https://github.com/olivere/elastic现在,如果我必须部分更新它(假设只有一个条目如“名称”),那么我想使用更新 API。我找不到任何描述如何在 oilvere/elastic 中使用此 API/函数的文档。我想知道是否有人以前使用过这个并且可以帮助我。

最佳答案

所以,我终于让这个东西工作了。这是我用来完成它的代码。

update, err := client.Update().Index("test3").Type("user").Id("2").Doc(map[string]interface{}{"location": message}).Do()
fmt.Println("updated id: ", update.Id)

这对我来说很好。

我尝试了另一种方法来更新它,但它不起作用。我将其张贴在这里,以便人们可以查看和检查。事情是这样的。

update := client.Update().Index("test3").Type("user").Id("2").Script(elastic.NewScript("ctx._source.location = loc").Params(map[string]interface{}{"loc": message}).Lang("groovy"))
fmt.Println("updated id: ", update.Id)

希望这对某人有帮助!

关于elasticsearch - 在 google go 中使用 olivere/elastic 更新 ElasticSearch 中的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37989555/

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