From c6b9f30277addf0edc10c9dcaa5a2326955bcf8a Mon Sep 17 00:00:00 2001 From: liugq Date: Tue, 18 Apr 2023 18:16:27 +0800 Subject: [PATCH] update mapping with specify type --- plugin/migration/api.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/plugin/migration/api.go b/plugin/migration/api.go index 37caaf62..7a30d8af 100644 --- a/plugin/migration/api.go +++ b/plugin/migration/api.go @@ -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)