Would it be possible to script the sort order of aggregations? Let me
explain with a contrived example:

{
   "aggs": {
      "agg1": {
         "terms": {
            "field": "somefield",
            "order": {
               "avg1": "desc"
            },
            "size" : 100
         },
         "aggs": {
            "avg1": {
               "avg": {
                  "field": "someotherfield"
               }
            }
         }
      }
   }

The above example will return an aggregation where the buckets are sorted
based on the average of some other field of the bucketized documents.
Pretty easy. What I would actually want is to do some more complex math
such as the average of the bucketized documents times the number of
documents in the bucket.

The metric aggregation script, as far as I can tell, does not have access
to information of the bucket it is in.

{ "script" : "doc['someotherfield'].value * ?bucket.count?" }

The aggregation order also does not offer script based sorting.

        "order": {
          "_script": {
            "script": "bucket.avg * bucket.count",
            "type": "number",
            "order": "desc"
          }
        }

Very pseudo code example above. My hope is that perhaps I missed the fact
that Elasticsearch does support one of these two scenarios. If not, are
there any workarounds to fine-tune sort order? Secondary sorting would also
help.

Cheers,

Ivan

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCLxU%3DFTddW%3DesWLWHz0G-SO_oN7Zb4OE4o%3DVdwyRw%2BkQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to