# Reindexing with date format conversion applied on dynamic fields matching regex

**URL:** https://discuss.elastic.co/t/reindexing-with-date-format-conversion-applied-on-dynamic-fields-matching-regex/237793
**Category:** Elasticsearch
**Created:** [June 19, 2020, 11:07am UTC](https://discuss.elastic.co/t/reindexing-with-date-format-conversion-applied-on-dynamic-fields-matching-regex/237793 "2020-06-19T11:07:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Andrei\_Gog](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_gog/32/70517_2.png) [@Andrei\_Gog](https://discuss.elastic.co/u/Andrei_Gog)
#### Post date: [June 19, 2020, 11:07am UTC](https://discuss.elastic.co/t/reindexing-with-date-format-conversion-applied-on-dynamic-fields-matching-regex/237793/1 "2020-06-19T11:07:49Z")

</div>

Hello Guys.  
I have an index A that has fields **dt\_0** to **dt\_n** (n\<=100) that unfortunately are stored as dynamic mappings and represent the Long value of a date. The index B has the same mappings as A but it also has the right mapping for the **dt\_n** fields as shown below.

```auto
"dt_1": {
            "type": "date",
            "format": "strict_date_time"
          }

```

Do you see any way I could use the reindex API to reindex from A to B and convert to date time only those fields that are name **dt\_** \*?  
Here are the failures I get when I try to perform a basic reindex operation.

```auto
{
  "took": 17151,
  "timed_out": false,
  "total": 459696,
  "updated": 104999,
  "created": 18000,
  "deleted": 0,
  "batches": 123,
  "version_conflicts": 0,
  "noops": 0,
  "retries": {
    "bulk": 0,
    "search": 0
  },
  "throttled_millis": 0,
  "requests_per_second": -1,
  "throttled_until_millis": 0,
  "failures": [
    {
      "index": "lc-uat-de1_accessgrant_project_v2",
      "type": "accessible",
      "id": "5eea03cec4839733aa11da6e",
      "cause": {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse [dt_1]",
        "caused_by": {
          "type": "illegal_argument_exception",
          "reason": "Invalid format: \"1579478400000\" is malformed at \"478400000\""
        }
      },
      "status": 400
    }
  ]
}

```

Thank you!

---

<div class="post-metadata">

### Author: ![Vinayak\_Sapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vinayak_sapre/32/45939_2.png) [@Vinayak\_Sapre](https://discuss.elastic.co/u/Vinayak_Sapre)
#### Post date: [June 19, 2020, 11:53pm UTC](https://discuss.elastic.co/t/reindexing-with-date-format-conversion-applied-on-dynamic-fields-matching-regex/237793/2 "2020-06-19T23:53:46Z")

</div>

Hi @Andrei_Gog  
You can try using script in reindex. Assuming all values in dt\_1 in index A are epoch millis.

```auto
{
  "source": {
    "index": "A"
  },
  "dest": {
    "index": "B"
  },
  "script": {
    "source": "long milliSinceEpoch = ctx._source.remove(\"dt_1\"); Instant instant = Instant.ofEpochMilli(milliSinceEpoch); ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, ZoneId.of('Z')); ctx._source.dt_1 = zdt;"
  }
}

```

---

<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: [July 17, 2020, 11:53pm UTC](https://discuss.elastic.co/t/reindexing-with-date-format-conversion-applied-on-dynamic-fields-matching-regex/237793/3 "2020-07-17T23:53:47Z")

</div>

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