Skip to content

[BUG] aggregation on nested field returns incorrect result #14347

Closed
@LantaoJin

Description

@LantaoJin

Describe the bug

Aggregation value_count on field of nested type returns incorrect result. This issue only happens on nested type, object type without nested looks fine.

Related component

Search:Aggregations

To Reproduce

Repro:

# create an test index with nested field
PUT test_nested_field_index
{
  "mappings" : {
    "properties": {
      "patients": { 
        "type" : "nested"
      }
    }
  }
}
# add some testing data
PUT test_nested_field_index/_doc/100
{ 
  "patients": [ 
    {"name" : "John Doe", "age" : 56, "smoker" : true},
    {"name" : "Mary Major", "age" : 85, "smoker" : false}
  ] 
}
# value_count should return 2 instead of 0
GET test_nested_field_index/_search
{
  "size": 0,
  "aggs": {
    "count_patients_name": {
      "value_count": {
        "field": "patients.name.keyword"
      }
    }
  }
}

Expected behavior

value_count should return 2 instead of 0

Additional Details

Plugins
Please list all plugins currently enabled.

Screenshots
If applicable, add screenshots to help explain your problem.

Host/Environment (please complete the following information):

  • OS: Mac
  • Version 2.14

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions