update mapping with specify type

This commit is contained in:
liugq 2023-04-18 18:16:27 +08:00
parent ca7c7d9ad6
commit c6b9f30277
1 changed files with 15 additions and 3 deletions

View File

@ -976,9 +976,21 @@ func (h *APIHandler) initIndex(w http.ResponseWriter, req *http.Request, ps http
return return
} }
} }
if len(reqBody.Mappings) > 0 { if ml := len(reqBody.Mappings); ml > 0 {
mappingBytes := util.MustToJSONBytes(reqBody.Mappings) var (
_, err = client.UpdateMapping(indexName, mappingBytes) docType = ""
mapping interface{} = reqBody.Mappings
)
if ml == 1 {
for key, _ := range reqBody.Mappings {
if key != "properties" {
docType = key
mapping = reqBody.Mappings[key]
}
}
}
mappingBytes := util.MustToJSONBytes(mapping)
_, err = client.UpdateMapping(indexName, docType, mappingBytes)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
h.WriteError(w, err.Error(), http.StatusInternalServerError) h.WriteError(w, err.Error(), http.StatusInternalServerError)