-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update
Oliver Eilhard edited this page Feb 13, 2018
·
5 revisions
The Update
service allows you to update documents.
// Update a tweet by the update API of Elasticsearch.
// We just increment the number of retweets.
ctx := context.Background()
update, err := client.Update().Index("twitter").Type("tweet").Id("1").
Script("ctx._source.retweets += num").
ScriptParams(map[string]interface{}{"num": 1}).
Upsert(map[string]interface{}{"retweets": 0}).
Do(ctx)
if err != nil {
// Handle error
panic(err)
}
fmt.Printf("New version of tweet %q is now %d", update.Id, update.Version)