Hello. I would like to query my documents in my index based on their _version.
I have tried a couple of solutions but none of them worked, hopefully you might be able to assist me with this.
My attempts are:
- Executing an _update_by_query request on all documents and assigning _version to a new, indexable field:
POST testing_index/_update_by_query
{
"query": {
"match_all": {}
},
"script": {
"lang": "painless",
"source": "ctx._source['version'] = ctx._version;"
}
}
However the value in 'version' shows -1 for all documents.
2. Creating an ingest pipeline with a script processor (also tried a "set" processor)
PUT _ingest/pipeline/version_searchable
{
"description" : "Moves _version to indexable field version",
"processors" : [
{
"script" : {
"source" : "ctx.version = ctx._version;"
}
}
]
}
POST testing_index/_update_by_query?pipeline=version_searchable
And in this attempt the version shows -3 oddly enough.
Am I doing something wrong here? Or is there maybe a better way of accomplishing this?
Appreciate the assistance 