更新整个选定的弹性记录

Using olivere/elastic to connect my Go (1.10) to my Elastic search, which is running in a Docker container.

Now when the database has an update it will run a trigger to my API which should search for that record in my Elastic search, if not found add a new record or if found update the whole record.

Now I have the add new record code in place and its working but I can not see how to update the whole record, selected elements of that record I can but not the whole record.

Here is what I have:

testData := []byte(`{"data1":"22222","data2":"ddddd"}`)

script := elastic.NewScript("ctx._source = params.newCont").Params(map[string]interface{}{"newCont": testData})

put1, _ := client.Update().
                Index("myindex").
                Type("mytype").
                Id("id-here").
                Script(script).
                Do(ctx)

fmt.Println( put1 )

Now when I update _source to something like _source.data1 I can update that but I want my testData var to update all records within this id. The testData var is just for testing, I will be loading this from the database, as I have no idea what would have changed, I need the whole record updated?

Thanks.

Make sure to read the unit tests of github.com/olivere/elastic as well. E.g. update_test.go and update_integration_test.go illustrate how to do updates. Combine that the official documentation and you will become a pro with Elasticsearch very soon :-)