Pin ES Documents at specific position

I have some documents in ES Index in which I have a requirement to pin the documents at specific index positions irrespective of their score based on the ids.

I tried pinned query but it fetching and pinning the documents on top. But I want to place the pinned items at specific positions.

My Data:

    {
      "docs": [
        {
          "_id": 1,
          "name": "jack",
          "score": 40
        },
        {
          "_id": 4,
          "name": "taylor",
          "score": 35
        },
        {
          "_id": 3,
          "name": "mark",
          "score": 20
        },
        {
          "_id": 2,
          "name": "ryan",
          "score": 10
        }
      ]
    }

Suppose I have pinned documents at index 2 and 4 based on its id values and the final response should be like below

Response:

      "docs": [
        {
          "_id": 1,
          "name": "jack",
          "score": 40
        },
        {
          "_id": 2,
          "name": "ryan",
          "score": 10
        },
        {
          "_id": 3,
          "name": "mark",
          "score": 20
        },
        {
          "_id": 4,
          "name": "taylor",
          "score": 35
        }
      ]
    }

Can someone please add some insights and inputs to solve this requirement.

Thanks& Regards.

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