# Faceting \*only\* Matched Nested Documents. Is it possible?

**URL:** <https://discuss.elastic.co/t/faceting-only-matched-nested-documents-is-it-possible/10341>\
**Category:** Elasticsearch\
**Created:** [January 15, 2013, 1:05am UTC](https://discuss.elastic.co/t/faceting-only-matched-nested-documents-is-it-possible/10341 "2013-01-15T01:05:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Cholakian](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_cholakian/32/1712_2.png) [@Andrew\_Cholakian](https://discuss.elastic.co/u/Andrew_Cholakian)\
**Post date:** [January 15, 2013, 1:05am UTC](https://discuss.elastic.co/t/faceting-only-matched-nested-documents-is-it-possible/10341/1 "2013-01-15T01:05:46Z")

</div>

Hi All! I'm wondering if it would be possible to implement a terms facet  
that matches against multiple nested docs, but only displays facet terms  
from docs that match all filter criteria.

What we're doing now is, in minimal form something like:

{facet\_filter:

{nested:  
{"\_scope": "label",  
path: "labels",  
query: {

```
    filtered: {
      query: 

      match_all: {}

    },

    filter:
    and: [{:term=>{:category=>"Foo"}},
          {:term=>{:brand=>"Bar"}}

```

The problem we face is that given a document that looks like:

{item:

{labels: [{category: "Foo", brand: "Bar", style: "Smooth"}, {category: "Baz", brand: "Blah", style: "Bold"}]}}

the terms facet will return both "Smooth" and "Bold" under 'style'. Where we'd only like to see "Smooth" because Bold is in an unmatched document.

Is this possible at all in a query against our items index?

--

---

<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:56am UTC](https://discuss.elastic.co/t/faceting-only-matched-nested-documents-is-it-possible/10341/2 "2017-07-06T02:56:30Z")

</div>


