Sort by multiple values based on nested document

I'm tryin to move my sorting mechanism from application to elasticseach but with no result. All i want to do is sort returned docs in elastic by nested item price and available quantity. Just simple as sql-type order like

order by Quantity desc, Price asc

Here is shortened elasticsearch return in Kibana

"_index": "product_index",
"_id": "1",        
"_source": {                       
    "id": 1
    },
    "sort": [          
          5.9
        ],
        "inner_hits": {
          "variants": {
            "hits": {
              "total": 2,
              "hits": [
                {
                  "_nested": {
                    "field": "variants",
                    "offset": 2
                  },
                  "_score": 0,
                  "_source": {                    
                    "offer_state": 3,
                    "stock_quantity": 2,                    
                    "gross_price": 5.9,                                     
                  }
                },
                {
                  "_nested": {
                    "field": "variants",
                    "offset": 1
                  },
                  "_score": 0,
                  "_source": {                    
                    "offer_state": 3,
                    "stock_quantity": 5,                    
                    "gross_price": 21.9,                    
                  }
                }
              ]
            }
          }
        }

and sort query passed to elastic

"sort": [
    {
      "variants.gross_price": {
        "order": "asc",
        "nested_filter": {
          "bool": {
            "filter": [
              {
                "term": {
                  "variants.offer_state": {
                    "value": 3
                  }
                }
              },
              {
                "range": {
                  "variants.gross_price": {
                    "gt": "0"
                  }
                }
              }              
            ]
          }
        },
        "nested_path": "variants"
      }
    }
  ]

How can i include cascade sorting based on nested document? My expected result is 21.9 in returned "sort": [ ]. Thanks for reply.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.