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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
naw
  • 39
  • 1
  • 8

1 Answers1

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.

  • 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. – Val Dec 02 '15 at 09:44
  • 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.. – naw Dec 02 '15 at 11:42