# Number format Exception For string type

**URL:** <https://discuss.elastic.co/t/number-format-exception-for-string-type/59175>\
**Category:** Elasticsearch\
**Created:** [August 29, 2016, 11:29am UTC](https://discuss.elastic.co/t/number-format-exception-for-string-type/59175 "2016-08-29T11:29:21Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [May 26, 2017, 6:03am UTC](https://discuss.elastic.co/t/number-format-exception-for-string-type/59175/6 "2017-05-26T06:03:37Z")

</div>

Hi,

did you create the new index before running the reindex? Please follow the example below. This worked fine for me on Elasticsearch 2.4.5 (as your talking about "string" I assumed you are on 2.x; in 5.x "string" type has been split into "text" and "keyword").

Let's start fresh and delete all involved indices for this example:

```auto
DELETE /old_books
DELETE /new_books

```

Then create the old index and add a document to it.

```auto
PUT /old_books
{
   "mappings": {
      "author": {
         "properties": {
            "name": {
               "type": "string"
            },
            "auid": {
                "type": "string"
            }
         }
      }
   }
}

PUT /old_books/author/1
{
    "name": "Mark Twain",
    "auid": "42"
}

```

Now we realize we made a mistake and create the new index where we correct the mapping of the `auid` field to `integer`:

```auto
PUT /new_books
{
   "mappings": {
      "author": {
         "properties": {
            "name": {
               "type": "string"
            },
            "auid": {
                "type": "integer"
            }
         }
      }
   }
}

```

and let the reindex API do its job:

```auto
POST /_reindex
{
  "source": {
    "index": "old_books"
  },
  "dest": {
    "index": "new_books"
  }
}

```

This worked fine for me. Here is the response:

```auto
{
   "took": 56,
   "timed_out": false,
   "total": 1,
   "updated": 0,
   "created": 1,
   "batches": 1,
   "version_conflicts": 0,
   "noops": 0,
   "retries": 0,
   "throttled_millis": 0,
   "requests_per_second": "unlimited",
   "throttled_until_millis": 0,
   "failures": []
}

```

Note, although Elasticsearch indexes the field now as integer, it is still a string in `_source`:

```auto
GET /new_books/author/_search
{
    "query": {
        "match_all": {}
    }
}

```

shows:

```auto
{
  ...
      "hits": [
         {
            "_index": "new_books",
            "_type": "author",
            "_id": "1",
            "_score": 1,
            "_source": {
               "name": "Mark Twain",
               "auid": "42"
            }
         }
      ]
...

```

If you do not want that you can use an inline script to convert the source as well during reindexing. Remember that inline scripts are a security risk and that you should rather use stored scripts for this. If you still want to use inline scripts then you need to (temporarily) enable them by setting `script.inline: true` in `config/elasticsearch.yml` and restart your cluster:

```auto
POST /_reindex
{
  "source": {
    "index": "old_books"
  },
  "dest": {
    "index": "new_books"
  },
"script": {
    "inline": "ctx._source.auid = Integer.valueOf(ctx._source.auid)"
  }
}

```

This will significantly slow-down the reindexing process though. Also check [how you can reindex without downtime](https://www.elastic.co/guide/en/elasticsearch/guide/current/index-aliases.html).

Daniel

---

_[View the full topic](https://discuss.elastic.co/t/number-format-exception-for-string-type/59175)._
