# Change text mapping from text to integer

**URL:** <https://discuss.elastic.co/t/change-text-mapping-from-text-to-integer/342484>\
**Category:** Elasticsearch\
**Created:** [September 7, 2023, 12:29am UTC](https://discuss.elastic.co/t/change-text-mapping-from-text-to-integer/342484 "2023-09-07T00:29:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geeboy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/geeboy/32/121876_2.png) [@Geeboy](https://discuss.elastic.co/u/Geeboy)\
**Post date:** [September 7, 2023, 12:29am UTC](https://discuss.elastic.co/t/change-text-mapping-from-text-to-integer/342484/1 "2023-09-07T00:29:38Z")

</div>

Good day!

Im creating new index, when I add this to "data views", it was tagged as TEXT type. I need it to be integer. do you have step by step guide for this case?

my temporary solution is this command -\> `emit (Integer.parseInt(doc['keyword'].value))`

please ignore the "DATE", I already change the format.  
Im using td-agent as log forwarder

```auto
  "indextrnxcount-000001" : {
    "mappings" : {
      "properties" : {
        "DATE" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "TransactionCount" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "tailed_path" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}

```

Thank you very much

---

<div class="post-metadata">

**Author:** ![cperzrt10](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cperzrt10/32/116152_2.png) [@cperzrt10](https://discuss.elastic.co/u/cperzrt10)\
**Post date:** [September 7, 2023, 11:13am UTC](https://discuss.elastic.co/t/change-text-mapping-from-text-to-integer/342484/2 "2023-09-07T11:13:17Z")

</div>

Hi @Geeboy, you must try to create an index template here  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/f/2f2acf3cc17fbd9bec410c0a6310bc81cba97784.png)

Then select index template and create or edit your template  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/2/225253536f84e43d0e955503043c7b8286c03e3f.png)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/d/1/d1d1efbc681628faa9cd00977f874c632809a578.png)

[Here](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-templates.html) the documentation to do via dev tools in kibana.

---

<div class="post-metadata">

**Author:** ![Geeboy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/geeboy/32/121876_2.png) [@Geeboy](https://discuss.elastic.co/u/Geeboy)\
**Post date:** [September 11, 2023, 1:42am UTC](https://discuss.elastic.co/t/change-text-mapping-from-text-to-integer/342484/3 "2023-09-11T01:42:32Z")

</div>

thank you for the info. how can I insert my mappings in my sample template below?

```auto
{
  "index_templates" : [
    {
      "name" : "smpphourly-template",
      "index_template" : {
        "index_patterns" : [
          "smpphourly-*"
        ],
        "template" : {
          "settings" : {
            "index" : {
              "lifecycle" : {
                "name" : "180-days-default",
                "rollover_alias" : "index-alias"
              },
              "number_of_shards" : "1",
              "number_of_replicas" : "0"
            }
          },
          "mappings" : {
            "_source" : {
              "enabled" : true
            }
          }
        },
        "composed_of" : []
      }
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![cperzrt10](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cperzrt10/32/116152_2.png) [@cperzrt10](https://discuss.elastic.co/u/cperzrt10)\
**Post date:** [September 11, 2023, 6:27am UTC](https://discuss.elastic.co/t/change-text-mapping-from-text-to-integer/342484/4 "2023-09-11T06:27:57Z")

</div>

Hi, here an example:

```auto
PUT _index_template/smpphourly-template
{
  "template": {
    "settings" : {
	  "index" : {
	    "lifecycle" : {
		  "name" : "180-days-default",
		  "rollover_alias" : "index-alias"
		},
		"number_of_shards" : "1",
        "number_of_replicas" : "0"
      }
    }
    "mappings": {
      "dynamic": true,
      "numeric_detection": false,
      "date_detection": true,
      "dynamic_date_formats": [
        "strict_date_optional_time",
        "yyyy/MM/dd HH:mm:ss Z||yyyy/MM/dd Z"
      ],
      "_source": {
        "enabled": true,
        "includes": [],
        "excludes": []
      },
      "_routing": {
        "required": false
      },
      "dynamic_templates": [],
      "properties": {
        "TransactionCount": {
          "type": "integer"
        }
      }
    }
  },
  "index_patterns": [
    "smpphourly-*"
  ]
}

```

---

<div class="post-metadata">

**Author:** ![Geeboy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/geeboy/32/121876_2.png) [@Geeboy](https://discuss.elastic.co/u/Geeboy)\
**Post date:** [September 12, 2023, 3:21am UTC](https://discuss.elastic.co/t/change-text-mapping-from-text-to-integer/342484/5 "2023-09-12T03:21:08Z")

</div>

thank you very much @cperzrt10 . great help 🙂

---

<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:** [October 10, 2023, 3:21am UTC](https://discuss.elastic.co/t/change-text-mapping-from-text-to-integer/342484/6 "2023-10-10T03:21:22Z")

</div>

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