# Change field types from String to integers and floats

**URL:** <https://discuss.elastic.co/t/change-field-types-from-string-to-integers-and-floats/80781>\
**Category:** Elasticsearch\
**Created:** [March 31, 2017, 7:48am UTC](https://discuss.elastic.co/t/change-field-types-from-string-to-integers-and-floats/80781 "2017-03-31T07:48:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pbData](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@pbData](https://discuss.elastic.co/u/pbData)\
**Post date:** [March 31, 2017, 7:48am UTC](https://discuss.elastic.co/t/change-field-types-from-string-to-integers-and-floats/80781/1 "2017-03-31T07:48:31Z")

</div>

I have the following data in elasticsearch. The system, which I cannot change, is putting most fields in as strings. See for example MaxProcessingTime. I want to use this data to graph it. The line graphs though need the data to be numeric fields! Can I change a type from a String to either a integer or float?

```
{
  "_index": "insight-2017.03.30",
  "_type": "sta-camel",
  "_id": "38MDo7Z_T_O1-bJTfnZCbw",
  "_score": 1,
  "_source": {
    "host": "myMetric",
    "@timestamp": "2017-03-30T16:02:10.780+01",
    "log-example-context": {
      "routes": {
        "log-route": {
          "ExchangesCompleted": "527",
          "MeanProcessingTime": "2",
          "ExchangesFailed": "0",
          "TotalProcessingTime": "1409",
          "FailuresHandled": "0",
          "MaxProcessingTime": "253",
          "Load15": "0.0",
          "Load05": "0.0",
          "ExternalRedeliveries": "0",
          "InflightExchanges": "0",
          "MinProcessingTime": "0",
          "Redeliveries": "0",
          "ExchangesTotal": "527",
          "Load01": "0.0"
        }
      }
    }
  }
}
```

---

<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 31, 2017, 8:08am UTC](https://discuss.elastic.co/t/change-field-types-from-string-to-integers-and-floats/80781/2 "2017-03-31T08:08:39Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

You need to reindex to change the type of any existing field.

---

<div class="post-metadata">

**Author:** ![pbData](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@pbData](https://discuss.elastic.co/u/pbData)\
**Post date:** [March 31, 2017, 8:43am UTC](https://discuss.elastic.co/t/change-field-types-from-string-to-integers-and-floats/80781/3 "2017-03-31T08:43:59Z")

</div>

I have just tried the following to change the type of a field named 'ExchangesCompleted' and although I got a acknowledged=true back the data it is still a string. Note that the property is nested and not sure if the syntax is correct.

```
curl -XPUT 'http://<somehost>:9200/insight-2017.03.31/sta-camel/_mapping' -d '
{
    "sta-camel" : {
        "properties" : {
            "_source.log-example-context.routes.log-route.ExchangesCompleted" : {"type" : "integer", "store" : "yes"}
        }
    }
}
'

```

The following query

`http://localhost:9200/insight-2017.03.31/sta-camel/_search`

gives the following response

```
{
	"took": 10,
	"timed_out": false,
	"_shards": {
		"total": 5,
		"successful": 5,
		"failed": 0
	},
	"hits": {
		"total": 111,
		"max_score": 1.0,
		"hits": [
			{
				"_index": "insight-2017.03.31",
				"_type": "sta-camel",
				"_id": "BHK23R5uSqSvlQygG5t1wA",
				"_score": 1.0,
				"_source": {
					"host": "myMetric",
					"@timestamp": "2017-03-31T08:24:02.743+01"
				}
			},
			{
				"_index": "insight-2017.03.31",
				"_type": "sta-camel",
				"_id": "9RZH3H3RSEWlyL6N9BFOqg",
				"_score": 1.0,
				"_source": {
					"host": "myMetric",
					"@timestamp": "2017-03-31T08:33:02.967+01",
					"log-example-context": {
						"routes": {
							"log-route": {
								"ExchangesCompleted": "107",
								"MeanProcessingTime": "1",
```

---

<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 28, 2017, 8:44am UTC](https://discuss.elastic.co/t/change-field-types-from-string-to-integers-and-floats/80781/4 "2017-04-28T08:44:08Z")

</div>

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