0
{
  "skus" : [
    {
      "inv" : 426,
      "sub_category_id" : 677
    },
    {
      "inv" : 112,
      "sub_category_id" : 678
    },
    {
      "inv" : 0,
      "sub_category_id" : 611
    }
  ]
}

I have the document called 'product' with child object sku and i want to sort my product in a fashion that the if the number of sku with inv as 0 is more than 50% of total skus for the product should always go down and if it is not 50%, the order should not be affected.

1 Answer 1

1

The simpiest (and probably the most performance cost effective) way is to add computed field to your product object for a sorting purpose and compute it on each index/update product request.

Sign up to request clarification or add additional context in comments.

2 Comments

Agreed! @naw, If you know in advance you'll need that information, you might as well index it. Otherwise, you'll have to resort to obscure scripting in order to achieve what you need.
I was clear about indexing with a new score field but if this same thing can be achieved using SortingScriptBuilder? I was more interested in achieving this through a custom sort/group..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.