Sorting products inside a category

Hi,
I am trying to find a way to sort products inside a category. I have two pages, One for the home where I am populating data with hierarchical categories.
Here my keys looks like:

"hierarchicalCategories": {
    "lvl0": [
      "Maincategory"
    ],
    "lvl1": [
      "Maincategory > 2nd Categorty"
    ],
    "lvl2": [
      "Maincategory > 2nd Category > 3rd Category"
    ]
  }

Now, On my category page, I use the filter to get products from a particular category. Here I also hide hierarchical Categories and get products using this key:

"CategoryIDs": [
    "1724"
  ]

And apply a filter like this:
filters: CategoryIDs:${categorysearch}

Now what I also want to achieve is to sort products inside a category. I have tried adding a new key which is

"categorySort": {
    "categoryID": orderNumber,
  }

but In facets, it will give me options like categorySort.CategoryID
I have so many categories how can I add each one of them to the facets, and then use filterFacets.

Thank you

Hi @RyanBorn

You had me until the last piece. I’m not sure how your filter plays into sorting/ranking – that’s typically handled via configuration at the index/replica level. Are you planning to query a different index/replica based on the value in this attribute?

Sorry I’m. not following your question.