I try to update my database of elasticsearch with golang.I have two functions :
func UpdateAllByUserID(client *elastic.Client, id string, requestName string, requestNick string) error {
ctx := context.Background()
query := elastic.NewMatchQuery("user_id", id)
out_name, err := client.UpdateByQuery().Index("test").Type("test").Query(query).Script(elastic.NewScriptInline("ctx._source.user_name = '" + requestName + "'")).Do(ctx)
if nil != err {
log.Println(err)
}
fmt.Println("update all name: ", out_name.Updated)
return nil
}
func UpdateAllNicksByUserIdInFeed(client *elastic.Client, id string, requestNick string) error {
ctx := context.Background()
query := elastic.NewMatchQuery("user_id", id)
out_nick, err := client.UpdateByQuery().Index("test").Type("test").Query(query).Script(elastic.NewScriptInline("ctx._source.user_nick = '" + requestNick + "'")).Do(ctx)
if nil != err {
log.Println(err)
}
fmt.Println("update all nick: ", out_nick.Updated)
return nil
}
The POST in elastic:
POST {index}/{type}/_update_by_query
{
"script": {
"inline": "ctx._source.user_name = 'test'",
"inline": "ctx._source.user_nick = 'test test'"
},
"query": {
"match": {
"user_id": "mtJZngDOy6Qj22Qv9MEf1MhSLVb2"
}
}
}
I'm using the library github.com/olivere/elastic. The versión of elasticsearch is 5.6 This functions per separate it works well, but I have two problems:
How can update in the same function? Why then use the two functions at the same time I have this error:
elastic: Error 409 (Conflict)