Add another one sorting to lift 3 docs to positions 3,4,5

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! :open_mouth: ). 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

Sorry, my mistake. The big difficulty here is that I'll be probably passing more than 3 ids, but I need not more than 3 docs to float

Have you considered using the multi search API to send 2 separate queries, one for the query and one for the prioritised documents, and then merge the result sets client side? This is as far as I can recall the standard solution for the type of mixed sorting you are describing.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.