# How to filter nested array in response?

**URL:** https://discuss.elastic.co/t/how-to-filter-nested-array-in-response/11821
**Category:** Elasticsearch
**Created:** [May 5, 2013, 12:16pm UTC](https://discuss.elastic.co/t/how-to-filter-nested-array-in-response/11821 "2013-05-05T12:16:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![aldm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aldm/32/45644_2.png) [@aldm](https://discuss.elastic.co/u/aldm)
#### Post date: [May 5, 2013, 12:16pm UTC](https://discuss.elastic.co/t/how-to-filter-nested-array-in-response/11821/1 "2013-05-05T12:16:36Z")

</div>

Hi,

I'm using nested documents in ES. I have nested array inside one entity and  
I would like to be able to filter array with nested query (not just filter  
root/parent doc but nested array also).

Nested filters enable to filter root doc. For example, if I have index  
'blogs' and type 'blog' and inside blog document I have property 'comments'  
(array of comments), with  
{"type": "nested" } in mappings, So for example I want to filter blogs that  
have comments that have title like 'today' (for example with match query)  
but in every blog I also want to show only comments that contains 'today'  
in title.

I know how nested filterworks. Also child-parent relationship isn't good  
for this purpose because there is no child documents in response as part of  
parent document.

Is there any way to do this directly in elasticsearch, without adding extra  
logic to application, which may affect performance ?  
Or is there and plans to add this as new option in nested query/filter in  
next versions or something similar ?

Thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![btiernay](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@btiernay](https://discuss.elastic.co/u/btiernay)
#### Post date: [May 7, 2013, 1:58am UTC](https://discuss.elastic.co/t/how-to-filter-nested-array-in-response/11821/2 "2013-05-07T01:58:39Z")

</div>

This looks very similiar to the question I just posted:

[https://groups.google.com/forum/?fromgroups=#!topic/elasticsearch/x1Mmnpudig0](https://groups.google.com/forum/?fromgroups=#!topic/elasticsearch/x1Mmnpudig0)

I don't believe this is possible today, but I would love to be wrong 🙂

Bob

On Sunday, 5 May 2013 08:16:36 UTC-4, aldm wrote:

> Hi,
> 
> I'm using nested documents in ES. I have nested array inside one entity  
> and I would like to be able to filter array with nested query (not just  
> filter root/parent doc but nested array also).
> 
> Nested filters enable to filter root doc. For example, if I have index  
> 'blogs' and type 'blog' and inside blog document I have property 'comments'  
> (array of comments), with  
> {"type": "nested" } in mappings, So for example I want to filter blogs  
> that have comments that have title like 'today' (for example with match  
> query) but in every blog I also want to show only comments that contains  
> 'today' in title.
> 
> I know how nested filterworks. Also child-parent relationship isn't good  
> for this purpose because there is no child documents in response as part of  
> parent document.
> 
> Is there any way to do this directly in elasticsearch, without adding  
> extra logic to application, which may affect performance ?  
> Or is there and plans to add this as new option in nested query/filter in  
> next versions or something similar ?
> 
> Thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:38am UTC](https://discuss.elastic.co/t/how-to-filter-nested-array-in-response/11821/3 "2017-07-06T02:38:01Z")

</div>


