Hello there!
I would like to report a behavior that, in my opinion, seems unusual.
I have the following document indexed in OpenSearch, which has a field that is a vector with the values: [0, 0, 64, 61, 50].
{
"_index": "test_nico",
"_id": "513",
"_score": 1,
"_source": {
"dish_orders_coverage": [
0,
0,
64,
61,
50
]
}
}
The following query on the index calculates the score based on the content at the position of the vector passed to the function:
GET test_nico/_search
{
"query": {
"function_score": {
"query": {
"ids": {
"values": [
"513"
]
}
},
"script_score": {
"script": {
"source": "def vector = doc['dish_orders_coverage']; return vector[params.meal_moment_slot]",
"params": {
"meal_moment_slot": 2
}
}
},
"boost_mode": "replace"
}
}
}
The score of that function returns 50 when we pass the position 2 as a parameter, although this is computationally incorrect, as the value at position 2 in the vector should be 64, not 50.
Upon further observation, it appears that when the vector is processed within the function score, the values of the vector are being sorted in ascending order and then it is processed.
The following table displays the score results based on the positions of the vector in the script:
param | score
0 | 0
1 | 0
2 | 50
3 | 61
4 | 64
I would like someone to explain this behavior to me. I understand that this ascending sorting should never occur.