2017-12-18 326 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