在Google中使用olivere / elastic更新ElasticSearch中的记录 [英] Updating a record in ElasticSearch using olivere/elastic in google go

查看:2456
本文介绍了在Google中使用olivere / elastic更新ElasticSearch中的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在弹性搜索中插入一条记录,如下所述: https://github.com/olivere/弹性
现在,如果我必须部分更新它(假设只有一个条目像'name'),那么我想使用UPDATE API。我找不到任何他们描述如何使用这个API /函数在有油/弹性的任何文档。我想知道是否有人使用过,并可以帮助我。

I am inserting a record in elastic search using go as stated here: https://github.com/olivere/elastic Now , if i have to partially update it(suppose if just one entry like 'name'), then i want to use UPDATE API. I cannot find any any documentation where they describe how to use this API/function in oilvere/elastic. I wonder if someone has used this before and could help me in this.

推荐答案

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

So, I finally got this thing working. Here is the code that i used to get it done.

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

这对我来说很好。

我尝试了另一种方法来更新它,但它不起作用。我在这里发布它,以便人们可以查看它并进行检查。这是类似的东西。

I tried another approach to update it but it wasn't working. I am posting it here so one can view it and check. It was something like this.

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)

希望这有助于某人!

这篇关于在Google中使用olivere / elastic更新ElasticSearch中的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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