Merge pull request 'update mapping with specify type' (#67) from fix_initindex into master

This commit is contained in:
silenceqi 2023-04-18 18:17:34 +08:00
commit 0038930c63
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
}
}
if len(reqBody.Mappings) > 0 {
mappingBytes := util.MustToJSONBytes(reqBody.Mappings)
_, err = client.UpdateMapping(indexName, mappingBytes)
if ml := len(reqBody.Mappings); ml > 0 {
var (
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 {
log.Error(err)
h.WriteError(w, err.Error(), http.StatusInternalServerError)