# Root fields in nested facet filter

**URL:** https://discuss.elastic.co/t/root-fields-in-nested-facet-filter/14720
**Category:** Elasticsearch
**Created:** [December 5, 2013, 3:40am UTC](https://discuss.elastic.co/t/root-fields-in-nested-facet-filter/14720 "2013-12-05T03:40:42Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Karthick\_Duraisamy\_S](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@Karthick\_Duraisamy\_S](https://discuss.elastic.co/u/Karthick_Duraisamy_S)
#### Post date: [December 5, 2013, 3:40am UTC](https://discuss.elastic.co/t/root-fields-in-nested-facet-filter/14720/1 "2013-12-05T03:40:42Z")

</div>

This document[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets.html#\_all\_nested\_matching\_root\_documents](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets.html#_all_nested_matching_root_documents) shows  
how to apply facet\_filter on the fields in the nested documents. I want to  
be able to apply facet\_filter on the root/parent fields while faceting on  
the nested fields

{  
"category" : "shirts"  
"variation" : [  
{

"color" : "blue",

"size" : 4

```
    },
    {

```

"color" : "green",

"size" : 6

```
   }
]

```

}

In the above doc for instance, I want to be able to do something like  
below.

{

"query": {

"match\_all": {}

},

"facets": {

```
  "size": {

               "terms": {
                         "field" : "size"
                },
                "nested": "obj1",
                "facet_filter" : {
                        "term" : {"category" : "shirts"}
                 }
         }

```

}

Is this possible ?

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/be67102c-3f46-44cb-a5ed-c52399924451%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/be67102c-3f46-44cb-a5ed-c52399924451%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [December 5, 2013, 3:52am UTC](https://discuss.elastic.co/t/root-fields-in-nested-facet-filter/14720/2 "2013-12-05T03:52:11Z")

</div>

It is not possible to filter on the parent/root fields. I have not looked  
if this functionality has been added with the new aggregation framework.

Cheers,

Ivan

On Wed, Dec 4, 2013 at 7:40 PM, dsk [karthick.soundararaj@gmail.com](mailto:karthick.soundararaj@gmail.com) wrote:

> This document[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets.html#\_all\_nested\_matching\_root\_documents](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets.html#_all_nested_matching_root_documents) shows  
> how to apply facet\_filter on the fields in the nested documents. I want to  
> be able to apply facet\_filter on the root/parent fields while faceting on  
> the nested fields
> 
> {  
> "category" : "shirts"  
> "variation" : [  
> {
> 
> "color" : "blue",
> 
> "size" : 4
> 
> ```
> },
> {
> 
> ```
> 
> "color" : "green",
> 
> "size" : 6
> 
> ```
> }
> ]
> 
> ```
> 
> }
> 
> In the above doc for instance, I want to be able to do something like  
> below.
> 
> {
> 
> "query": {
> 
> "match\_all": {}
> 
> },
> 
> "facets": {
> 
> ```
> "size": {
> 
> "terms": {
> "field" : "size"
> },
> "nested": "obj1",
> "facet_filter" : {
> "term" : {"category" : "shirts"}
> }
> }
> 
> ```
> 
> }
> 
> Is this possible ?
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/be67102c-3f46-44cb-a5ed-c52399924451%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/be67102c-3f46-44cb-a5ed-c52399924451%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDD\_Vx1Ltpo0g%2B\_4XDOugQFuq3%3DK51h2ZaV2nFMzR039w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDD_Vx1Ltpo0g%2B_4XDOugQFuq3%3DK51h2ZaV2nFMzR039w%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Karthick\_Duraisamy\_S](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@Karthick\_Duraisamy\_S](https://discuss.elastic.co/u/Karthick_Duraisamy_S)
#### Post date: [December 6, 2013, 1:10am UTC](https://discuss.elastic.co/t/root-fields-in-nested-facet-filter/14720/3 "2013-12-06T01:10:52Z")

</div>

I tried aggregations today. I am able to do this  
{

"query": {

"match\_all": {}

},

"aggs": {

```
  "size": {

               "filter" : { "range" : { "model" : { "gt" : 2013 } } },
         }

```

}

On Wed, Dec 4, 2013 at 7:52 PM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> It is not possible to filter on the parent/root fields. I have not looked  
> if this functionality has been added with the new aggregation framework.
> 
> Cheers,
> 
> Ivan
> 
> On Wed, Dec 4, 2013 at 7:40 PM, dsk [karthick.soundararaj@gmail.com](mailto:karthick.soundararaj@gmail.com)wrote:
> 
> > This document[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets.html#\_all\_nested\_matching\_root\_documents](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets.html#_all_nested_matching_root_documents) shows  
> > how to apply facet\_filter on the fields in the nested documents. I want to  
> > be able to apply facet\_filter on the root/parent fields while faceting on  
> > the nested fields
> > 
> > {  
> > "category" : "shirts"  
> > "variation" : [  
> > {
> > 
> > "color" : "blue",
> > 
> > "size" : 4
> > 
> > ```
> > },
> > {
> > 
> > ```
> > 
> > "color" : "green",
> > 
> > "size" : 6
> > 
> > ```
> > }
> > ]
> > 
> > ```
> > 
> > }
> > 
> > In the above doc for instance, I want to be able to do something like  
> > below.
> > 
> > {
> > 
> > "query": {
> > 
> > "match\_all": {}
> > 
> > },
> > 
> > "facets": {
> > 
> > ```
> > "size": {
> > 
> > "terms": {
> > "field" : "size"
> > },
> > "nested": "obj1",
> > "facet_filter" : {
> > "term" : {"category" : "shirts"}
> > }
> > }
> > 
> > ```
> > 
> > }
> > 
> > Is this possible ?
> > 
> > --  
> > 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).
> > 
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/be67102c-3f46-44cb-a5ed-c52399924451%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/be67102c-3f46-44cb-a5ed-c52399924451%40googlegroups.com)  
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/et\_V2JBTeA8/unsubscribe](https://groups.google.com/d/topic/elasticsearch/et_V2JBTeA8/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDD\_Vx1Ltpo0g%2B\_4XDOugQFuq3%3DK51h2ZaV2nFMzR039w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDD_Vx1Ltpo0g%2B_4XDOugQFuq3%3DK51h2ZaV2nFMzR039w%40mail.gmail.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CABKv5CL6RbL8mWYrn6Osd1Ftia1ExUnndGYeJOwOUY%3D43693KA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CABKv5CL6RbL8mWYrn6Osd1Ftia1ExUnndGYeJOwOUY%3D43693KA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Karthick\_Duraisamy\_S](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@Karthick\_Duraisamy\_S](https://discuss.elastic.co/u/Karthick_Duraisamy_S)
#### Post date: [December 6, 2013, 1:46am UTC](https://discuss.elastic.co/t/root-fields-in-nested-facet-filter/14720/4 "2013-12-06T01:46:22Z")

</div>

Thanks for the email Ivan. Sorry about my previous partial message.

I explored aggregations today. I tried the following query, but doesnt  
work. Would be great if someone could help.

{

"query": {  
"match\_all": {}

},

"aggs": {

```
  "categories": {

                     "filter" : { "terms" : { "category" : "shirts" }

```

},  
"nested" : { "path" : "variation" },  
"aggs" : {  
"size" : {  
"terms" : { "field" : "size" } }  
}  
}  
}  
}  
}

Also, even filtering docs on nested field doesnt seem to work, for instance

- the following query doesnt work

{

"query": {  
"match\_all": {}

},

"aggs": {

```
  "categories": {

                     "filter" : { "terms" : { "color" : "blue" } },
                     "nested" : { "path" : "variation" },
                     "aggs" : {
                           "size" : {
                                   "terms" : { "field" : "size" } }
                            }
                      }
               }
       }

```

}

Thanks in advance

On Thu, Dec 5, 2013 at 5:10 PM, Karthick Duraisamy Soundararaj \<  
[karthick.soundararaj@gmail.com](mailto:karthick.soundararaj@gmail.com)\> wrote:

> I tried aggregations today. I am able to do this  
> {
> 
> "query": {
> 
> "match\_all": {}
> 
> },
> 
> "aggs": {
> 
> ```
> "size": {
> 
> "filter" : { "range" : { "model" : { "gt" : 2013 } } },
> }
> 
> ```
> 
> }
> 
> On Wed, Dec 4, 2013 at 7:52 PM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:
> 
> > It is not possible to filter on the parent/root fields. I have not looked  
> > if this functionality has been added with the new aggregation framework.
> > 
> > Cheers,
> > 
> > Ivan
> > 
> > On Wed, Dec 4, 2013 at 7:40 PM, dsk [karthick.soundararaj@gmail.com](mailto:karthick.soundararaj@gmail.com)wrote:
> > 
> > > This document[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets.html#\_all\_nested\_matching\_root\_documents](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets.html#_all_nested_matching_root_documents) shows  
> > > how to apply facet\_filter on the fields in the nested documents. I want to  
> > > be able to apply facet\_filter on the root/parent fields while faceting on  
> > > the nested fields
> > > 
> > > {  
> > > "category" : "shirts"  
> > > "variation" : [  
> > > {
> > > 
> > > "color" : "blue",
> > > 
> > > "size" : 4
> > > 
> > > ```
> > > },
> > > {
> > > 
> > > ```
> > > 
> > > "color" : "green",
> > > 
> > > "size" : 6
> > > 
> > > ```
> > > }
> > > ]
> > > 
> > > ```
> > > 
> > > }
> > > 
> > > In the above doc for instance, I want to be able to do something like  
> > > below.
> > > 
> > > {
> > > 
> > > "query": {
> > > 
> > > "match\_all": {}
> > > 
> > > },
> > > 
> > > "facets": {
> > > 
> > > ```
> > > "size": {
> > > 
> > > "terms": {
> > > "field" : "size"
> > > },
> > > "nested": "obj1",
> > > "facet_filter" : {
> > > "term" : {"category" : "shirts"}
> > > }
> > > }
> > > 
> > > ```
> > > 
> > > }
> > > 
> > > Is this possible ?
> > > 
> > > --  
> > > 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).
> > > 
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/be67102c-3f46-44cb-a5ed-c52399924451%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/be67102c-3f46-44cb-a5ed-c52399924451%40googlegroups.com)  
> > > .  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/et\_V2JBTeA8/unsubscribe](https://groups.google.com/d/topic/elasticsearch/et_V2JBTeA8/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDD\_Vx1Ltpo0g%2B\_4XDOugQFuq3%3DK51h2ZaV2nFMzR039w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDD_Vx1Ltpo0g%2B_4XDOugQFuq3%3DK51h2ZaV2nFMzR039w%40mail.gmail.com)  
> > .
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CABKv5CJpDBs\_ZK4vzqDLwNEK\_jtw%3Dp2tYTyi6Wc2KuuORggQ8w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CABKv5CJpDBs_ZK4vzqDLwNEK_jtw%3Dp2tYTyi6Wc2KuuORggQ8w%40mail.gmail.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:02am UTC](https://discuss.elastic.co/t/root-fields-in-nested-facet-filter/14720/5 "2017-07-06T02:02:57Z")

</div>


