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

Sum bucket aggregation cannot sum more than one level deep #25273

Closed
andrewvc opened this issue Jun 16, 2017 · 7 comments · Fixed by #40068
Closed

Sum bucket aggregation cannot sum more than one level deep #25273

andrewvc opened this issue Jun 16, 2017 · 7 comments · Fixed by #40068

Comments

@andrewvc
Copy link
Contributor

Executing a sum_bucket aggregation with a bucket path multiple levels deep, like bucket_1>bucket_2>metric will fail with:

{
  "error": {
    "root_cause": [],
    "type": "search_phase_execution_exception",
    "reason": "",
    "phase": "fetch",
    "grouped": true,
    "failed_shards": [],
    "caused_by": {
      "type": "aggregation_execution_exception",
      "reason": "buckets_path must reference either a number value or a single value numeric metric aggregation, got: java.lang.Object[]"
    }
  },
  "status": 503
}

It would be preferable that this work. You can work around this by having one sum_bucket per aggregation depth level, but it would be nice to either have this return a more relevant error or just work.

@andrewvc
Copy link
Contributor Author

After discussing this with @polyfractal it seems that this is most likely only the case with nested terms aggregations.

@andrewvc andrewvc changed the title Sum bucket aggregation cannot some more than one level deep Sum bucket aggregation cannot some sum than one level deep Jun 20, 2017
@andrewvc andrewvc changed the title Sum bucket aggregation cannot some sum than one level deep Sum bucket aggregation cannot sum more than one level deep Jun 20, 2017
@colings86
Copy link
Contributor

colings86 commented Jun 20, 2017

This will be true for any nested aggregations (e.g. terms>histogram) and was made like this by design. I agree that we should improve the error message here but I am hesitant to support summing over multiple levels as its possible to do (like you say) with multiple sum_bucket aggregations and we don't currently have support int eh bucket_path syntax for traversing multi bucket aggregations

@andrewvc
Copy link
Contributor Author

@colings86 I think that makes sense. I do think it'd be better to return a 422 response code than a 503, along with a more helpful error.

@andrewvc
Copy link
Contributor Author

I'll just say that I was confused by this for a while till I did some experiments and determined the workaround.

@colings86 colings86 added help wanted adoptme and removed discuss labels Jun 20, 2017
@colings86 colings86 removed their assignment Jun 27, 2017
@polyfractal
Copy link
Contributor

@elastic/es-search-aggs

Note: keeping this open because we should fix the error message to be more helpful (display the name of the path component that was not compatible), not the underlying issue of pathing through a multi-bucket.

polyfractal added a commit to polyfractal/elasticsearch that referenced this issue Apr 25, 2018
Instead of throwing a technical error (`found Object[]`), we can check
to see if any of the referenced aggs are a multi-bucket agg and throw
a friendlier exception.

Closes elastic#25273
@ssmulders
Copy link

ssmulders commented Nov 5, 2020

After a lot of digging I came here as well, to find it's not a bug but a feature. The error message threw me off as well.

I was trying to do a extended_stats_bucket on a result that was first bucketed by modelId, and then another layer that bucketed the results in 24 hour chunks with date_histogram, which had an agg that summed up a specific value in that 24 hour window.

This produced a result like this, that I was unable to unleash the stats on:

  "aggregations" : {
    "models" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : 1602,
          "doc_count" : 116,
          "24_hour_windows" : {
            "buckets" : [
              {
                "key_as_string" : "2019-03-01T00:00:00.000Z",
                "key" : 1551398400000,
                "doc_count" : 11,
                "value" : {
                  "value" : 39.0
                }
              },
              {
                "key_as_string" : "2019-03-02T00:00:00.000Z",
                "key" : 1551484800000,
                "doc_count" : 18,
                "value" : {
                  "value" : 59.0
                }
              },

Erroring out with:

{
  "error" : {
    "root_cause" : [ ],
    "type" : "search_phase_execution_exception",
    "reason" : "",
    "phase" : "fetch",
    "grouped" : true,
    "failed_shards" : [ ],
    "caused_by" : {
      "type" : "aggregation_execution_exception",
      "reason" : "buckets_path must reference either a number value or a single value numeric metric aggregation, got: [Object[]] at aggregation [24_hour_windows]"
    }
  },
  "status" : 500
}

I would have expected models>24_hour_windows>value to work.

@jaymc-arg
Copy link

@ssmulders so how did you solve it? i don't get what feature you are talking about.

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

Successfully merging a pull request may close this issue.

5 participants