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 not providing expected results #51993

Closed
veeraraghavan-s opened this issue Feb 6, 2020 · 1 comment
Closed

Sum bucket aggregation not providing expected results #51993

veeraraghavan-s opened this issue Feb 6, 2020 · 1 comment

Comments

@veeraraghavan-s
Copy link

veeraraghavan-s commented Feb 6, 2020

I am trying to fetch latest status for all devices and then use sum bucket to calculate the total hits for a particular status. Please see my query below.
The value from the sum bucket always returned as 0.0.
I don't have any zero values in my data and the sum(statusInt) value is 1.0
Tested in Elasticsearch version 6.7
Also what is strange is it does not throw any error.

Is this related to #25273
But I don't get any error.

REQUEST

{
  "size": 0,
  "aggs": {
"devicelist": {
  "terms": {
    "field": "device",
    "size": 9999},
    "aggs": {
      "currentstatus": {
        "terms": {
          "field": "status.keyword",
          "size": 1,
          "order": {
            "latest": "desc"
          }},
          "aggs": {
            "latest": {
              "max": {
                "field": "time"
              }
            },
            "total": {
              "sum": {
                "field": "statusInt"
              }
            }
      }
    }
  }
},
"sumd": {
  "sum_bucket": {
    "buckets_path": "devicelist>currentstatus['SUCCESS']>total"
  }
}
  }
}

RESPONSE

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 5,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "aggregations" : {
    "devicelist" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "DEVICE1",
          "doc_count" : 3,
          "currentstatus" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 2,
            "buckets" : [
              {
                "key" : "SUCCESS",
                "doc_count" : 1,
                "total" : {
                  "value" : 1.0
                },
                "latest" : {
                  "value" : 1.579865333E12,
                  "value_as_string" : "2020-01-24T11:28:53.000Z"
                }
              }
            ]
          }
        },
        {
          "key" : "DEVICE2",
          "doc_count" : 1,
          "currentstatus" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 0,
            "buckets" : [
              {
                "key" : "SUCCESS",
                "doc_count" : 1,
                "total" : {
                  "value" : 1.0
                },
                "latest" : {
                  "value" : 1.579865153E12,
                  "value_as_string" : "2020-01-24T11:25:53.000Z"
                }
              }
            ]
          }
        },
        {
          "key" : "DEVICE3",
          "doc_count" : 1,
          "currentstatus" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 0,
            "buckets" : [
              {
                "key" : "DELETED",
                "doc_count" : 1,
                "total" : {
                  "value" : 2.0
                },
                "latest" : {
                  "value" : 1.579865393E12,
                  "value_as_string" : "2020-01-24T11:29:53.000Z"
                }
              }
            ]
          }
        }
      ]
    },
    "sumd" : {
      "value" : 0.0
    }
  }
}
@jasontedor
Copy link
Member

Thanks very much for your interest in Elasticsearch.

This appears to be a user question, and we'd like to direct these kinds of things to the forums. If you can stop by there, we'd appreciate it. This allows us to use GitHub for verified bug reports, feature requests, and pull requests.

There's an active community in the forums that should be able to help get an answer to your question. As such, I hope you don't mind that I close this.

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

No branches or pull requests

2 participants