首页 文章

与Solr动态字段相比,Elasticsearch动态映射

提问于
浏览
5

在Solr中,我可以定义一个动态字段并将其绑定到特定的数据类型 . 在以下示例中,以"dt"结尾的索引文档中的所有字段都将编入索引为long . <dynamicField name="*_dt" stored="true" indexed="true" type="long" multiValued="true"/>

在ElasticSearch中,知道字段的名称,我可以使用"mappings"中的"properties"子节点将字段索引到特定类型 . "properties": { "msh_datetimeofmessage_hl7_dt": { "type": "date", "format": "YYYYMMddHHmmss" },

我尝试了以下操作并尝试使用模板,但未成功 . "properties": { "*_dt": { "type": "date", "format": "YYYYMMddHHmmss" },

ElasticSearch是否提供与Solr相同的功能,如上所述?

提前致谢 .

1 回答

  • 3

    我想你可能正在寻找dynamic templates提供的功能 . 除非我弄错了,否则你的映射看起来会像这样(主要是从链接页面借来的) .

    PUT /my_index
    {
    "mappings": {
        "my_type": {
            "dynamic_templates": [
                { "my_date_template": {
                      "match":              "*_dt", 
                      "mapping": {
                          "type":           "date",
                          "format": "YYYYMMDDHHmmss"
                      }
                }}
            ]
    }}}
    

相关问题