# Parent conditions in NESTED or SCOPED facets

**URL:** https://discuss.elastic.co/t/parent-conditions-in-nested-or-scoped-facets/9268
**Category:** Elasticsearch
**Created:** [October 8, 2012, 7:23am UTC](https://discuss.elastic.co/t/parent-conditions-in-nested-or-scoped-facets/9268 "2012-10-08T07:23:33Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Pavel\_Horal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pavel_horal/32/2653_2.png) [@Pavel\_Horal](https://discuss.elastic.co/u/Pavel_Horal)
#### Post date: [October 8, 2012, 7:23am UTC](https://discuss.elastic.co/t/parent-conditions-in-nested-or-scoped-facets/9268/1 "2012-10-08T07:23:33Z")

</div>

Hello,

I might found an undocumented restriction of ES facet implementation. I was  
trying to do this:

{  
"query": { /\* Some query - not important _/ },  
"filter": { /_ MAIN FILTER _/,  
"facets": {  
"foo": {  
"terms": {  
"term": "foo"  
},  
"nested": "foo",  
"facet\_filter": {  
"has\_parent": { /_ THIS DOES NOT WORK \*/ }  
}  
}  
}  
}

I don't see any theoretical issue why this is not working. So my question  
is: _Is this some undocumented restriction or is this just  
not-yet-implemented?_

P.S.: this can be solved by using another search request or the  
multi-search functionality. However my question remains :).

--

---

<div class="post-metadata">

### Author: ![Maciej\_Kowalski](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maciej_kowalski/32/2677_2.png) [@Maciej\_Kowalski](https://discuss.elastic.co/u/Maciej_Kowalski)
#### Post date: [October 17, 2012, 9:52am UTC](https://discuss.elastic.co/t/parent-conditions-in-nested-or-scoped-facets/9268/2 "2012-10-17T09:52:36Z")

</div>

Hi,

@Pavel Horal  
Did you any workaround for this problem?

[@everyone](https://discuss.elastic.co/groups/everyone)  
Is it bug OR feature?

W dniu poniedziałek, 8 października 2012 09:23:33 UTC+2 użytkownik Pavel  
Horal napisał:

> Hello,
> 
> I might found an undocumented restriction of ES facet implementation. I  
> was trying to do this:
> 
> {  
> "query": { /\* Some query - not important _/ },  
> "filter": { /_ MAIN FILTER _/,  
> "facets": {  
> "foo": {  
> "terms": {  
> "term": "foo"  
> },  
> "nested": "foo",  
> "facet\_filter": {  
> "has\_parent": { /_ THIS DOES NOT WORK \*/ }  
> }  
> }  
> }  
> }
> 
> I don't see any theoretical issue why this is not working. So my question  
> is: _Is this some undocumented restriction or is this just  
> not-yet-implemented?_
> 
> P.S.: this can be solved by using another search request or the  
> multi-search functionality. However my question remains :).

--

---

<div class="post-metadata">

### Author: ![Pavel\_Horal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pavel_horal/32/2653_2.png) [@Pavel\_Horal](https://discuss.elastic.co/u/Pavel_Horal)
#### Post date: [November 4, 2012, 10:00am UTC](https://discuss.elastic.co/t/parent-conditions-in-nested-or-scoped-facets/9268/3 "2012-11-04T10:00:12Z")

</div>

I've workarounded this issue by using _filter_ facets with nested filters.  
I needed only to return result counts for three nested terms, so I just  
added three nested \*filter \*facets.

Other (more efficient) workaround would be to make totally different search  
request using the _MAIN FILTER_ as a part of the query (_filtered_).

On Wednesday, October 17, 2012 11:52:36 AM UTC+2, Maciej Kowalski wrote:

> Hi,
> 
> @Pavel Horal  
> Did you any workaround for this problem?
> 
> [@everyone](https://discuss.elastic.co/groups/everyone)  
> Is it bug OR feature?
> 
> W dniu poniedziałek, 8 października 2012 09:23:33 UTC+2 użytkownik Pavel  
> Horal napisał:
> 
> > Hello,
> > 
> > I might found an undocumented restriction of ES facet implementation. I  
> > was trying to do this:
> > 
> > {  
> > "query": { /\* Some query - not important _/ },  
> > "filter": { /_ MAIN FILTER _/,  
> > "facets": {  
> > "foo": {  
> > "terms": {  
> > "term": "foo"  
> > },  
> > "nested": "foo",  
> > "facet\_filter": {  
> > "has\_parent": { /_ THIS DOES NOT WORK \*/ }  
> > }  
> > }  
> > }  
> > }
> > 
> > I don't see any theoretical issue why this is not working. So my question  
> > is: _Is this some undocumented restriction or is this just  
> > not-yet-implemented?_
> > 
> > P.S.: this can be solved by using another search request or the  
> > multi-search functionality. However my question remains :).

--

---

<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, 3:06am UTC](https://discuss.elastic.co/t/parent-conditions-in-nested-or-scoped-facets/9268/4 "2017-07-06T03:06:17Z")

</div>


