You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
jfcantu edited this page May 31, 2020
·
5 revisions
The Update service allows you to update documents.
v3 and above:
ctx:=context.Background()
update, err:=client.Update().Index("twitter").Type("tweet").Id("1").
Script(elastic.NewScript("ctx._source.retweets += params.num").Param("num", 1)).
Upsert(map[string]interface{}{"retweets": 0}).
Do(ctx)
iferr!=nil {
// Handle errorpanic(err)
}
fmt.Printf("New version of tweet %q is now %d", update.Id, update.Version)
Prior to v3:
// 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)
iferr!=nil {
// Handle errorpanic(err)
}
fmt.Printf("New version of tweet %q is now %d", update.Id, update.Version)