Reindex API - Reference doc


(Shahar Mor) #1

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.


(David Pilato) #2

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


(Shahar Mor) #3

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


(David Pilato) #4

But you can.

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


(Shahar Mor) #5

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


(Shahar Mor) #6

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


(Shahar Mor) #7

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.


(David Pilato) #8

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


(David Pilato) #9

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


(Shahar Mor) #10

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?


(David Pilato) #11

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


(system) #12

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