elasticsearch动态模板

时间:2017-06-13 07:32:18

标签: elasticsearch elasticsearch-5

如何为下面的映射设置动态模板

      "ipAddress" : {
        "properties" : {
          "bytes" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }
      },

我尝试了多种选项,但无法解决如何将文本/字符串字段更改为ip数据类型的问题。我猜这是由于嵌套,但我是动态模板的新手,不知道如何构建一个

curl -XPUT localhost:9200/_template/clee-new-* -d '{
"template": "clee-new-*",
"mappings": {
    "clee-new": {
        "_all": {
            "enabled": true
        },
        "dynamic_templates": [
            {
                "string_fields": {
                    "match": "ipAddress*",
                    "match_mapping_type": "nested",
                    "mapping": {
                        "index": "not_analyzed",
                        "type": "ip"
                    }
                }
            }
        ]
    }
}
}'

curl -XPUT localhost:9200/_template/clee-new-* -d '{
"template": "clee-new-*",
"mappings": {
    "clee-new": {
        "_all": {
            "enabled": true
        },
        "dynamic_templates": [
            {
                "string_fields": {
                    "match": "ipAddress.bytes",
                    "match_mapping_type": "string",
                    "mapping": {
                        "index": "not_analyzed",
                        "type": "ip"
                    }
                }
            }
        ]
    }
}
}'

1 个答案:

答案 0 :(得分:0)

让它与path_match一起使用

curl -XPUT localhost:9200/_template/clee-new -d '{
"template": "clee-new-*",
"mappings": {
    "_default_": {
        "_all": {
            "enabled": true
        },
        "dynamic_templates": [
            {
                "string_fields": {
                    "path_match": "ipAddress.*",
                    "match_mapping_type": "*",
                    "mapping": {
                        "index": "not_analyzed",
                        "type": "ip"
                    }
                }
            }
        ]
    }
}
}'