Search code examples
elasticsearchelasticsearch-java-api

Sorting on child occurrences Elasticsearch JAVA API


{
  "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.


Solution

  • 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.