# Reindex with text replace

**URL:** <https://discuss.elastic.co/t/reindex-with-text-replace/182908>\
**Category:** Elasticsearch\
**Created:** [May 27, 2019, 12:23pm UTC](https://discuss.elastic.co/t/reindex-with-text-replace/182908 "2019-05-27T12:23:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_Fredriksson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martin_fredriksson/32/46892_2.png) [@Martin\_Fredriksson](https://discuss.elastic.co/u/Martin_Fredriksson)\
**Post date:** [May 27, 2019, 12:23pm UTC](https://discuss.elastic.co/t/reindex-with-text-replace/182908/1 "2019-05-27T12:23:59Z")

</div>

I was trying to reindex a large index when I discovered that there are trailing \r\n in the end of all values of a field. Since the mapping in the new index for this field is a double, and not a string, it crashes.

How do I replace/trim these values to in the reindex process?

---

<div class="post-metadata">

**Author:** ![gbrown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gbrown/32/34482_2.png) [@gbrown](https://discuss.elastic.co/u/gbrown)\
**Post date:** [May 28, 2019, 11:10pm UTC](https://discuss.elastic.co/t/reindex-with-text-replace/182908/2 "2019-05-28T23:10:41Z")

</div>

If all you want to do is trim whitespace on the one field, you can set up an [ingest pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/7.0/ingest.html) with the [trim processor](https://www.elastic.co/guide/en/elasticsearch/reference/7.0/trim-processor.html) set up for the field, then specify the pipeline in your reindex request like so:

```auto
POST _reindex
{
  "source": {
    "index": "source_index"
  },
  "dest": {
    "index": "dest_index",
    "pipeline": "trim_my_double_field_pipeline"
  }
}

```

(above example pulled with minor changes from the [Reindex docs](https://www.elastic.co/guide/en/elasticsearch/reference/7.0/docs-reindex.html))

Alternatively, you could use a script in the reindex request, but using an ingest pipeline is probably easier.

---

<div class="post-metadata">

**Author:** ![Martin\_Fredriksson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martin_fredriksson/32/46892_2.png) [@Martin\_Fredriksson](https://discuss.elastic.co/u/Martin_Fredriksson)\
**Post date:** [May 29, 2019, 7:30am UTC](https://discuss.elastic.co/t/reindex-with-text-replace/182908/3 "2019-05-29T07:30:29Z")

</div>

Thank you Gordon!

---

<div class="post-metadata">

**Author:** ![Martin\_Fredriksson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martin_fredriksson/32/46892_2.png) [@Martin\_Fredriksson](https://discuss.elastic.co/u/Martin_Fredriksson)\
**Post date:** [May 29, 2019, 7:40am UTC](https://discuss.elastic.co/t/reindex-with-text-replace/182908/4 "2019-05-29T07:40:17Z")

</div>

It works! And I learned something...

---

<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:** [June 26, 2019, 7:40am UTC](https://discuss.elastic.co/t/reindex-with-text-replace/182908/5 "2019-06-26T07:40:18Z")

</div>

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