Can it possible to be sorted a sublist in Sorting and Ranking?

I have a structure object below

{
    "objectID": "string",
    "superModelId": "string",
    "models": [
      {
        "modelId": "string",
        "price": number,
        "webLabel": "string"
      }
    ]
  }

And add the sorting by models.price ascending like in the image

I then have a sorted list like this

[
  {
    "objectID": "305340",
    "superModelId": "305340",
    "models": [
      {
        "modelId": "8528656",
        "price": 5,
        "webLabel": "Kids' hiking T-Shirt MH500 - Green"
      },
      {
        "modelId": "8528653",
        "price": 5,
        "webLabel": "Kids' hiking T-Shirt - MH500 - Blue"
      }
    ]
  },
  {
    "objectID": "127726",
    "superModelId": "127726",
    "models": [
      {
        "modelId": "8569519",
        "price": 12,
        "webLabel": "Children's Hiking Shorts - MH500 KID Green"
      },
      {
        "modelId": "8530016",
        "price": 8,
        "webLabel": "Kids Hiking Short - MH500 KID - Blue"
      }
    ]
  }
]

But in the second object, I have a sub-list (models) and I want to it would be sorted by price too. Can it possible for this?

I would appreciate any help.

Many thanks!

1 Like

Hello,

I’m not sure to properly understand what you are trying to achieve.

I don’t understand if you’d like to sort the results overal depending on the price of nested models, or if you’d like to simply sort the elements in a given result.

Here come a few ideas to solve your problem.

Split records in multiple ones
If what you want to achieve is to be able to sort the results based on the price, you will need to split each record in multiple records. In your case you would have 1 record pour model.
The reason for this splitting is that you cannot select a models.price as a sort by attribute given it has multiple values. the result of picking that regardless would be somewhat random.

Precompute a custom score
Let’s say you want to keep de current record schema. You could add a new attribute at the to level, for example the average price. This value could computed and added at indexing time and then used as the sort by attribute.

I hope this helps. Let me know.