How to overwrite the default template

hello everyone
I have a default template setting using pattern * and set some dynamic mapping

PUT /_template/template_default
{
    "index_patterns" : ["*"],
    "order" : 0,
    "settings": {
        "index": {
            "number_of_shards": "3"
        }
    },
    "mappings" : {
        "doc": {
            "dynamic_templates": [
                {
                    "strings_as_keywords": {
                        "match_mapping_type": "string",
                        "mapping": {
                          "type": "keyword",
                          "norms": false
                        }
                    }
                }
            ]
        }
    }
}

now i meet some special requirement that the _type should be values. So I create a new template

PUT /_template/zabbix_dbl
{
    "index_patterns" : ["zabbix_dbl-*"],
    "order" : 0,
    "settings": {
        "index": {
            "number_of_shards": "3"
        }
    },
     "mappings" : {
      "values" : {
         "properties" : {
            "itemid" : {
               "type" : "long"
            },
            "clock" : {
               "format" : "epoch_second",
               "type" : "date"
            },
            "value" : {
               "type" : "double"
            }
         }
      }
   },
    "aliases": {
        "zabbix_dbl_get": {}
    }
}

when i create new index by PUT zabbix_dbl-000001 there will be an error

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Rejecting mapping update to [zabbix_dbl-000001] as the final mapping would have more than 1 type: [values, doc]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Rejecting mapping update to [zabbix_dbl-000001] as the final mapping would have more than 1 type: [values, doc]"
  },
  "status": 400
}

it seems both above templates are applied to the index

how could i define a template properly having a different mapping _type name, please?

same question as Unable to create index with more that 1 type in 6.x

from 6.x, you can't create more than 1 type in one index

Thanks.
I already know this. But what I want is not an index with 2 type.

I define a default template using index_patterns * with a dynamic_templates so that every new string type will be mapped as keyword.
In my common use case, I usually ignore the _type parameter and I don't care about the _type of an index. So in this default template, the _type name may not necessarily be doc.

But in this specific case, since the zabbix process use the index with a _type name values. I want to know is there some mechanism in elasticsearch so that I can define a template to ignore the mapping part of the default index_patterns * template or ignore the whole defaule template.

you may use _doc as type name in template. _doc was the only type of the index now in es 6.x.

If I use the _doc as the type name, I still can't POST an index with types as its type.

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Rejecting mapping update to [test] as the final mapping would have more than 1 type: [types, _doc]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Rejecting mapping update to [test] as the final mapping would have more than 1 type: [types, _doc]"
  },
  "status": 400
}

Both need to be _doc, you cannot have different values.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.