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

[BUG] Sum aggregation returns 0 which all documents have null values for the field #17581

Open
gaobinlong opened this issue Mar 13, 2025 · 0 comments
Labels

Comments

@gaobinlong
Copy link
Collaborator

gaobinlong commented Mar 13, 2025

Describe the bug

When performing sum aggregation on a field which doesn't exist in all the documents or all documents have explicit null value for that field, the aggregation result shows 0, which is not as expected, null makes more sense. And you can see that, the avg/max/min aggregation returns null.

Request:

GET test1/_search
{
  "size": 0,
  "aggs": {
    "stats-agg": {
      "stats": {
        "field": "a"
      }
    }
  }
}

result:

{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 3,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  },
  "aggregations": {
    "stats-agg": {
      "count": 0,
      "min": null,
      "max": null,
      "avg": null,
      "sum": 0
    }
  }
}

Related component

Search:Aggregations

To Reproduce

  1. DELETE test1
PUT test1/_mapping
{
  "properties":{
    "a":{
      "type":"integer"
    }
  }
}
POST test1/_doc?refresh
{
  "a":null
}
  1. Check the result
GET test1/_search
{
  "size": 0,
  "aggs": {
    "stats-agg": {
      "stats": {
        "field": "a"
      }
    }
  }
}

Expected behavior

Sum aggregation returns null rather than 0 for the case that all documents have null values for the field the aggregation performs on.

Additional Details

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant