# Creating facets from nested data

**URL:** <https://discuss.elastic.co/t/creating-facets-from-nested-data/13437>\
**Category:** Elasticsearch\
**Created:** [September 2, 2013, 5:02pm UTC](https://discuss.elastic.co/t/creating-facets-from-nested-data/13437 "2013-09-02T17:02:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sander\_Toonen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sander_toonen/32/1913_2.png) [@Sander\_Toonen](https://discuss.elastic.co/u/Sander_Toonen)\
**Post date:** [September 2, 2013, 5:02pm UTC](https://discuss.elastic.co/t/creating-facets-from-nested-data/13437/1 "2013-09-02T17:02:41Z")

</div>

Hi,

I'm playing with ES for a few days now but I'm stuck where it comes to  
facetted search.  
I have documents that are formatted in a specific way. Since they are  
pulled in via the Mongo River plugin I have not that much control over the  
format.  
They look like this:

{  
"\_id": { "$oid" : "522494037c92286f44acd7f8" },  
"description": "....",  
"created": "2013-08-20 11:26:13",  
"modified": "2013-08-20 11:26:13",  
"some\_nested\_data": [  
...,  
...  
],  
"features": [  
{  
"name": "color",  
"label": "Color",  
"value": "Blue",  
"type": "string",  
"modified": "2013-08-20 11:31:01",  
...  
},  
{  
"name": "length\_mm",  
"label": "Length (in mm)",  
"value": "1200",  
"type": "int",  
"modified": "2013-08-20 11:31:01",  
...  
},  
...  
]  
}

Is there a way so that I can create facets from the nested data in the  
'features' array?  
I'd like to be able to filter on color:Blue for example.

Thanks!

Sander

--  
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:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [September 3, 2013, 10:22am UTC](https://discuss.elastic.co/t/creating-facets-from-nested-data/13437/2 "2013-09-03T10:22:53Z")

</div>

Hello,

If your features are defined as nested  
type[http://www.elasticsearch.org/guide/reference/mapping/nested-type/](http://www.elasticsearch.org/guide/reference/mapping/nested-type/)in  
your mapping, you have to specify the path when you do the facet. To  
see  
an example, look for "nested" in here:

> **[Elastic — The Search AI Company](https://www.elastic.co)**
>
> Power insights and outcomes with The Elastic Search AI Platform. See into your data and find answers that matter with enterprise solutions designed to help you accelerate time to insight. Try Elastic ...

If it's not a nested type, then you should be able to refer to the field  
you need with something like features.color

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Mon, Sep 2, 2013 at 8:02 PM, Sander Toonen [s.toonen@gmail.com](mailto:s.toonen@gmail.com) wrote:

> Hi,
> 
> I'm playing with ES for a few days now but I'm stuck where it comes to  
> facetted search.  
> I have documents that are formatted in a specific way. Since they are  
> pulled in via the Mongo River plugin I have not that much control over the  
> format.  
> They look like this:
> 
> {  
> "\_id": { "$oid" : "522494037c92286f44acd7f8" },  
> "description": "....",  
> "created": "2013-08-20 11:26:13",  
> "modified": "2013-08-20 11:26:13",  
> "some\_nested\_data": [  
> ...,  
> ...  
> ],  
> "features": [  
> {  
> "name": "color",  
> "label": "Color",  
> "value": "Blue",  
> "type": "string",  
> "modified": "2013-08-20 11:31:01",  
> ...  
> },  
> {  
> "name": "length\_mm",  
> "label": "Length (in mm)",  
> "value": "1200",  
> "type": "int",  
> "modified": "2013-08-20 11:31:01",  
> ...  
> },  
> ...  
> ]  
> }
> 
> Is there a way so that I can create facets from the nested data in the  
> 'features' array?  
> I'd like to be able to filter on color:Blue for example.
> 
> Thanks!
> 
> Sander
> 
> --  
> 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).

--  
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:** ![Sander\_Toonen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sander_toonen/32/1913_2.png) [@Sander\_Toonen](https://discuss.elastic.co/u/Sander_Toonen)\
**Post date:** [September 4, 2013, 3:43pm UTC](https://discuss.elastic.co/t/creating-facets-from-nested-data/13437/3 "2013-09-04T15:43:30Z")

</div>

I don't believe that that will work with my structure will it?

Doesn't the nested type require you to have _{: }_?  
I have a structure where the format is _{name: , value: }._

On Tuesday, 3 September 2013 12:22:53 UTC+2, Radu Gheorghe wrote:

> Hello,
> 
> If your features are defined as nested type[http://www.elasticsearch.org/guide/reference/mapping/nested-type/](http://www.elasticsearch.org/guide/reference/mapping/nested-type/)in your mapping, you have to specify the path when you do the facet. To see  
> an example, look for "nested" in here:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/)
> 
> If it's not a nested type, then you should be able to refer to the field  
> you need with something like features.color
> 
> ## Best regards, Radu
> 
> [http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene
> 
> On Mon, Sep 2, 2013 at 8:02 PM, Sander Toonen \<[s.to...@gmail.com](mailto:s.to...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi,
> > 
> > I'm playing with ES for a few days now but I'm stuck where it comes to  
> > facetted search.  
> > I have documents that are formatted in a specific way. Since they are  
> > pulled in via the Mongo River plugin I have not that much control over the  
> > format.  
> > They look like this:
> > 
> > {  
> > "\_id": { "$oid" : "522494037c92286f44acd7f8" },  
> > "description": "....",  
> > "created": "2013-08-20 11:26:13",  
> > "modified": "2013-08-20 11:26:13",  
> > "some\_nested\_data": [  
> > ...,  
> > ...  
> > ],  
> > "features": [  
> > {  
> > "name": "color",  
> > "label": "Color",  
> > "value": "Blue",  
> > "type": "string",  
> > "modified": "2013-08-20 11:31:01",  
> > ...  
> > },  
> > {  
> > "name": "length\_mm",  
> > "label": "Length (in mm)",  
> > "value": "1200",  
> > "type": "int",  
> > "modified": "2013-08-20 11:31:01",  
> > ...  
> > },  
> > ...  
> > ]  
> > }
> > 
> > Is there a way so that I can create facets from the nested data in the  
> > 'features' array?  
> > I'd like to be able to filter on color:Blue for example.
> > 
> > Thanks!
> > 
> > Sander
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > 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).  
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:18am UTC](https://discuss.elastic.co/t/creating-facets-from-nested-data/13437/4 "2017-07-06T02:18:13Z")

</div>


