类目更新接口修改,三个平台同时更新-->只修改传入的平台的类目
This commit is contained in:
parent
ce1261dcbf
commit
d52c24edf5
@ -527,13 +527,30 @@ func (svc *BookService) UpdateBookCatIdByISBNHandler(request *request.BookUpdate
|
||||
return nil, fmt.Errorf("没有有效的更新字段")
|
||||
}
|
||||
|
||||
// 构建更新脚本,只更新传入的字段,保留现有字段
|
||||
var scriptParts []string
|
||||
params := make(map[string]interface{})
|
||||
|
||||
// 转换为 map 以便访问
|
||||
newCatId, ok := catIdValue.(map[string]interface{})
|
||||
if ok {
|
||||
for key, value := range newCatId {
|
||||
scriptParts = append(scriptParts, fmt.Sprintf("ctx._source.cat_id.%s = params.%s;", key, key))
|
||||
params[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
if len(scriptParts) == 0 {
|
||||
return nil, fmt.Errorf("没有有效的 cat_id 字段")
|
||||
}
|
||||
|
||||
script := strings.Join(scriptParts, " ")
|
||||
|
||||
body := map[string]interface{}{
|
||||
"script": map[string]interface{}{
|
||||
"source": "ctx._source.cat_id = params.cat_id;",
|
||||
"source": script,
|
||||
"lang": "painless",
|
||||
"params": map[string]interface{}{
|
||||
"cat_id": catIdValue,
|
||||
},
|
||||
"params": params,
|
||||
},
|
||||
"query": map[string]interface{}{
|
||||
"term": map[string]interface{}{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user