# Facets : get all nested fields, without specifiyng the name

**URL:** <https://discuss.elastic.co/t/facets-get-all-nested-fields-without-specifiyng-the-name/12415>\
**Category:** Elasticsearch\
**Created:** [June 14, 2013, 9:07am UTC](https://discuss.elastic.co/t/facets-get-all-nested-fields-without-specifiyng-the-name/12415 "2013-06-14T09:07:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastianpx](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@Sebastianpx](https://discuss.elastic.co/u/Sebastianpx)\
**Post date:** [June 14, 2013, 9:07am UTC](https://discuss.elastic.co/t/facets-get-all-nested-fields-without-specifiyng-the-name/12415/1 "2013-06-14T09:07:28Z")

</div>

Hi !

I am currently playing with facets, and I am facing the following problems.  
The documents I am indexing are products. They have different fields  
(Title, id) and a list of attributes, defined in a nested field.

My mapping looks like this :

mappings: {  
product: {  
properties: {  
title: {  
type: string  
}  
id: {  
type: long  
}  
attributes: {  
dynamic: true  
properties: {  
screen: {  
type: string  
}  
color: {  
type: string  
}  
brand: {  
type: string  
}  
type: {  
type: string  
}  
memory: {  
type: string  
}  
}  
}  
}  
}  
}

What I want to do, is to get a count of the different values I have within  
"attributes". I can easily do it by specyfing the name of theses fields in  
the facets by doing something like this :

{  
"query" : {  
"match\_all" : {}  
},  
"facets" : {  
"tags" : { "terms" : {"fields" : ["brand", "color"]} }  
}  
}

But what i would actually like to do is a bit different. As I may not know  
the fields within the "attributes" part, i would like to build my facets by  
doing something like "Give me a count for all the fields within the  
attribute field".  
Is this somehow possible ?

Thanks in advance

Sebastian

--  
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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 14, 2013, 9:27am UTC](https://discuss.elastic.co/t/facets-get-all-nested-fields-without-specifiyng-the-name/12415/2 "2013-06-14T09:27:09Z")

</div>

I would probably ask ES for mapping of your type. Then build one Terms facet per field in attributes object.

So you should probably handle that on client side.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 14 juin 2013 à 11:07, Sebastianpx [sebastian.piedoux@gmail.com](mailto:sebastian.piedoux@gmail.com) a écrit :

> Hi !
> 
> I am currently playing with facets, and I am facing the following problems.  
> The documents I am indexing are products. They have different fields (Title, id) and a list of attributes, defined in a nested field.
> 
> My mapping looks like this :
> 
> mappings: {  
> product: {  
> properties: {  
> title: {  
> type: string  
> }  
> id: {  
> type: long  
> }  
> attributes: {  
> dynamic: true  
> properties: {  
> screen: {  
> type: string  
> }  
> color: {  
> type: string  
> }  
> brand: {  
> type: string  
> }  
> type: {  
> type: string  
> }  
> memory: {  
> type: string  
> }  
> }  
> }  
> }  
> }  
> }
> 
> What I want to do, is to get a count of the different values I have within "attributes". I can easily do it by specyfing the name of theses fields in the facets by doing something like this :
> 
> {  
> "query" : {  
> "match\_all" : {}  
> },  
> "facets" : {  
> "tags" : { "terms" : {"fields" : ["brand", "color"]} }  
> }  
> }
> 
> But what i would actually like to do is a bit different. As I may not know the fields within the "attributes" part, i would like to build my facets by doing something like "Give me a count for all the fields within the attribute field".  
> Is this somehow possible ?
> 
> Thanks in advance
> 
> Sebastian
> 
> --  
> 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:** ![Sebastianpx](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@Sebastianpx](https://discuss.elastic.co/u/Sebastianpx)\
**Post date:** [June 18, 2013, 8:06am UTC](https://discuss.elastic.co/t/facets-get-all-nested-fields-without-specifiyng-the-name/12415/3 "2013-06-18T08:06:05Z")

</div>

Thanks for you answer, we decided to follow a similar approach !

---

<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:30am UTC](https://discuss.elastic.co/t/facets-get-all-nested-fields-without-specifiyng-the-name/12415/4 "2017-07-06T02:30:40Z")

</div>


