# Reindex api and date field

**URL:** <https://discuss.elastic.co/t/reindex-api-and-date-field/144943>\
**Category:** Elasticsearch\
**Created:** [August 17, 2018, 6:00pm UTC](https://discuss.elastic.co/t/reindex-api-and-date-field/144943 "2018-08-17T18:00:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![guilherme\_maranhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_maranhao/32/101483_2.png) [@guilherme\_maranhao](https://discuss.elastic.co/u/guilherme_maranhao)\
**Post date:** [August 17, 2018, 6:00pm UTC](https://discuss.elastic.co/t/reindex-api-and-date-field/144943/1 "2018-08-17T18:00:18Z")

</div>

Dear all,

I've used \_reindex and all the date fields were changed to **"type": "text"**. In the source index, they are all declared as follow:

`my_date_field": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss" }`

The reindex json was:

```
{
  "source": {
    "index": "my_source_index"
  },
  "dest": {
    "index": "my_dest_index"
  },
  "script": {
    "inline": "ctx._source.remove('another_field')"
  }
}

```

My elastic version is 6.2.1.

Does anybody know why that happened?

Thanks a lot,

Guilherme

---

<div class="post-metadata">

**Author:** ![cdekker](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cdekker](https://discuss.elastic.co/u/cdekker)\
**Post date:** [August 17, 2018, 6:33pm UTC](https://discuss.elastic.co/t/reindex-api-and-date-field/144943/2 "2018-08-17T18:33:11Z")

</div>

Make sure you set up your (empty) destination index including mappings first. Else it is left for ES to guess the mapping for each field which it seems to do incorrectly in your case.

---

<div class="post-metadata">

**Author:** ![guilherme\_maranhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_maranhao/32/101483_2.png) [@guilherme\_maranhao](https://discuss.elastic.co/u/guilherme_maranhao)\
**Post date:** [August 20, 2018, 12:58pm UTC](https://discuss.elastic.co/t/reindex-api-and-date-field/144943/3 "2018-08-20T12:58:35Z")

</div>

Thank you, @cdekker, but I couldn't find this option in the \_reindex documentation page ([https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)).

However, according to the "Important note", if I want to duplicate the source index settings, it's supposed to run the index creation prior to the \_reindex execution, isn't it?

Thanks,

Guilherme

---

<div class="post-metadata">

**Author:** ![guilherme\_maranhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_maranhao/32/101483_2.png) [@guilherme\_maranhao](https://discuss.elastic.co/u/guilherme_maranhao)\
**Post date:** [August 20, 2018, 1:09pm UTC](https://discuss.elastic.co/t/reindex-api-and-date-field/144943/4 "2018-08-20T13:09:32Z")

</div>

Actually, the mappings and settings replication should be default for the \_reindex. Why would you want to reindex (copy) an index without the source settings???

---

<div class="post-metadata">

**Author:** ![cdekker](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cdekker](https://discuss.elastic.co/u/cdekker)\
**Post date:** [August 21, 2018, 8:21am UTC](https://discuss.elastic.co/t/reindex-api-and-date-field/144943/5 "2018-08-21T08:21:53Z")

</div>

It is literally in the first paragraph of the documentation you linked 🙂

> Reindex does not attempt to set up the destination index. It does not copy the settings of the source index. You should set up the destination index prior to running a `_reindex` action, including setting up mappings, shard counts, replicas, etc.

Reindex gives you complete freedom over the destination index, which is why it doesn't set up the destination index for you. For example, we use it when a field mapping changes. In those cases you actually want to manually set up a different destination index mapping before copying over all data.

Other 'cloning' operations such as `_shrink` and `_split` do set up the destination index for you. But in those cases it is also clearly documented.

EDIT: For our use case we have also disabled dynamic index creation and dynamic mapping (adding fields automatically). It saved us a lot of confusing situations by throwing an error instead of magically creating unknown fields 🙂

---

<div class="post-metadata">

**Author:** ![guilherme\_maranhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_maranhao/32/101483_2.png) [@guilherme\_maranhao](https://discuss.elastic.co/u/guilherme_maranhao)\
**Post date:** [August 21, 2018, 12:43pm UTC](https://discuss.elastic.co/t/reindex-api-and-date-field/144943/6 "2018-08-21T12:43:55Z")

</div>

Thank you, @cdekker

> [@cdekker](#):
>
> Other 'cloning' operations such as `_shrink` and `_split` do set up the destination index for you. But in those cases it is also clearly documented.

I didn't know those operations. Maybe I'll try them in the next time.

> [@cdekker](#):
>
> Reindex gives you complete freedom over the destination index, which is why it doesn't set up the destination index for you. For example, we use it when a field mapping changes. In those cases you actually want to manually set up a different destination index mapping before copying over all data.

It makes sense.

Regards!

Guilherme

---

<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:** [September 18, 2018, 12:57pm UTC](https://discuss.elastic.co/t/reindex-api-and-date-field/144943/7 "2018-09-18T12:57:15Z")

</div>

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