# Open Distro for Elasticsearch does not use template in index creation

**URL:** <https://forum.opensearch.org/t/open-distro-for-elasticsearch-does-not-use-template-in-index-creation/3548>\
**Category:** Open Source Elasticsearch and Kibana\
**Created:** [August 19, 2020, 8:50pm UTC](https://forum.opensearch.org/t/open-distro-for-elasticsearch-does-not-use-template-in-index-creation/3548 "2020-08-19T20:50:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hweber](https://avatars.discourse-cdn.com/v4/letter/h/3ec8ea/32.png) [@hweber](https://forum.opensearch.org/u/hweber)\
**Post date:** [August 19, 2020, 8:50pm UTC](https://forum.opensearch.org/t/open-distro-for-elasticsearch-does-not-use-template-in-index-creation/3548/1 "2020-08-19T20:50:19Z")

</div>

I am using Open Distro for Elasticsearch, version 1.9.0.  
I executed

```auto
curl -ivvk -H "Content-Type: application/json" -H "Accept: application/json" -u username:password -X PUT "https://localhost:9200/_template/test_template" -d '
{
  "index_patterns": ["test-*"],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "index.refresh_interval": "5s"
    },
    "mappings": {
      "properties": {
        "status": {
    	  "type": "keyword"
        },
       "message": {
    	  "type": "text"
	}
      }
    }
  }
}'

HTTP/1.1 200 OK

{"acknowledged":true}

curl -ivvk -H "Accept: application/json" -u username:password -X GET "https://localhost:9200/_cat/templates"

HTTP/1.1 200 OK

[{"name":"test_template","index_patterns":"[test-*]","order":"0","version":null,"composed_of":""}]

```

I then created the index, test-1, with a deliberate attempt to violate the intended mapping of **status** to keyword, by assigning an integer value to it:

```auto
curl -ivvk -H "Content-Type: application/json" -H "Accept: application/json" -u username:password -X POST "https://localhost:9200/test-1/_create/1" -d '
{
  "status": 7,
  "message": "This is a test."
}'

HTTP/1.1 201 Created

{"_index":"test-1","_type":"_doc","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}

```

When I inspected the mapping that was applied to test-1, I saw:

```auto
curl -ivvk -u username:password -H "Accept: application/json" "https://localhost:9200/test-1/_mapping?pretty"

HTTP/1.1 200

{
  "test-1" : {
    "mappings" : {
      "properties" : {
        "message" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "status" : {
          "type" : "long"
        }
      }
    }
  }
}

```

I realized the template was ignored since status had type, long, instead of keyword. Can someone tell me what I should be doing?

---

<div class="post-metadata">

**Author:** ![stmx38](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/stmx38/32/4354_2.png) [@stmx38](https://forum.opensearch.org/u/stmx38)\
**Post date:** [August 20, 2020, 11:11am UTC](https://forum.opensearch.org/t/open-distro-for-elasticsearch-does-not-use-template-in-index-creation/3548/3 "2020-08-20T11:11:25Z")

</div>

Hello @hweber, I tried to follow your steps and did just a first one. After I tried to see created template:

#### Create template

```auto
curl -ivvk -H "Content-Type: application/json" -H "Accept: application/json" -X PUT "http://localhost:9200/_template/test_template" -d '
{
  "index_patterns": ["test-*"],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "index.refresh_interval": "5s"
    },
    "mappings": {
      "properties": {
        "status": {
      "type": "keyword"
        },
       "message": {
      "type": "text"
}
      }
    }
  }
}'

```

#### Get template

```auto
curl http://localhost:9200/_template/test_template?pretty
{
  "test_template" : {
    "order" : 0,
    "index_patterns" : [
      "test-*"
    ],
    "settings" : { },
    "mappings" : { },
    "aliases" : { }
  }
}

```

It is Open Distro 1.7.0. We have some templates and they works but I created one from the file using the following steps:

### Create template json

`vi nginx-access.json`

```auto
{
    "order" : 0,
    "version" : 60001,
    "index_patterns" : [
      "nginx-access*"
    ],
    "settings" : {
      "index" : {
        "number_of_shards" : "1",
        "refresh_interval" : "5s"
      }
    },
    "mappings" : {
      "dynamic_templates" : [
        {
          "message_field" : {
            "path_match" : "message",
            "mapping" : {
              "norms" : false,
              "type" : "text"
            },
            "match_mapping_type" : "string"
          }
        },
        {
          "string_fields" : {
            "mapping" : {
              "norms" : false,
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "ignore_above" : 256,
                  "type" : "keyword"
                }
              }
            },
            "match_mapping_type" : "string",
            "match" : "*"
          }
        }
      ],
      "properties" : {
        "@timestamp" : {
          "type" : "date"
        },
        "@version" : {
          "type" : "keyword"
        },
        "geoip" : {
          "dynamic" : true,
          "properties" : {
            "ip" : {
              "type" : "ip"
            },
            "latitude" : {
              "type" : "half_float"
            },
            "location" : {
              "type" : "geo_point"
            },
            "longitude" : {
              "type" : "half_float"
            }
          }
        },
        "ng_real_ip" : {
          "type" : "ip"
        },
        "ng_remote_addr" : {
          "type" : "ip"
        },
        "ng_request_time" : {
          "type" : "long"
        },
        "ng_request_length" : {
          "type" : "long"
        },
        "ng_bytes_sent" : {
          "type" : "long"
        },
        "ng_upstream_connect_time" : {
          "type" : "long"
        },
        "ng_upstream_response_time" : {
          "type" : "long"
        }
      }
    },
    "aliases" : { }
  }
}

```

### Upload template

`curl -XPUT http://localhost:9200/_template/nginx-access?pretty -H 'Content-Type: application/json' -d @nginx-access.json`

I want to say that it works and in such a case we just should set it correctly via request, like you do it.

---

<div class="post-metadata">

**Author:** ![hweber](https://avatars.discourse-cdn.com/v4/letter/h/3ec8ea/32.png) [@hweber](https://forum.opensearch.org/u/hweber)\
**Post date:** [August 20, 2020, 1:30pm UTC](https://forum.opensearch.org/t/open-distro-for-elasticsearch-does-not-use-template-in-index-creation/3548/4 "2020-08-20T13:30:05Z")

</div>

Thank you! It appears that the “template” name/value in my test\_template caused the problem. When I removed it to make it look like your nginx-access.json it worked.
