# SOS! How it is possible to implement filtering of nested objects depending on the values of the parent nested object

**URL:** https://discuss.elastic.co/t/sos-how-it-is-possible-to-implement-filtering-of-nested-objects-depending-on-the-values-of-the-parent-nested-object/220247
**Category:** Elasticsearch
**Created:** [February 20, 2020, 6:16pm UTC](https://discuss.elastic.co/t/sos-how-it-is-possible-to-implement-filtering-of-nested-objects-depending-on-the-values-of-the-parent-nested-object/220247 "2020-02-20T18:16:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![iva3682](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iva3682/32/67504_2.png) [@iva3682](https://discuss.elastic.co/u/iva3682)
#### Post date: [February 20, 2020, 6:16pm UTC](https://discuss.elastic.co/t/sos-how-it-is-possible-to-implement-filtering-of-nested-objects-depending-on-the-values-of-the-parent-nested-object/220247/1 "2020-02-20T18:16:47Z")

</div>

Good afternoon! Thanks for such a wonderful product! There is the following question:  
how it is possible to implement filtering of nested objects depending on the values ​​of the parent nested object.  
For example, there is the following mapping:

```
'properties' => [
	'Link' => [
		'type' => 'text'
	],
	'Dates' => [
		'type' => 'nested',
		'properties' => [
			'Date' => [
				'type' => 'date',
				'format' => 'yyyy-MM-dd'
			],
			'Cities' => [
				'type' => 'nested',
				'properties' => [
					'CityID' => [
						'type' => 'long'
					],
					'Statuses' => [
						'type' => 'nested',
						'properties' => [
							'StatusID' => [
								'type' => 'long'
							]
						]
					]
				]
			]
		]
	]
]

```

There is a document:

```
'Link' => "http://...",
'Dates' => [{
	'Date' => '2020-02-20',
	'Cities' => [{
		'CityID' => 1,
		'Statuses' => [
			{
				'StatusID' => 1
			},
			{
				'StatusID' => 2
			}
		]
	}]
]}

```

How can I remove StatusID =\> 2 from inner\_hits if CityID =\> 1?  
if CityID \<\> 1, then do not remove anything

Thanks in advance!!!

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [February 21, 2020, 8:05am UTC](https://discuss.elastic.co/t/sos-how-it-is-possible-to-implement-filtering-of-nested-objects-depending-on-the-values-of-the-parent-nested-object/220247/2 "2020-02-21T08:05:07Z")

</div>

I am not a hundred percent sure I understand that use-case, but how about creating two different searches and putting them into a single `bool` with a `should` clause, this way either the cityId=\>1 && statusId == 2 query matches.

However, one thing you cannot do, is remove things from a response, even with `inner_hits` specified.

If you come up with a **minimal reproducible example** that contains requests and responses using curl or the kibana dev-tools, it might be easier to follow what you are after.

---

<div class="post-metadata">

### Author: ![iva3682](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iva3682/32/67504_2.png) [@iva3682](https://discuss.elastic.co/u/iva3682)
#### Post date: [February 29, 2020, 12:45pm UTC](https://discuss.elastic.co/t/sos-how-it-is-possible-to-implement-filtering-of-nested-objects-depending-on-the-values-of-the-parent-nested-object/220247/3 "2020-02-29T12:45:44Z")

</div>

Thanks!

---

<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: [March 28, 2020, 12:45pm UTC](https://discuss.elastic.co/t/sos-how-it-is-possible-to-implement-filtering-of-nested-objects-depending-on-the-values-of-the-parent-nested-object/220247/4 "2020-03-28T12:45:46Z")

</div>

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