# Filter not working in nested / aggregation

**URL:** <https://discuss.elastic.co/t/filter-not-working-in-nested-aggregation/59686>\
**Category:** Elasticsearch\
**Created:** [September 2, 2016, 3:52pm UTC](https://discuss.elastic.co/t/filter-not-working-in-nested-aggregation/59686 "2016-09-02T15:52:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bastimm](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@bastimm](https://discuss.elastic.co/u/bastimm)\
**Post date:** [September 2, 2016, 3:52pm UTC](https://discuss.elastic.co/t/filter-not-working-in-nested-aggregation/59686/1 "2016-09-02T15:52:17Z")

</div>

Hello together,

first my excerpt from my mapping:

```
"manufacturerTitle_ID" : {
	"type" : "string",
	"index" : "not_analyzed"
},
"merkmale" : {
	"type" : "nested",
	"include_in_parent" : true,
	"properties" : {
		"key" : {
			"type" : "string",
			"index" : "not_analyzed"
		},
		"value" : {
		"type" : "string",
		"index" : "not_analyzed"
		}
	}
},
"merkmale_key_value" : {
	"type" : "string",
	"index" : "not_analyzed"
}

```

my problem is that i need a filter to "merkmale\_key\_value" from an aggregation in merkmale. I need the filtered doc\_count, but every time this is 0.....  
I think my query is wrong, but i dont find a solution.  
Perhaps somebody can help me or give me a hint?  
The same filter is used in the aggregation manufacturer and works great.... so i think the problem has been invoked by the nested element?

now my excerpt from my query, if you need further infos to help me, please ask and thanks in advance!!!!

```
[aggregations] => Array
(
	[manufacturer] => Array
		(
			[terms] => Array
				(
					[field] => manufacturerTitle_ID
					[size] => 0
					[order] => Array
					(
						[_term] => asc
					)
				)
			[aggs] => Array
				(
					[filtered] => Array
						(
							[filter] => Array
								(
									[terms] => Array
										(
											[merkmale_key_value] => Array
												(
													[0] => Array
														(
															[0] => 26_163
														)
												)
										)
								)
						)
				)
		)
)
[merkmale] => Array
	(
		[nested] => Array
			(
				[path] => merkmale
			)
		[aggs] => Array
			(
		[key] => Array
		(
			[terms] => Array
				(
					[field] => merkmale.key
					[size] => 5
				)
				[aggs] => Array
					(
						[value] => Array
							(
								[terms] => Array
									(
										[field] => merkmale.value
										[size] => 5
									)

								[aggs] => Array
									(
										[filtered] => Array
											(
												[filter] => Array
													(
														[terms] => Array
															(
																[merkmale_key_value] => Array
																	(
																		[0] => 31_200,31_201
																	)
															)
													)
											)
									)
							)
					)
			)
	)
```

---

<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/filter-not-working-in-nested-aggregation/59686/2 "2017-07-05T22:22:48Z")

</div>

Closed on July 5, 2017, 10:22pm UTC


