# Facet Filter by Element and Element Sibling

**URL:** <https://discuss.elastic.co/t/facet-filter-by-element-and-element-sibling/4510>\
**Category:** Elasticsearch\
**Created:** [May 31, 2011, 11:07pm UTC](https://discuss.elastic.co/t/facet-filter-by-element-and-element-sibling/4510 "2011-05-31T23:07:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Owen\_Coutts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/owen_coutts/32/3179_2.png) [@Owen\_Coutts](https://discuss.elastic.co/u/Owen_Coutts)\
**Post date:** [May 31, 2011, 11:07pm UTC](https://discuss.elastic.co/t/facet-filter-by-element-and-element-sibling/4510/1 "2011-05-31T23:07:30Z")

</div>

Hello All,

I'm looking to do a facet filter on documents that look like  
this[http://pastebin.com/Dgy7YwKW](http://pastebin.com/Dgy7YwKW)one.

I have an array named "results" and within that array I have elements with  
field "name" and field "failed". I'd like to do a facet search over the  
"name" field across all elements of the "results" array in in all documents.  
Furthermore, I'd like to be able to filter out all elements where "failed"  
(the sibling of "name") is 0. How would I do this?

I've tried looking at the Term  
Scripts[http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet.html)documentation  
but I don't think I am able to access the sibling from the  
script.

Does \_scope allow this to happen? Could I somehow scope the facets down to  
an individual element in "results"?

Thanks for your help,  
Owen Coutts

--  
Owen Coutts  
[owen@owencoutts.com](mailto:owen@owencoutts.com)

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 31, 2011, 11:54pm UTC](https://discuss.elastic.co/t/facet-filter-by-element-and-element-sibling/4510/2 "2011-05-31T23:54:13Z")

</div>

You will loose the notion of order between two different fields in this case. You will filter by docs that have failed set to 0, but then that doc becomes "qualified" to do terms stats on it. What you can do is separate each element in the array to a different doc.

On Wednesday, June 1, 2011 at 2:07 AM, Owen Coutts wrote:

> Hello All,
> 
> I'm looking to do a facet filter on documents that look like this ([{ "application\_repository": "http://hg.mozilla.org/mozilla-central", " - Pastebin.com](http://pastebin.com/Dgy7YwKW)) one.
> 
> I have an array named "results" and within that array I have elements with field "name" and field "failed". I'd like to do a facet search over the "name" field across all elements of the "results" array in in all documents. Furthermore, I'd like to be able to filter out all elements where "failed" (the sibling of "name") is 0. How would I do this?
> 
> I've tried looking at the Term Scripts ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet.html)) documentation but I don't think I am able to access the sibling from the script.
> 
> Does \_scope allow this to happen? Could I somehow scope the facets down to an individual element in "results"?
> 
> Thanks for your help,  
> Owen Coutts
> 
> --  
> Owen Coutts  
> [owen@owencoutts.com](mailto:owen@owencoutts.com) ([mailto:owen@owencoutts.com](mailto:owen@owencoutts.com))

---

<div class="post-metadata">

**Author:** ![Owen\_Coutts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/owen_coutts/32/3179_2.png) [@Owen\_Coutts](https://discuss.elastic.co/u/Owen_Coutts)\
**Post date:** [June 1, 2011, 1:01am UTC](https://discuss.elastic.co/t/facet-filter-by-element-and-element-sibling/4510/3 "2011-06-01T01:01:21Z")

</div>

How would I do that while keeping the meta data (at the root of the current  
doc) in the index for each result? Should I create separate documents where  
the meta data is repeated?

On Tue, May 31, 2011 at 4:54 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> You will loose the notion of order between two different fields in this  
> case. You will filter by docs that have failed set to 0, but then that doc  
> becomes "qualified" to do terms stats on it. What you can do is separate  
> each element in the array to a different doc.
> 
> On Wednesday, June 1, 2011 at 2:07 AM, Owen Coutts wrote:
> 
> Hello All,
> 
> I'm looking to do a facet filter on documents that look like this[http://pastebin.com/Dgy7YwKW](http://pastebin.com/Dgy7YwKW)one.
> 
> I have an array named "results" and within that array I have elements with  
> field "name" and field "failed". I'd like to do a facet search over the  
> "name" field across all elements of the "results" array in in all documents.  
> Furthermore, I'd like to be able to filter out all elements where "failed"  
> (the sibling of "name") is 0. How would I do this?
> 
> I've tried looking at the Term Scripts[http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet.html)documentation but I don't think I am able to access the sibling from the  
> script.
> 
> Does \_scope allow this to happen? Could I somehow scope the facets down to  
> an individual element in "results"?
> 
> Thanks for your help,  
> Owen Coutts
> 
> --  
> Owen Coutts  
> [owen@owencoutts.com](mailto:owen@owencoutts.com)

--  
Owen Coutts  
University of Waterloo

--  
Email: [owen@owencoutts.com](mailto:owen@owencoutts.com)  
Phone: 519.729.3859  
Book a Meeting With Me: [tungle.me/ocoutts](http://tungle.me/ocoutts)

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 1, 2011, 1:47am UTC](https://discuss.elastic.co/t/facet-filter-by-element-and-element-sibling/4510/4 "2011-06-01T01:47:34Z")

</div>

You will need to repeat the metadata in each document, or, use the parent child feature (at the cost of slower searches with has\_child filter or top\_children query).

On Wednesday, June 1, 2011 at 4:01 AM, Owen Coutts wrote:

> How would I do that while keeping the meta data (at the root of the current doc) in the index for each result? Should I create separate documents where the meta data is repeated?
> 
> On Tue, May 31, 2011 at 4:54 PM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) ([mailto:shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com))\> wrote:
> 
> > You will loose the notion of order between two different fields in this case. You will filter by docs that have failed set to 0, but then that doc becomes "qualified" to do terms stats on it. What you can do is separate each element in the array to a different doc.
> > 
> > On Wednesday, June 1, 2011 at 2:07 AM, Owen Coutts wrote:
> > 
> > > Hello All,
> > > 
> > > I'm looking to do a facet filter on documents that look like this ([{ "application\_repository": "http://hg.mozilla.org/mozilla-central", " - Pastebin.com](http://pastebin.com/Dgy7YwKW)) one.
> > > 
> > > I have an array named "results" and within that array I have elements with field "name" and field "failed". I'd like to do a facet search over the "name" field across all elements of the "results" array in in all documents. Furthermore, I'd like to be able to filter out all elements where "failed" (the sibling of "name") is 0. How would I do this?
> > > 
> > > I've tried looking at the Term Scripts ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet.html)) documentation but I don't think I am able to access the sibling from the script.
> > > 
> > > Does \_scope allow this to happen? Could I somehow scope the facets down to an individual element in "results"?
> > > 
> > > Thanks for your help,  
> > > Owen Coutts
> > > 
> > > --  
> > > Owen Coutts  
> > > [owen@owencoutts.com](mailto:owen@owencoutts.com) ([mailto:owen@owencoutts.com](mailto:owen@owencoutts.com))
> 
> --  
> Owen Coutts  
> University of Waterloo
> 
> --  
> Email: [owen@owencoutts.com](mailto:owen@owencoutts.com) ([mailto:owen@owencoutts.com](mailto:owen@owencoutts.com))  
> Phone: 519.729.3859 (tel:519.729.3859)  
> Book a Meeting With Me: [tungle.me/ocoutts](http://tungle.me/ocoutts) ([http://tungle.me/ocoutts](http://tungle.me/ocoutts))

---

<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, 4:05am UTC](https://discuss.elastic.co/t/facet-filter-by-element-and-element-sibling/4510/5 "2017-07-06T04:05:07Z")

</div>

Closed on July 6, 2017, 4:05am UTC


