# Elasticsearch Update Doc String Replacement

**URL:** <https://discuss.elastic.co/t/elasticsearch-update-doc-string-replacement/120992>\
**Category:** Elasticsearch\
**Created:** [February 22, 2018, 6:40am UTC](https://discuss.elastic.co/t/elasticsearch-update-doc-string-replacement/120992 "2018-02-22T06:40:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![adityosn](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@adityosn](https://discuss.elastic.co/u/adityosn)\
**Post date:** [February 22, 2018, 6:40am UTC](https://discuss.elastic.co/t/elasticsearch-update-doc-string-replacement/120992/1 "2018-02-22T06:40:54Z")

</div>

I have some documents on my Elasticsearch. I want to update my document contents by using String Regexp.

For example, I would like to replace all http words into https words with in a paragraph, is it possible ?

Thank You

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 22, 2018, 7:36am UTC](https://discuss.elastic.co/t/elasticsearch-update-doc-string-replacement/120992/2 "2018-02-22T07:36:26Z")

</div>

May be with a painless script using the update API?  
Or with the reindex API.

How many documents do you need to update ?

---

<div class="post-metadata">

**Author:** ![adityosn](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@adityosn](https://discuss.elastic.co/u/adityosn)\
**Post date:** [February 22, 2018, 8:13am UTC](https://discuss.elastic.co/t/elasticsearch-update-doc-string-replacement/120992/3 "2018-02-22T08:13:06Z")

</div>

Thank you for your reply.

I tried to construct the script but no idea for now.

I want to update all documents within my index. Here is the sample data struct:  
{  
"id" : 1,  
"content" : "Test Test Test",  
"ImageURL" : "[http://www.image.com/test/image.jpg](http://www.image.com/test/image.jpg)"  
}

For example, I want to change all http into https or change the domain for all documents.

Is there any update script that can update this scheme ? or I just create new index with the data ?

It would be nice if I can do update instead of reimport / make another index.

Thank You

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 22, 2018, 8:41am UTC](https://discuss.elastic.co/t/elasticsearch-update-doc-string-replacement/120992/4 "2018-02-22T08:41:46Z")

</div>

To update 100% of the data, aka reindex, I'd use the reindex API with an ingest script processor.

If you have the source of the data elsewhere, may be it can be easier for you to do this transformation on your application side?

If not, reindex API is the way to go IMO.

---

<div class="post-metadata">

**Author:** ![adityosn](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@adityosn](https://discuss.elastic.co/u/adityosn)\
**Post date:** [February 22, 2018, 10:56am UTC](https://discuss.elastic.co/t/elasticsearch-update-doc-string-replacement/120992/5 "2018-02-22T10:56:15Z")

</div>

Thanks for your reply.

If I use reindex API, do I need to reimport data again ?

I will use transformation by using application if I am stuck with elastic natives API haha.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 22, 2018, 11:14am UTC](https://discuss.elastic.co/t/elasticsearch-update-doc-string-replacement/120992/6 "2018-02-22T11:14:34Z")

</div>

> If I use reindex API, do I need to reimport data again ?

Hmmm. Not sure I understand it.  
I'd say "no".

Reindex API reads data from elasticsearch using `_source` field and reindex all in another index.

---

<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:** [March 22, 2018, 11:15am UTC](https://discuss.elastic.co/t/elasticsearch-update-doc-string-replacement/120992/7 "2018-03-22T11:15:15Z")

</div>

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