UseCase
代码
func (elasticSearchClient *ElasticSearchClient) Upsert(index string, indextype string, id string, jobApplication models.JobApplication) {
client := elasticSearchClient.GetClient()
upsert, err := client.Update().
Index(index).Type(indextype).Id(id).
Script(elastic.NewScript("if(! ctx._source.jobApplications.contains(application)){ ctx._source.jobApplications += application }").
Params(map[string]interface{}{"application": jobApplication})).
Upsert(map[string]interface{}{"jobApplications": jobApplication}).
Do()
if err != nil {
fmt.Println("Error , got: %v", err.Error())
}
fmt.Println(upsert)
}
注意
错误:
错误400(错误请求):无法执行脚本 [类型= illegal_argument_exception]