Unable to perform group on one field and sort on another field in Terms aggregation

We want to perform group on src_id and sort on field alias1.Is there any possibility to perform this action.

Please find query below.

"aggs": {
    "grp_by_src": {
      "terms": {
        "field": "src_id",
        "order": {
          "alias1": "asc"
        }
      },
      "aggs": {
        "visitor_count": {
          "sum": {
            "field": "visitor_count",
            "missing": 0
          }
        }
      }
    },
    "sum_total": {
      "sum": {
        "field": "visitor_count",
        "missing": 0
      }
    }

}

Hi,

If I understand correctly, you want to sort the result aggregated buckets based on some other field, right? If that is the case, you can use the bucket_sort aggregation. Have a look at the docs for examples.

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