I have a query with several sortings. Here is the sorting part:
"sort": [
"isHistorical",
"_score",
{
"_script": {
"type": "number",
"script": {
"lang": "painless",
"source": "double score = 0; for (int i = 0; i < params.scalar_values.length; ++i) { if (doc[params.scalar_values[i].field].value == params.scalar_values[i].value) { score += params.scalar_values[i].score; } } for (int i = 0; i < params.array_values.length; ++i) { if (doc[params.array_values[i].field].contains(params.array_values[i].value)) { score += params.array_values[i].score; } } return score;",
"params": {
"scalar_values": [],
"array_values": []
}
},
"order": "desc"
}
},
{
"inStock": {
"order": "desc"
},
"daysUntilReadinessForPickup": {
"order": "asc"
},
"numberTradePointsForNearestPickup": {
"order": "desc"
},
"availableInTradePointsCount": {
"order": "desc"
}
}
]
After all sortings applied (and before limit) I want to add another sorting. It is related to prioritized documents.
Every doc has field "assortmentUnitId" of integer type. I have a list of assortmentUnitIds, each of them has sort order value. where sort order of 0 is the top priority. 1 is less, and so far.
assortmentUnitId = 123, sort order = 0
assortmentUnitId = 456, sort order = 1
assortmentUnitId = 789, sort order = 2
assortmentUnitId = 999, sort order = 5
I want to pass this map (assortmentUnitId => sortOrder) to the query so that
after applying all the other sortings these prioritized docs go up in the result list to the position 3, 4, 5 (not right at the beginning! ). I'll be passing only 3 prioritized values to the query
Is it possible? Can you guide me how to achieve this? Should I give your the other parts of the request? Thanks