Updating a record in ElasticSearch using olivere/elastic in google go

olivere/elastic example
go-elasticsearch vs olivere
olivere/elastic vs go-elasticsearch
golang elasticsearch query builder
best golang elasticsearch client
golang olivere/elastic example
olivere/elastic v7
go query elasticsearch

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)

This is working fine for me.

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)

Hope this helps someone!

olivere/elastic: Elasticsearch client for Go., client for Go. Contribute to olivere/elastic development by creating an account on GitHub. Elasticsearch client for Go. https://olivere.github.io/elastic/ · elasticsearch go cluster-test · Clean up, GitHub actions, Go update, and more, 2 months ago query.go · Prepare for Elasticsearch 5.0 (wip), 4 years ago. reindex.go  If you want to use stable versions of Elastic, please use Go modules for the 7.x release (or later) or a dependency manager like dep for earlier releases. Elastic is an Elasticsearch client for the Go programming language.


If you're using github.com/olivere/elastic always check the unit tests. They not only serve as a safety net for changes but also illustrate how to use the library. E.g. update_test.go and update_integration_test.go come with a list of examples how to use the syntax explained in the documentation.

Elastic: An Elasticsearch client for Go, Elastic is an Elasticsearch client for the Go programming language (Golang). You must use an import path of github.com/olivere/elastic/v7 . Notice that you  Elasticsearch client for Go. Contribute to olivere/elastic development by creating an account on GitHub. Using with AWS Elasticsearch Service Update; Using


If you want to use scripts, here is an example of conditional update:

_, err := client.UpdateByQuery(). Query(query). Index(index). Script(elastic.NewScript("ctx._source = tag").Params(map[string]interface{}{"tag": doc}).Lang("groovy")). Type(docType).IgnoreUnavailable(true). Do(ctx)

index is your ES index name in which the document resides. query has all the necessary conditions(eg: update the doc only if age>18). For more knowledge on queries, please refer here. The output of query will be available in ctx.source, which here i am setting to the params i passed. You can also do something like: "ctx.source.salary = sal" in that case sal will be one of the params you will pass dynamically. I hope, it helps.

update.go - olivere/elastic, Use of this source code is governed by a MIT-license. "net/url". "strings". "​golang.org/x/net/context" UpdateService updates a document in Elasticsearch. if the entire record is exactly the same when the dup occurs, you can take an MD5 hash of the record and use it as the value of the id, instead of using UUID for example. When you index the data, use this MD5 hash as the id and pass it to ES along with the document (or record) to be indexed.


elastic, Today, I am going to show Elasticsearch implementation in Go. Elasticsearch is a NoSQL database that has been very successful in tackling those issues. By the time I am writing this article, I will be using Elasticsearch with the version number of 7.4.2 . "fmt"elastic "gopkg.in/olivere/elastic.v7" Hi, I need to update all the value of the keys named as "per_name" (key is the document Json key:value pair entry ) in all the documents in all the indexes present in my Elastic Search . I have an update curl which tak…


Elasticsearch in Go - Pramono Winata, How To Index Elasticsearch Documents Using The Olivere Golang Driver. Written by Data Pilot. July 22, 2019. Elasticsearch; Golang. Subscribe. Like  Updating data fields. Elasticsearch. afonso.ribeiro October 12, 2017, 4:35pm #1. Hello guys, I want to update a field in elasticsearch but with a condition. In sql it


How To Index Elasticsearch Documents Using The Olivere Golang , Elasticsearch is one of the most popular highly scalable full-text search In this post I'll demonstrate on example how to index and search for application logs using Go. As a storage it allows you to execute CRUD (create, read, update, package main import ( "errors" "fmt" "gopkg.in/olivere/elastic.v3"  Elastic is a client for Elasticsearch for the Go programming language. We use it in production since 2012. We use it in production since 2012. It supports Elasticsearch versions 1.x, 2.x, 5.x, 6.x and 7.x.