Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cumulative sum use field rather then buckets_path #149

Closed
2qU24Tlb opened this issue Aug 30, 2017 · 3 comments
Closed

cumulative sum use field rather then buckets_path #149

2qU24Tlb opened this issue Aug 30, 2017 · 3 comments
Labels

Comments

@2qU24Tlb
Copy link

in cumulative aggregation, the default key should be buckets_path rather then field

@ferronrsmith
Copy link
Collaborator

ferronrsmith commented Sep 7, 2017

bodybuilder().aggregation('date_histogram', {
        "field": "date",
        "interval": "month"
    }, 'sales_per_month', agg =>
    agg.aggregation('sum', 'price', 'sales')
    .aggregation('cumulative_sum', {
        buckets_path: 'sales'
    }, 'cumulative_sales')
).build()

maps to =>

{
    "size": 0,
    "aggs" : {
        "sales_per_month" : {
            "date_histogram" : {
                "field" : "date",
                "interval" : "month"
            },
            "aggs": {
                "sales": {
                    "sum": {
                        "field": "price"
                    }
                },
                "cumulative_sales": {
                    "cumulative_sum": {
                        "buckets_path": "sales" 
                    }
                }
            }
        }
    }
}

@danpaz
Copy link
Owner

danpaz commented Sep 7, 2017

@unioah You should be able to override the default key by passing an object as the second argument to bodybuilder.aggregation. For example:

bodybuilder()
  .aggregation('cumulative_sum', { buckets_path: 'the_sum' }, 'name_me')
  .build()

@ferronrsmith
Copy link
Collaborator

Added the example from the documentation page above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants