# Missing aggregation with value

**URL:** <https://discuss.elastic.co/t/missing-aggregation-with-value/179372>\
**Category:** Elasticsearch\
**Created:** [May 2, 2019, 1:20pm UTC](https://discuss.elastic.co/t/missing-aggregation-with-value/179372 "2019-05-02T13:20:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tharindudg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tharindudg/32/45426_2.png) [@tharindudg](https://discuss.elastic.co/u/tharindudg)\
**Post date:** [May 2, 2019, 1:20pm UTC](https://discuss.elastic.co/t/missing-aggregation-with-value/179372/1 "2019-05-02T13:20:42Z")

</div>

Below is the structure of a document that I've indexed into elasticsearch 6.7

```
{
	"instance": {
		"id": 1,
		...
		"relatedInstances": [
			{
				"id": 101,
				...
				"instFields": [
					{
						"sourceFieldId": 202,
						"fieldValue": "some value"
					},
					{
						"sourceFieldId": 505,
						"fieldValue": "some value"
					},
					...					
				]
			},
			...
		]
	}
}

```

- A document can have different `instance.relatedInstances.instFields.sourceFieldId`s and if a document doesn't have a particular `instance.relatedInstances.instFields.sourceFieldId` then it is not included in the document.

- I'm trying to do an aggregation(count) on `instance.relatedInstances.instFields.sourceFieldId` for all the instances that has the  
`instance.relatedInstances.instFields.sourceFieldId` value `202`.

- I also need to include the count of instances that doesn't have `instance.relatedInstances.instFields.sourceFieldId` with value `202`

I tried with the following query,

```
"aggs": {
    "missing-count": {
      "missing": {
		"field": "instance.relatedInstances.instFields.sourceFieldId",
		"value": "202"
      }
    }                     
}

```

and got the error `[missing] unknown field [value], parser not found`.

As per the [documentation][1] **missing** field can be specified, but it doesn't show how to find documents that doesn't have a field with a specific value.

Appreciate any help to solve this problem.  
[1]: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-missing-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-missing-aggregation.html)

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [May 6, 2019, 5:35pm UTC](https://discuss.elastic.co/t/missing-aggregation-with-value/179372/2 "2019-05-06T17:35:28Z")

</div>

The `missing` aggregation is to find documents that are completely lacking a particular field, not that they don't have specific value.

You'll want to use a `bool` query with a "must\_not" clause to find documents that do not have a specific value. That can either go in the `"query"` section of the search request, or inside a `filter` aggregation.

---

<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:** [June 3, 2019, 5:39pm UTC](https://discuss.elastic.co/t/missing-aggregation-with-value/179372/3 "2019-06-03T17:39:36Z")

</div>

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