Using gopkg.in/olivere/elastic.v5 for adding a field to a document in elasticsearch Code:
script := elastic.NewScript(`ctx._source.new_field += params.vijay`).Param("vijay", "kumar").p
//script := elastic.NewScript("ctx._source.retweets += params.num").Param("num", 1)
fmt.Println("script", script)
update, err := client.Update().Index("idx001").Type("sdoc").Id(t.Docid).Script(script).Do(ctx)
if err != nil {
// Handle error
panic(err)
}
fmt.Println("result is", update.Result)
And the result got is(here i am printing the script formed also)
script &{ctx._source.new_field += params.vijay map[vijay:kumar]} panic: elastic: Error 400 (Bad Request): failed to execute script [type=illegal_argument_exception]
Expected the field vijay to be added into elasticsearch with the value kumar