Can you reindex to the same index

I have an existing indice and want to multiply this data with a small modification to it, simply increment a few fields, but the rest of the data can remain the same. Hence, I am not looking to actually change the mappings of the indice, but simply to copy it on top of what's existingly there.

This way I could just restore the data from a SNAPSHOT with 2x shard count before re-indexing onto itself. I was wondering that since there isn't any mapping modification, would it be possible to index an indice onto itself?

Something that would look like this:

POST <index>/<index_type>/_reindex
{
  "source": {
    "index": "<index_name>"
  },
  "dest": {
    "index": "<index_name>",
  },
  "script": {
		"source": """
ctx._source.bene_acc_no += '21'; 
ctx._source.orig_acc_no += '21'; 
ctx._source.owner_acc_no += '21';
"""    
"lang": "painless"
  }
}

If this is not possible

Thank you in advance for your help.

Check out update by query

Thank you Alexander for your response.

The Update API modifies the data and replaces the old one. I would like to modify the data and to copy it on top of the original data.

I could use reindex API to a new index and then use aliases for queries to point to both indices. I was just wondering if it would be possible to reindex to itself instead?

reindex to itself is not possible. Also you want two operations per document (change and reindex), this is not possible either.

Going with reindex and aliases (always use aliases.. all the time) sounds like the way to go in your case.

1 Like

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