Created
September 23, 2018 11:29
-
-
Save adityakrshnn/d4515d9d47de8097d1141ffeb8d38ebf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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