I am using ES 7.10.2
Mappings for fields are as follows:
{
"properties": {
"ItemInfo": {
"type": "nested",
"include_in_parent": true,
"properties": {
"ShipInfo": {
"type": "nested",
"include_in_parent": true,
"properties": {
"City": {
"type": "keyword",
"store": true
}
}
},
"OriginalAmount": {
"type": "double",
"store": true
}
}
}
}
}
Then I indexed the document where some document have "OriginalAmount" while others not.
Now when I query ES for aggregation, where I want to calculate Avg of OriginalAmount for each city, as below:-
POST myindex/_search
{
"from": 0,
"size": 0,
"query": {
"match_all": {
"boost": 1
}
},
"aggregations": {
"City": {
"terms": {
"field": "ItemInfo.ShipInfo.City",
"size": 10
},
"aggregations": {
"OriginalAmount": {
"avg": {
"field": "OriginalAmount"
}
}
}
}
}
}
The result I get is :-
"buckets" : [
{
"key" : "Littleton",
"doc_count" : 5,
"OriginalAmount" : {
"value" : 76.98666666666666
}
},
{
"key" : "Paris",
"doc_count" : 1,
"OriginalAmount" : {
"value" : null
}
}
]
As you can see for document with City "Paris" the avg I am getting is null, as that document is not indexed with OriginalAmount.
Is there any property on ES or any configuration within Aggregation, where it considers parent agg count instead of current aggregation count, so that instead of getting null I will get 0?