Get document id (_id) inside a native script


(Jconwell) #1

I've got a native script that runs as a transform when adding a new document. I need the document id but its not passed in as part of the script params. Is there any way to get ElasticSearch to pass in the document id? Or some way of reading it ... somehow?


(Mark Walkom) #2

You'd have to define it yourself as otherwise ES generates one automatically, and it cannot pass that to the script until it's been indexed (catch-22).


(Jconwell) #3

I do define it and pass it in when calling prepareIndex(), but the native script (implementation of AbstractExecutableScript) only gets passed the values for _source, and not the _id.

Is there a way I can ask for the _id?


(system) #4