我在嘗試插入帶有物件的檔案時遇到此錯誤something:
failed to parse field [alert.something] of type [text]
in document with id 'S7wzjXwBoPDEI_MgkgFb'. Preview of field's value: '{a=b}'",
這是訊息:
{
"random" : 1634334912,
"alert" : {
"app_key" : "abc",
"host" : "prod-mongo-1",
"check" : "heap_size",
"status" : "warning",
"something": {
"a": "b"
}
}
}
這是索引模板:
{
"order" : 0,
"index_patterns" : [
"rawpayload-*"
],
"settings" : {
"index" : {
"mapping" : {
"coerce" : "false",
"nested_fields" : {
"limit" : "50"
},
"depth" : {
"limit" : "20"
},
"ignore_malformed" : "false"
}
}
},
"mappings" : {
"_source" : {
"enabled" : true
},
"dynamic_templates": [
{
"alert_boject": {
"path_match": "alert.*",
"match_mapping_type" : "*",
"mapping": {
"type": "text"
}
}
}
],
"properties" : {
"application" : {
"index" : "false",
"store" : true,
"type" : "text"
}
}
}
}
你能指出或幫我解決這個問題:)?
uj5u.com熱心網友回復:
由于alert.*可以是字串或物件,因此為物件添加新的動態型別映射。
您當前的模板接受以下任何 JSON 型別alert_boject:
"match_mapping_type" : "*",
但僅映射到 JSON 字串 - text- 不適用于物件:
"mapping": {
"type": "text"
}
修改當前模板以僅選擇text:
{
"alert_boject": {
"path_match": "alert.*",
"match_mapping_type" : "text",
"mapping": {
"type": "text"
}
}
}
然后基于上述創建一個新模板 - 將映射型別 ( mapping.type)object更改match_mapping_type為使其接受物件并更改為object。
這樣,您將有 2 個模板根據您是否有一個text欄位或object.
"dynamic_templates":[
{
"alert_object_text":{
"path_match":"alert.*",
"match_mapping_type":"text",
"mapping":{
"type":"text"
}
}
},
{
"alert_object_object":{
"path_match":"alert.*",
"match_mapping_type":"object",
"mapping":{
"type":"object"
}
}
}
]
uj5u.com熱心網友回復:
我不確定這是一個解決方案,但我很想聽聽一些意見。我設法通過添加模板定義來減輕錯誤:
{
"alert_object_parser": {
"path_match": "alert.*",
"match_mapping_type" : "object",
"mapping": {
"type": "object"
}
}
}
你怎么認為 ?
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/320911.html
標籤:弹性搜索
上一篇:使用樣式組件的React組件支持TypeScript錯誤
下一篇:命名的multi_match查詢
