Division between two sum fields and order by the result

Hi,
I need help to order by the division between two sum fields, how can I do ? Something like this

{
  "aggs": {
    "field1": {
      "terms": { 
        "field": "field1",
        "size":50,
        "order": division
      },
      "aggs":{
        "field2":{
          "sum":{
            "field":"field2"
          }
        },
        "field3":{
          "sum":{
            "field":"field3"
          }
        },
        "division": {
          "bucket_script": {
            "buckets_path": {
               "my_var1": "field2",
               "my_var2": "field3"
             },
            "script": "params.my_var1 / params.my_var2"
           }
         }
      }
    }
  }
}

This aggregation actually dose not work because the pipeline aggregation cannot be used for order, so how can I do ?

It is not possible.

Are there any other work arounds to make this possible? like using script?

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