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
|
@ -24,74 +24,78 @@ var defaultPrefix = "kubernetes"
|
||||||
|
|
||||||
var mapping = `
|
var mapping = `
|
||||||
{
|
{
|
||||||
"settings": {
|
"settings":{
|
||||||
"index": {
|
"index":{
|
||||||
"number_of_shards": 1,
|
"number_of_shards":1,
|
||||||
"number_of_replicas": 0
|
"number_of_replicas":0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mappings": {
|
"mappings":{
|
||||||
"properties": {
|
"properties":{
|
||||||
"apiVersion": {
|
"apiVersion":{
|
||||||
"type": "text"
|
"type":"text"
|
||||||
},
|
},
|
||||||
"kind": {
|
"kind":{
|
||||||
"type": "text"
|
"type":"text"
|
||||||
},
|
},
|
||||||
"metadata": {
|
"metadata":{
|
||||||
"properties": {
|
"properties":{
|
||||||
"annotations": {
|
"annotations":{
|
||||||
"type": "flattened"
|
"type":"object",
|
||||||
},
|
"enabled":false
|
||||||
"creationTimestamp": {
|
},
|
||||||
"type": "text"
|
"creationTimestamp":{
|
||||||
},
|
"type":"text"
|
||||||
"deletionTimestamp": {
|
},
|
||||||
"type": "text"
|
"deletionTimestamp":{
|
||||||
},
|
"type":"text"
|
||||||
"labels": {
|
},
|
||||||
"type": "flattened"
|
"labels":{
|
||||||
},
|
"type":"object",
|
||||||
"name": {
|
"enabled":false
|
||||||
"type": "text",
|
},
|
||||||
"fields": {
|
"name":{
|
||||||
"keyword": {
|
"type":"text",
|
||||||
"type": "keyword",
|
"fields":{
|
||||||
"ignore_above": 256
|
"keyword":{
|
||||||
}
|
"type":"keyword",
|
||||||
}
|
"ignore_above":256
|
||||||
},
|
}
|
||||||
"namespace": {
|
}
|
||||||
"type": "text",
|
},
|
||||||
"fields": {
|
"namespace":{
|
||||||
"keyword": {
|
"type":"text",
|
||||||
"type": "keyword",
|
"fields":{
|
||||||
"ignore_above": 256
|
"keyword":{
|
||||||
}
|
"type":"keyword",
|
||||||
}
|
"ignore_above":256
|
||||||
},
|
}
|
||||||
"ownerReferences": {
|
}
|
||||||
"type": "flattened"
|
},
|
||||||
},
|
"ownerReferences":{
|
||||||
"resourceVersion": {
|
"type":"text"
|
||||||
"type": "text",
|
},
|
||||||
"fields": {
|
"resourceVersion":{
|
||||||
"keyword": {
|
"type":"text",
|
||||||
"type": "keyword",
|
"fields":{
|
||||||
"ignore_above": 256
|
"keyword":{
|
||||||
}
|
"type":"keyword",
|
||||||
}
|
"ignore_above":256
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"spec": {
|
}
|
||||||
"type": "flattened"
|
}
|
||||||
},
|
},
|
||||||
"status": {
|
"spec":{
|
||||||
"type": "flattened"
|
"type":"object",
|
||||||
}
|
"enabled":false
|
||||||
}
|
},
|
||||||
}
|
"status":{
|
||||||
}
|
"type":"object",
|
||||||
|
"enabled":false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -232,7 +236,7 @@ func (os *OpenSearch) indexName(us *unstructured.Unstructured) (string, error) {
|
||||||
os.l.Lock()
|
os.l.Lock()
|
||||||
defer os.l.Unlock()
|
defer os.l.Unlock()
|
||||||
|
|
||||||
if _, ok := os.indices[name]; !ok {
|
if _, ok := os.indices[name]; ok {
|
||||||
return name, nil
|
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)}
|
res := opensearchapi.IndicesCreateRequest{Index: name, Body: strings.NewReader(mapping)}
|
||||||
resp, err := res.Do(context.Background(), os.client)
|
resp, err := res.Do(context.Background(), os.client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(), "already exists") {
|
if strings.Contains(err.Error(), "resource_already_exists_exception") {
|
||||||
klog.V(4).Info("index already exists")
|
klog.Info("index already exists")
|
||||||
os.indices[name] = struct{}{}
|
os.indices[name] = struct{}{}
|
||||||
return name, nil
|
return name, nil
|
||||||
}
|
}
|
||||||
return name, fmt.Errorf("cannot create index: %v", err)
|
return name, fmt.Errorf("cannot create index: %v", err)
|
||||||
}
|
}
|
||||||
if resp.IsError() {
|
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{}{}
|
os.indices[name] = struct{}{}
|
||||||
|
|
||||||
return name, nil
|
return name, nil
|
||||||
|
|
Loading…
Reference in New Issue