# Nested field empty values aggregation returns the wrong value

**URL:** <https://discuss.elastic.co/t/nested-field-empty-values-aggregation-returns-the-wrong-value/90979>\
**Category:** Elasticsearch\
**Created:** [June 27, 2017, 2:30pm UTC](https://discuss.elastic.co/t/nested-field-empty-values-aggregation-returns-the-wrong-value/90979 "2017-06-27T14:30:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shashi-GS](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Shashi-GS](https://discuss.elastic.co/u/Shashi-GS)\
**Post date:** [June 27, 2017, 2:30pm UTC](https://discuss.elastic.co/t/nested-field-empty-values-aggregation-returns-the-wrong-value/90979/1 "2017-06-27T14:30:29Z")

</div>

I have the following nested mapping for the data.  
{  
"index": {  
"mappings": {  
"type": {  
"\_all": {  
"enabled": false  
},  
"properties": {  
"A": {  
"type": "nested",  
"properties": {  
"productmaster\_FABRIC": {  
"type": "string",  
"index": "not\_analyzed",  
"fielddata": {  
"format": "doc\_values",  
"loading": "eager\_global\_ordinals"  
},  
"fields": {  
"hash": {  
"type": "murmur3",  
"precision\_step": 2147483647  
}  
},  
"null\_value": "null",  
"ignore\_above": 10922  
}  
}  
},  
"purchaseli\_QTY": {  
"type": "integer"  
}  
}  
}  
}  
}  
}

sample data for the object is  
[{purchaseli\_QTY : 1, productmaster\_FABRIC:"cotton"},{purchaseli\_QTY : 2, productmaster\_FABRIC:"polyster"}, {purchaseli\_QTY : 1, productmaster\_FABRIC:"rymonds"},  
{purchaseli\_QTY : 8, productmaster\_FABRIC:""},{purchaseli\_QTY : 5, productmaster\_FABRIC:"cotton"},{purchaseli\_QTY : 2, productmaster\_FABRIC:"polyster"}, {purchaseli\_QTY : 5, productmaster\_FABRIC:"rymonds"},  
{purchaseli\_QTY : 9, productmaster\_FABRIC:""},{purchaseli\_QTY : 1, productmaster\_FABRIC:"cotton"},{purchaseli\_QTY : 2, productmaster\_FABRIC:"polyster"}, {purchaseli\_QTY : 1, productmaster\_FABRIC:"rymonds"},  
{purchaseli\_QTY : 8, productmaster\_FABRIC:""},{purchaseli\_QTY : 1, productmaster\_FABRIC:"cotton"},{purchaseli\_QTY : 2, productmaster\_FABRIC:"polyster"}, {purchaseli\_QTY : 1, productmaster\_FABRIC:"rymonds"},  
{purchaseli\_QTY : 8, productmaster\_FABRIC:""}]

here is my query with the sum, avg or any other aggregation would return the wrong results for the empty field, other than the count aggregation.

```
{
	"size": 0,
	"_source": false,
	"query": {
		"filtered": {
			"filter": {
				"bool": {
					"must": [{
						"query": {
							"nested": {
								"path": "A",
								"query": {
									"term": {
										"A.productmaster_FABRIC": ""
									}
								}
							}
						}
					}]
				}
			}
		}
	},
	"aggs": {
		"sumpurchase": {
			"sum": {
				"field": "purchaseli_QTY"
			}
		}
	}
}

```

is any one has any idea about this issue.

I am using the elasticsearch 2.2.0 version.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 25, 2017, 2:30pm UTC](https://discuss.elastic.co/t/nested-field-empty-values-aggregation-returns-the-wrong-value/90979/2 "2017-07-25T14:30:53Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
