Skip to content

Instantly share code, notes, and snippets.

@adityakrshnn
Created September 23, 2018 11:29
Show Gist options
  • Save adityakrshnn/d4515d9d47de8097d1141ffeb8d38ebf to your computer and use it in GitHub Desktop.
Save adityakrshnn/d4515d9d47de8097d1141ffeb8d38ebf to your computer and use it in GitHub Desktop.
func incrementVote(index, Type, id string) bool {
client, _ := elastic.NewSimpleClient(elastic.SetURL("http://00.00.00.00:0000"),
elastic.SetErrorLog(log.New(os.Stderr, "ELASTIC ", log.LstdFlags)),
elastic.SetInfoLog(log.New(os.Stdout, "", log.LstdFlags)))
ctx := context.Background()
script := elastic.NewScript("ctx._source.votes+=1")
_, err := elastic.NewUpdateService(client).Index(index).Type(Type).Id(id).Script(script).Do(ctx)
if err != nil {
fmt.Println(err)
return false
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment