Elastic Search Aggregations / Subtotals

Viewed 86

Is it possible to generate subtotals? I have an aggregation like this:

body_options: {
          aggs:{
            wbs_item_id: {
              terms: {
                field: "wbs_item_id"
              },
              aggs: {
                "total": {
                  "sum": {
                    "field": "total"
                  }
                },
                "invoiced": {
                  "sum": {
                    "field": "invoiced"
                  }
                },
                "forecast": {
                  "sum": {
                    "field": "forecast"
                  }
                },
                "committed": {
                  "sum": {
                    "field": "committed"
                  }
                },
                "accrued": {
                  "sum": {
                    "field": "accrued"
                  }
                }
              }
            }
          }
        }

I also have a wbs_parent_id field that I want to sub total on. Something Like:

  1. Cars (5)

    • Ford (2)
    • Toyota (3)
  2. Fruit (3)

    • Apples (2)
    • Oranges (1)

Can you do this with an Elastic Search aggregation? If so how?

0 Answers
Related