I want to get Total Unique email count in a Nested object. Below is the example of the document. When we keep Nested object as property in mapping then the count for cardinality is always showing zero while if that object does not have nested property then it does show unique count with same query. We would like to get unique overall count for nested object field. Below is query for aggregation. For Below data value should be 5. Any help would be appreciated to achieve this.
Sample Document Data
{
{
"ID":"1",
"Email":[
{
"EMAIL":"value1"
},
{
"EMAIL":"value2"
},
{
"EMAIL":"value1"
},
{
"EMAIL":"value2"
}
]
},
{
"ID":"2",
"Email":[
{
"EMAIL":"value3"
},
{
"EMAIL":"value4"
},
{
"EMAIL":"value5"
},
{
"EMAIL":"value3"
}
]
}
}
Aggregation Query
{
"size": 0,
"aggs": {
"count": {
"cardinality": {
"field": "Email.EMAIL.keyword"
}
}
}
}
Mapping Query
{
"mappings":{
"properties":{
"ID":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword"
}
}
},
"Email":{
"type":"nested",
"properties":{
"EMAIL":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword"
}
}
}
}
}
}
}
}