elasticsearch 如何在elasticsearch动态模板中为动态字段创建别名?,elasticsearch,mapping,elasticsearch,Mapping" /> elasticsearch 如何在elasticsearch动态模板中为动态字段创建别名?,elasticsearch,mapping,elasticsearch,Mapping" />

elasticsearch 如何在elasticsearch动态模板中为动态字段创建别名?

elasticsearch 如何在elasticsearch动态模板中为动态字段创建别名?,elasticsearch,mapping,elasticsearch,Mapping,我正在使用elasticsearch 1.0.2,并在索引中使用一个示例动态模板。我们是否可以从动态字段名的一部分派生字段索引名 这是我的模板 {"dynamic_templates":[ "dyn_string_fields": { "match": "dyn_string_*", "match_mapping_type": "string", "mapping": { "type": "string", "index" : "analyze

我正在使用elasticsearch 1.0.2,并在索引中使用一个示例动态模板。我们是否可以从动态字段名的一部分派生字段索引名

这是我的模板

{"dynamic_templates":[
  "dyn_string_fields": {
    "match": "dyn_string_*",
    "match_mapping_type": "string",
    "mapping": {
      "type": "string",
      "index" : "analyzed",
      "index_name": "{name}"
    }
  }
}]}
动态模板可以工作,我可以添加字段。我们的目标是添加前缀为“dyn\u string\u”的字段,但在搜索时,它应该只是没有“dyn\u string\u”前缀的字段名。我测试了使用match_mapping_type添加字段,但这将允许添加任何字段。有人有什么建议吗


我查看了Elasticsearch API,他们在1.3中有一个转换功能,允许在插入之前修改文档。(不幸的是,我无法升级到该版本。)

在单个模板中,可以设置多个别名。有关快速示例,请查看以下虚拟示例:

    curl -XPUT localhost:9200/_template/test_template -d '
{
    "template" : "test_*",
    "settings" : {
        "number_of_shards" : 4
    },
    "aliases" : {
        "name_for_alias" : {}
    },
    "mappings" : {
         "type" : {
        "properties" : {
          "id" : {
            "type" : "integer",
            "include_in_all" : false
          },
          "test_user_id" : {
            "type" : "integer",
            "include_in_all" : false
          }
        }
      }
    }
}
' 
这里的“name_for_alias”是您的简单别名。作为参数,如果您想使用别名过滤数据,可以定义预设过滤器

更多信息可在此处找到: