I'm new to Elastic Search. I need go through all the documents, take the _id
and add it to the _source
as a separate field by script. Is it possible? If yes, сan I have an example of something similar or a link to similar scripts? I haven't seen anything like that on the docks. Why i need it? - Because after that i will do SELECT with Opendistro and SQL. This frame cannot return me fields witch not in source. If anyone can suggest I would be very grateful.
Asked
Active
Viewed 779 times
1

TehD
- 28
- 5
1 Answers
2
There are two options:
First option: Add this new field in your existing index and populate it and build the new index again.
Second option: Simply define a new field in a new index mapping(keep rest all field same) and than use reindex API with below script.
"script": {
"source": "ctx._source.<your-field-name> = ctx._id"
}

Amit
- 30,756
- 6
- 57
- 88
-
2POST index/_doc/_update_by_query `{ "query": { "match_all": {} }, "script": { "source": "ctx._source.docId = ctx._id" } }` Exactly what I need, thanks! – TehD Feb 08 '21 at 12:21