I am trying to write a script to calculate the euclidean distance for some points stored as an array. Each array consists of 128 Double values.
The field is currently indexed and stored as such:
"my_array": [0.176, 0.165, 0.987, 0.67, ...]
When I use Painless to read and loop the array using doc['my_array'].values; it returns the array sorted for some reason. So instead of the above I get the array as:[0.165, 0.176, 0.67, 0.987, ...]
What other options do I have to get the array in the same order?
Values are indeed always returned in order. If you need to maintain order, one potential trick is to encode your values in such a way that they will be in order, for instance if all values are between 0 and 1, you could add the index to all values at index time, ie. [0.176, 0.165, 0.987, 0.67, ...] becomes [0.176, 1.165, 2.987, 3.67, ...] and then subtract it at search time.
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.