Sort results by inner hits (min/max)

I'm using a join field and an has_child filter in my search to join products with their various configuration permutations.
There's a single level join from a product to a configuration. When a user searches for something the has_child filter is used to return only the matching products with only the matching configurations.

The configurations have different prices and I'm wondering how to sort the products by the price, and how to set the sort mode (e.g. "min" or "max") so that if a user sorts by "Price (Low-High)" it sorts by "configurations.price" using the "min" mode "asc".

I've had a look around various docs and I can't see how to do this, I only found some unanswered posts here but really need to get this working.

Here's an example query which would need to be sorted:

GET /tours/_search
{
  "sort": [
   // What to put here to sort the results by the inner date or price fields?
  ],
  "query": {
    "bool": {
      "should": [
        {
          "match_all": {}
        }
      ],
      "filter": [
        {
          "match": {
            "organization_id": "01h90c44kh5h92qykyqdjh5htn"
          }
        },
        {
          "has_child": {
            "inner_hits": {
              "size": 100,
              "sort": {
                "dates": "asc"
              }
            },
            "type": "departure",
            "query": {
              "bool": {
                "should": [
                  {
                    "match_all": {}
                  }
                ],
                "filter": [
                  {
                    "term": {
                      "published": true
                    }
                  },
                  {
                    "bool": {
                      "should": [
                        {
                          "bool": {
                            "filter": [
                              {
                                "term": {
                                  "kind": "fixed"
                                }
                              },
                              {
                                "range": {
                                  "dates": {
                                    "gte": "now",
                                    "relation": "within"
                                  }
                                }
                              }
                            ]
                          }
                        },
                        {
                          "bool": {
                            "filter": [
                              {
                                "term": {
                                  "kind": "fixed_duration"
                                }
                              },
                              {
                                "range": {
                                  "dates": {
                                    "gte": "now",
                                    "relation": "intersects"
                                  }
                                }
                              }
                            ]
                          }
                        }
                      ]
                    }
                  },
                  {
                    "exists": {
                      "field": "lead_prices.GBP"
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

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