2017-12-18 312 views
0

我目前正在努力簡化Elasticsearch的映射模板文件。事實上,我有幾個Object字段具有相同的結構(例如源和目標)Elasticsearch動態模板匹配幾個確切的字段

有沒有辦法設置動態模板,以便它可以匹配多個模式?

這是我執行:

POST /_template/mapping-lol 
{ 
    "template": "*-newevents-*", 
    "mappings": { 
    "log": { 
     "dynamic_templates": [ 
     { 
      "system": { 
      "match_pattern": "regex", 
      "match": "^(source|destination)$", 
      "mapping": { 
       "properties": { 
       "name": { 
        "dynamic": false, 
        "type": "object", 
        "properties": { 
        "first": { 
         "type": "text" 
        }, 
        "last": { 
         "type": "text" 
        } 
        } 
       }, 
       "ip": { 
        "type": "ip" 
       } 
       } 
      } 
      } 
     } 
     ], 
     "properties": { 
     "source": { 
      "type": "object", 
      "dynamic": true 
     }, 
     "destination": { 
      "type": "object", 
      "dynamic": true 
     } 
     } 
    } 
    } 
} 

POST /tenant-newevents-1/log 
{ 
    "source": { 
    "name": { 
     "first": "John", 
     "last": "Doe" 
    }, 
    "ip": "1.2.3.4" 
    }, 
    "destination": { 
    "name": { 
     "first": "Jane", 
     "last": "Doe" 
    }, 
    "ip": "3.4.5.6" 
    } 
} 

GET /tenant-newevents-1 

這上面沒有工作...

我有的是這些相同的方案來匹配(〜20)。

非常感謝您的幫助!

+0

看起來不錯。剛剛嘗試過ES 5和6,並且運行良好。請說明你如何創建索引/映射? – Val

+0

curl -XPOST「locallhost:9200/_template/mapping-events」[email protected] – moutonjr

+0

好的一個!那麼mymapping.json的內容呢? – Val

回答

0

OK我發現出了什麼問題:字段不能映射在所有動態映射繼續。在映射工作中刪除「源」和「目標」方案。

POST /_template/mapping-lol 
{ 
    "template": "*-newevents-*", 
    "mappings": { 
    "log": { 
     "dynamic_templates": [ 
     { 
      "system": { 
      "match_pattern": "regex", 
      "match": "^(source|destination)$", 
      "mapping": { 
       "properties": { 
       "name": { 
        "dynamic": false, 
        "type": "object", 
        "properties": { 
        "first": { 
         "type": "text" 
        }, 
        "last": { 
         "type": "text" 
        } 
        } 
       }, 
       "ip": { 
        "type": "ip" 
       } 
       } 
      } 
      } 
     } 
     ], 
     "properties": {} 
    } 
    } 
} 
+0

這是我的下一個評論;-)如果你有他們的動態模板映射他們沒有意義。 – Val