# Reindex string to date field exception

**URL:** <https://discuss.elastic.co/t/reindex-string-to-date-field-exception/260863>\
**Category:** Elasticsearch\
**Tags:** reindex\
**Created:** [January 12, 2021, 4:02pm UTC](https://discuss.elastic.co/t/reindex-string-to-date-field-exception/260863 "2021-01-12T16:02:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thanhlam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thanhlam/32/78982_2.png) [@thanhlam](https://discuss.elastic.co/u/thanhlam)\
**Post date:** [January 12, 2021, 4:02pm UTC](https://discuss.elastic.co/t/reindex-string-to-date-field-exception/260863/1 "2021-01-12T16:02:42Z")

</div>

Hello,  
I've done much searching on the topics of converting a field that's defined or mapped as "text string" to type date but can't find a specific example like what I'm trying. Any help would be appreciated.

This index is created from filebeat input (log file) to logstash. And, I can't find the original index fields mapping. The problem is a date field has type "text string" that I want to be type date for the purposes of date range querying.

Because the type of a field can't be changed, I'm trying to create a new index with all the fields the same as the current index. With two fields changed to have type date. Then, I tried to run \_reindex to copy data from current index to new index.

The new index has all the data okay but the two fields that I defined as date type still have type "text string". That's because reindex hit the following exceptions:

```auto
{
  "took": 276,
  "timed_out": false,
  "total": 252,
  "updated": 0,
  "created": 0,
  "deleted": 0,
  "batches": 1,
  "version_conflicts": 0,
  "noops": 0,
  "retries": {
    "bulk": 0,
    "search": 0
  },
  "throttled_millis": 0,
  "requests_per_second": -1,
  "throttled_until_millis": 0,
  "failures": [
    {
      "index": "cast-allocation-test",
      "type": "_doc",
      "id": "193",
      "cause": {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse field [data.begin_time] of type [date] in document with id '193'. Preview of field's value: '2020-11-02 13:04:22.413672'",
        "caused_by": {
          "type": "illegal_argument_exception",
          "reason": "failed to parse date field [2020-11-02 13:04:22.413672] with format [YYYY-MM-dd HH:mm:ss.000000]",
          "caused_by": {
            "type": "date_time_parse_exception",
            "reason": "Text '2020-11-02 13:04:22.413672' could not be parsed at index 20"
          }
        }
      },
      "status": 400
    },

```

From the exception above, you can see the original text string looks like this:

```auto
'2020-11-02 13:04:22.413672'

```

And, my new index date type format for those two fields looks like:

```auto
YYYY-MM-dd HH:mm:ss.000000

```

I'd like to check if the format and what is done is the right way to do this. Thanks in advance for any help.

My reindex command:

```auto
POST _reindex
{
  "source": {
    "index": "cast-allocation"
  },
  "dest": {
    "index": "cast-allocation-test"
  }
}

```

---

<div class="post-metadata">

**Author:** ![thanhlam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thanhlam/32/78982_2.png) [@thanhlam](https://discuss.elastic.co/u/thanhlam)\
**Post date:** [January 14, 2021, 7:15pm UTC](https://discuss.elastic.co/t/reindex-string-to-date-field-exception/260863/2 "2021-01-14T19:15:36Z")

</div>

Hmm.... Nobody found a problem here?

After more try and error experiments, I kind of concluding that the problem is in the text string of date format having a blank between date and time:

```auto
'2020-11-02 13:04:22.413672'

```

Can't even write that string to a new record with a date field. So this is probably the problem with `reindex` also. It didn't matter what date format was defined for the date field.

Using the same text string with the letter T replacing the blank, I can write the new record with no problem. I also removed the format for the new date field. That makes the format more flexible.

Back to the problem with `reindex`, I wonder if a "processing" "script" can be added to `reindex` to add the T into the text string date before the record being written into the new index? Something like:

```auto
POST _reindex
{
  "source": {
    "index": "cast-allocation"
  },
  "dest": {
    "script": "<change 'date time' to 'dateTtime'>"
    "index": "cast-allocation-test"
  }
}

```

Can someone help with an example of the above "script"?

---

<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:** [February 11, 2021, 7:15pm UTC](https://discuss.elastic.co/t/reindex-string-to-date-field-exception/260863/3 "2021-02-11T19:15:41Z")

</div>

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