I'm not sure this is possible in a simple way. Isn't the information available implicitly by the position in the hits array? Or is the hits array getting scrambled by whatever you are using to query elastic?
Ah, I understand your problem now. I was refering to the fact that the position of the doc is obviously also the position in the hits array, but since you're trying to use that inside the same query that is of no help.
I don't know if what you're planning to do is possible. The best I could come up with would be using the _score variable, which would at least preserve the relative position of the documents.
SomeFunction could be something simple like 1/_score, or maybe something more sophisticated. This should give you the relative positioning of all documents that fullfill your condition. However, you obviously wouldn't have the exact position and would lose all information about the "position distance" between the documents.
In addition, the exact _score values obviously will not between consistent at all between different searches. If you need any of that, then I'm afraid I'm out of ideas for you.
As I'm looking for an exact position I'm afraid using the _score won't be sufficient.
I tried using script_fields to get the position but it did not work as expected - For some reason the position of last element is reset to initial value:
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.