Elasticsearch 8.5 Reindexing with Custom Scripts Causes Document Loss in Partial Updates
I'm a bit lost with I tried several approaches but none seem to work. After trying multiple solutions online, I still can't figure this out. I'm currently attempting to reindex an index in Elasticsearch 8.5 using a custom script for transforming document fields. However, I've encountered an scenario where some documents seem to be missing after the reindexing process, particularly those that involve partial updates. My goal is to ensure that I retain all documents, even when fields are being modified conditionally. To implement the reindexing, I've used the following script: ```json POST _reindex { "source": { "index": "old_index" }, "dest": { "index": "new_index" }, "script": { "source": "if (ctx._source.fieldA == 'old_value') { ctx._source.fieldB = 'new_value'; } else { ctx.op = 'noop'; }" } } ``` This script is designed to update `fieldB` only when `fieldA` has a certain value. I noticed that during the reindexing process, I receive the following warning in the logs: ``` [WARN ][o.e.a.b.TransportBulkAction] [node-1] failed to execute bulk item (index) index old_index:document ``` After the reindexing completes, I check the `new_index`, and it appears that some documents are missing. I've tried running the script without the conditional logic and found that all documents are retained, which indicates that the scenario lies within the script's logic. I've also confirmed that the documents in question exist in `old_index` prior to reindexing. The mapping for both indices is identical, and I've ensured that the fields are correctly defined. I've experimented with using `ctx.op = 'create'` instead of `ctx.op = 'noop'`, but this led to errors when a document already exists in the destination index. Could there be an scenario with how the script is evaluating the conditions, or is there a better way to handle partial updates during reindexing? Any insights or solutions would be greatly appreciated. My development environment is Windows. Any advice would be much appreciated. Am I missing something obvious?