[source, ruby]
----
response = client.search(
  index: 'sales',
  body: {
    size: 0,
    aggregations: {
      sales_per_month: {
        date_histogram: {
          field: 'date',
          calendar_interval: 'month'
        },
        aggregations: {
          total_sales: {
            sum: {
              field: 'price'
            }
          },
          sales_bucket_sort: {
            bucket_sort: {
              sort: [
                {
                  total_sales: {
                    order: 'desc'
                  }
                }
              ],
              size: 3
            }
          }
        }
      }
    }
  }
)
puts response
----
