# Import mapping via index template

**URL:** <https://discuss.elastic.co/t/import-mapping-via-index-template/267393>\
**Category:** Elasticsearch\
**Created:** [March 16, 2021, 3:27pm UTC](https://discuss.elastic.co/t/import-mapping-via-index-template/267393 "2021-03-16T15:27:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Voula\_Mikr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/voula_mikr/32/58451_2.png) [@Voula\_Mikr](https://discuss.elastic.co/u/Voula_Mikr)\
**Post date:** [March 16, 2021, 3:27pm UTC](https://discuss.elastic.co/t/import-mapping-via-index-template/267393/1 "2021-03-16T15:27:29Z")

</div>

I want to import an index template with a mapping for the fields of the index pmdata\* in order to set as type of the field counter\_value **float**.  
After the import of the template with counter\_value type float, I imported an index with counter\_value: 17 (so a long number).  
After that, I got again the mapping of the index and the type of counter\_value was long and not float as it was in my initial mapping:  
**"counter\_value" : {**  
**"type" : "long"**  
}

Seems that the import of the template even if it was successful, didn't "affect" the mapping of the index and the type of the counter\_value is long instead of float.

How could it be possible to import a template before we have any index in order to have the proper type for the field?

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 16, 2021, 3:42pm UTC](https://discuss.elastic.co/t/import-mapping-via-index-template/267393/2 "2021-03-16T15:42:36Z")

</div>

Yes. That's the goal of index templates.  
You might have done something wrong.

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can copy and paste in Kibana dev console, click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![Voula\_Mikr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/voula_mikr/32/58451_2.png) [@Voula\_Mikr](https://discuss.elastic.co/u/Voula_Mikr)\
**Post date:** [March 17, 2021, 11:03am UTC](https://discuss.elastic.co/t/import-mapping-via-index-template/267393/3 "2021-03-17T11:03:18Z")

</div>

Hi David,

Thank you for the prompt answer.  
Actually I did all the described actions via curl commands.

I try to import an index template via (with no pmdata\* indices in elasticsearch):  
`curl -k -XPUT --header 'Authorization: Basic YWRtaW46cUUzRSZGRSMyUXNsUzkmcQ==' "https://10.254.88.15:9200/_template/template_1?pretty" -H 'Content-Type: application/json' -d @pmdata_map_float_to_template_v2.json`

where the content of `pmdata_map_float_to_template_v2.json` is the below :

```
{
  "index_patterns" : "pmdata*",
  "template" : {
    "settings": {
      "index.refresh_interval": "5s"
    },
    "mappings": {
      "_default_": {
        "properties": {
          "counter_display_name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "counter_group_name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "counter_name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "counter_value": {
            "type": "float"
          },
          "date": {
            "type": "date"
          },
          "distinguished_name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "is_dynamic": {
            "type": "boolean"
          },
          "measurement_time": {
            "type": "date"
          },
          "vnf_name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "vnf_type": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
  }
}

```

After that I get

```
{
  "acknowledged" : true
}

```

Then I import a pmdata index which has as counter\_value the number 7 for example.  
Then I am checking the mapping of the index with  
` curl -k -XGET --header 'Authorization: Basic YWRtaW46cUUzRSZGRSMyUXNsUzkmcQ==' "https://10.254.88.15:9200/pmdata*/_mapping?pretty"`

and I am getting the below :

```
 {
  "pmdata-zts6-2021-03-05" : {
    "mappings" : {
      "properties" : {
        "counter_display_name" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "counter_group_name" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "counter_name" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "counter_value" : {
          "type" : "long"
        },
        "date" : {
          "type" : "date"
        },
        "distinguished_name" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "is_dynamic" : {
          "type" : "boolean"
        },
        "measurement_time" : {
          "type" : "date"
        },
        "vnf_name" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "vnf_type" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}

```

I was expecting that since the imported template was with type float for `counter_value`, that even it was imported an integer (here 7) , still in mapping the type of the `counter_value` would be float.

Sorry for the long text.  
Thank you again!

---

<div class="post-metadata">

**Author:** ![Voula\_Mikr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/voula_mikr/32/58451_2.png) [@Voula\_Mikr](https://discuss.elastic.co/u/Voula_Mikr)\
**Post date:** [March 22, 2021, 2:13pm UTC](https://discuss.elastic.co/t/import-mapping-via-index-template/267393/4 "2021-03-22T14:13:43Z")

</div>

Hi @dadoonet ,

Do you have any update for this?  
Thank you again.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 24, 2021, 6:52pm UTC](https://discuss.elastic.co/t/import-mapping-via-index-template/267393/5 "2021-03-24T18:52:06Z")

</div>

As I said, it's definitely better to provide a full and simple recreation script. That takes less time for readers to reproduce so we can eventually answer and with a better response time.

Anyway, here is what you did.

```auto
DELETE /_template/template_1
PUT /_template/template_1
{
  "index_patterns": "pmdata*",
  "template": {
    "mappings": {
      "properties": {
        "counter_value": {
          "type": "float"
        }
      }
    }
  }
}

DELETE pmdata1
POST pmdata1/_doc
{
  "counter_value": 7
}

GET pmdata1/_mapping

```

And the fix:

```auto
DELETE /_template/template_1
PUT /_template/template_1
{
  "index_patterns": "pmdata*",
  "mappings": {
    "properties": {
      "counter_value": {
        "type": "float"
      }
    }
  }
}

DELETE pmdata1
POST pmdata1/_doc
{
  "counter_value": 7
}

GET pmdata1/_mapping

```

As you can see the `template` level does not exist. See [Create or update index template API | Elasticsearch Reference [7.12] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates-v1.html)

BTW, you should switch to the new template API. [Index templates | Elasticsearch Reference [7.12] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-templates.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 21, 2021, 6:52pm UTC](https://discuss.elastic.co/t/import-mapping-via-index-template/267393/6 "2021-04-21T18:52:49Z")

</div>

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