# Missing agg does not work with nested documents

**URL:** <https://discuss.elastic.co/t/missing-agg-does-not-work-with-nested-documents/59685>\
**Category:** Elasticsearch\
**Created:** [September 2, 2016, 3:51pm UTC](https://discuss.elastic.co/t/missing-agg-does-not-work-with-nested-documents/59685 "2016-09-02T15:51:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![neilime](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neilime/32/11753_2.png) [@neilime](https://discuss.elastic.co/u/neilime)\
**Post date:** [September 2, 2016, 3:51pm UTC](https://discuss.elastic.co/t/missing-agg-does-not-work-with-nested-documents/59685/1 "2016-09-02T15:51:14Z")

</div>

Hello world,

I have an issue with using "missing" agg on nested documents.

An example to reproduce the problem :

Mapping :

```
POST /mli_test2 {
   "mappings": {
      "participations": {
         "properties": {
            "participationProducts": {
               "type": "nested",
               "properties": {
                  "label": {
                     "type": "string"
                  },
                  "quantity": {
                     "type": "long"
                  }
               }
            }
         }
      }
   }
}

```

Data :

```
POST /mli_test2/participations/1
{
   "number": "xxxx"
}

POST /mli_test2/participations/2
{
   "participationProducts": [
      {
         "label": "TEST_LABEL",
         "quantity": 1
      }
   ],
   "number": "xxxx"
}

POST /mli_test2/participations/3
{
   "participationProducts": [
      {
         "label": "TEST_LABEL",
         "quantity": 1
      }
   ]
}

POST /mli_test2/participations/4
{
   "number": "xxxx"
}
POST /mli_test2/participations/5
{
   "number": "xxxx"
}

```

Elasticsearch query :

```
POST /mli_test2/participations/_search?search_type=count
{
   "aggs": {
      "participationProducts_agg": {
         "nested": {
            "path": "participationProducts"
         },
         "aggs": {
            "participationProducts_empty_agg": {
               "missing": {
                  "field": "participationProducts"
               }
            },
            "label_agg": {
               "terms": {
                  "field": "participationProducts.label"
               },
               "aggs": {
                  "participationProducts_agg": {
                     "sum": {
                        "field": "participationProducts.quantity"
                     }
                  }
               }
            }
         }
      },
      "number_agg": {
         "terms": {
            "size": 1000,
            "field": "number"
         }
      },
      "number_empty_agg": {
         "missing": {
            "field": "number"
         }
      }
   }
}

```

What we expect to retrieve from elasticsearch response :

- number = xxxx =\> 4 (participations 1,2,4,5)
- number\_empty =\> 1 (participation 3)
- participationProducts = TEST\_LABEL =\> 2 (participations 2,3)
- participationProducts\_empty =\> 3 (participations 1,4,5)

But here is the result :

- number = xxxx =\> 4 OK
- number\_empty =\> 1 OK
- participationProducts = TEST\_LABEL =\> 2 OK
- participationProducts\_empty =\> 3 **_KO_**

Thank you for your help

---

<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 5, 2017, 10:22pm UTC](https://discuss.elastic.co/t/missing-agg-does-not-work-with-nested-documents/59685/2 "2017-07-05T22:22:49Z")

</div>


