# Reindex API - Reference doc

**URL:** <https://discuss.elastic.co/t/reindex-api-reference-doc/103140>\
**Category:** Elasticsearch\
**Created:** [October 8, 2017, 6:55am UTC](https://discuss.elastic.co/t/reindex-api-reference-doc/103140 "2017-10-08T06:55:13Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaharmor](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@shaharmor](https://discuss.elastic.co/u/shaharmor)\
**Post date:** [October 8, 2017, 6:55am UTC](https://discuss.elastic.co/t/reindex-api-reference-doc/103140/1 "2017-10-08T06:55:13Z")

</div>

Hi,

I'm trying to use the Reindex API to update an existing document, but I can't seem to find how to increment the value of the existing field with the value of the new document.

---

<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:** [October 8, 2017, 7:25am UTC](https://discuss.elastic.co/t/reindex-api-reference-doc/103140/2 "2017-10-08T07:25:01Z")

</div>

I don’t understand. When you reindex, you reindex an old document. What do you mean by referencing the value of a new document?

---

<div class="post-metadata">

**Author:** ![shaharmor](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@shaharmor](https://discuss.elastic.co/u/shaharmor)\
**Post date:** [October 8, 2017, 7:31am UTC](https://discuss.elastic.co/t/reindex-api-reference-doc/103140/3 "2017-10-08T07:31:15Z")

</div>

Forget it. I though you can also update the existing doc when using the Reindex API, but apparently you can't.

---

<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:** [October 8, 2017, 8:05am UTC](https://discuss.elastic.co/t/reindex-api-reference-doc/103140/4 "2017-10-08T08:05:58Z")

</div>

But you can.

You can add an ingest pipeline with a painless script which edits the old document before reindexing it.

---

<div class="post-metadata">

**Author:** ![shaharmor](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@shaharmor](https://discuss.elastic.co/u/shaharmor)\
**Post date:** [October 8, 2017, 8:09am UTC](https://discuss.elastic.co/t/reindex-api-reference-doc/103140/5 "2017-10-08T08:09:33Z")

</div>

Hmm thats a really good point. Can i also use that for upserting when the doc doesn't exist?

---

<div class="post-metadata">

**Author:** ![shaharmor](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@shaharmor](https://discuss.elastic.co/u/shaharmor)\
**Post date:** [October 8, 2017, 8:16am UTC](https://discuss.elastic.co/t/reindex-api-reference-doc/103140/6 "2017-10-08T08:16:50Z")

</div>

I don't see where in the docs of the script processor I can access both the existing doc and the new doc

---

<div class="post-metadata">

**Author:** ![shaharmor](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@shaharmor](https://discuss.elastic.co/u/shaharmor)\
**Post date:** [October 8, 2017, 8:52am UTC](https://discuss.elastic.co/t/reindex-api-reference-doc/103140/7 "2017-10-08T08:52:52Z")

</div>

I'm actually pretty sure you can't do it, as the ingestion phase can be located to different nodes which don't hold the data.

---

<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:** [October 8, 2017, 9:32am UTC](https://discuss.elastic.co/t/reindex-api-reference-doc/103140/8 "2017-10-08T09:32:14Z")

</div>

> [@shaharmor](#):
>
> Can i also use that for upserting when the doc doesn't exist?

That’s confusing. Reindex API is reindexing documents from an existing index. So the document exists for sure.

---

<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:** [October 8, 2017, 9:33am UTC](https://discuss.elastic.co/t/reindex-api-reference-doc/103140/9 "2017-10-08T09:33:17Z")

</div>

The “new” doc is the existing doc. I think you are not understanding what reindex api is.

---

<div class="post-metadata">

**Author:** ![shaharmor](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@shaharmor](https://discuss.elastic.co/u/shaharmor)\
**Post date:** [October 8, 2017, 9:37am UTC](https://discuss.elastic.co/t/reindex-api-reference-doc/103140/10 "2017-10-08T09:37:06Z")

</div>

I understand.

Its "re-indexing" existing documents from 1 index to another.

But there can be a situation where you have 3 documents:  
Given you are re-indexing from index1 to index2:

1. the original document in index1
2. an existing document in index2
3. the re-indexed document that is being copied from index1 to index2

If I set the `ctx._id` of the soon-to-be-reindexed document to the same as an existing one, it will override the older doc with this new one.

My question is, can I use the same Reindex API to **update** the old document instead of overriding it?

---

<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:** [October 8, 2017, 10:22am UTC](https://discuss.elastic.co/t/reindex-api-reference-doc/103140/11 "2017-10-08T10:22:46Z")

</div>

I see.

No it will override.

But if you have a document

```
{
  “foo”: “bar”
}

```

And reindex it, it will become:

```
{
  “foo”: “bar”
}

```

You can apply an ingest script if you wish so you document can become:

```
{
  “foo”: “barbaz”,
  “age”: 20
}

```

If you wish

---

<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:** [November 5, 2017, 10:22am UTC](https://discuss.elastic.co/t/reindex-api-reference-doc/103140/12 "2017-11-05T10:22:59Z")

</div>

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