fix opensearch mapper_parsing_exception
karmada-search error log: Could not dynamically add mapping for field [app.name]. Existing mapping for [metadata.labels.app] must be of type object but found [text]. Co-authored-by: liys87x <liyasong1987x@gmail.com> Signed-off-by: huntsman_ly <huntsman_ly@sina.com>
This commit is contained in:
parent
79992fe222
commit
b4c86a26df
|
@ -41,7 +41,8 @@ var mapping = `
|
|||
"metadata":{
|
||||
"properties":{
|
||||
"annotations":{
|
||||
"type": "flattened"
|
||||
"type":"object",
|
||||
"enabled":false
|
||||
},
|
||||
"creationTimestamp":{
|
||||
"type":"text"
|
||||
|
@ -50,7 +51,8 @@ var mapping = `
|
|||
"type":"text"
|
||||
},
|
||||
"labels":{
|
||||
"type": "flattened"
|
||||
"type":"object",
|
||||
"enabled":false
|
||||
},
|
||||
"name":{
|
||||
"type":"text",
|
||||
|
@ -71,7 +73,7 @@ var mapping = `
|
|||
}
|
||||
},
|
||||
"ownerReferences":{
|
||||
"type": "flattened"
|
||||
"type":"text"
|
||||
},
|
||||
"resourceVersion":{
|
||||
"type":"text",
|
||||
|
@ -82,13 +84,15 @@ var mapping = `
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"spec":{
|
||||
"type": "flattened"
|
||||
"type":"object",
|
||||
"enabled":false
|
||||
},
|
||||
"status":{
|
||||
"type": "flattened"
|
||||
}
|
||||
"type":"object",
|
||||
"enabled":false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -232,7 +236,7 @@ func (os *OpenSearch) indexName(us *unstructured.Unstructured) (string, error) {
|
|||
os.l.Lock()
|
||||
defer os.l.Unlock()
|
||||
|
||||
if _, ok := os.indices[name]; !ok {
|
||||
if _, ok := os.indices[name]; ok {
|
||||
return name, nil
|
||||
}
|
||||
|
||||
|
@ -240,19 +244,23 @@ func (os *OpenSearch) indexName(us *unstructured.Unstructured) (string, error) {
|
|||
res := opensearchapi.IndicesCreateRequest{Index: name, Body: strings.NewReader(mapping)}
|
||||
resp, err := res.Do(context.Background(), os.client)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "already exists") {
|
||||
klog.V(4).Info("index already exists")
|
||||
if strings.Contains(err.Error(), "resource_already_exists_exception") {
|
||||
klog.Info("index already exists")
|
||||
os.indices[name] = struct{}{}
|
||||
return name, nil
|
||||
}
|
||||
return name, fmt.Errorf("cannot create index: %v", err)
|
||||
}
|
||||
if resp.IsError() {
|
||||
return name, fmt.Errorf("cannot create index: %v", resp.String())
|
||||
if strings.Contains(resp.String(), "resource_already_exists_exception") {
|
||||
klog.Info("index already exists")
|
||||
os.indices[name] = struct{}{}
|
||||
return name, nil
|
||||
}
|
||||
return name, fmt.Errorf("cannot create index (resp): %v", resp.String())
|
||||
}
|
||||
|
||||
klog.V(4).Infof("create index response: %s", resp.String())
|
||||
|
||||
klog.Infof("create index response: %s", resp.String())
|
||||
os.indices[name] = struct{}{}
|
||||
|
||||
return name, nil
|
||||
|
|
Loading…
Reference in New Issue