# Confusion/problems working with facets for nested documents

**URL:** <https://discuss.elastic.co/t/confusion-problems-working-with-facets-for-nested-documents/5842>\
**Category:** Elasticsearch\
**Created:** [November 11, 2011, 8:27am UTC](https://discuss.elastic.co/t/confusion-problems-working-with-facets-for-nested-documents/5842 "2011-11-11T08:27:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rubish\_Gupta](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@Rubish\_Gupta](https://discuss.elastic.co/u/Rubish_Gupta)\
**Post date:** [November 11, 2011, 8:27am UTC](https://discuss.elastic.co/t/confusion-problems-working-with-facets-for-nested-documents/5842/1 "2011-11-11T08:27:59Z")

</div>

I am trying to implement faceted search for users.

Relevant part of mapping for users can be seen at  
[https://gist.github.com/1357430#file\_mapping.json](https://gist.github.com/1357430#file_mapping.json). Each user has some  
personal\_info, alma\_info and many professional details. I want to filter  
users based on name, course/branch(alma\_info) and professional details.  
Professions are nested documents in a user.

Sample document for the user can be seen at  
[https://gist.github.com/1357430#file\_sample\_document.json](https://gist.github.com/1357430#file_sample_document.json).

I have three use cases for facets on company names of users:

1. Facet on all past and current(independently) company names of matched  
users in the query
2. Facet on past and current company names matching a string(using  
edgeNGram) of matched users
3. Facet on company names excluding documents matching certain names of  
matched users

Questions:

1. Is it possible to filter on root documents and only get facets for  
nested types for the filtered root documents. Query I was trying to  
generate for this was [https://gist.github.com/1357430#file\_query1.curl](https://gist.github.com/1357430#file_query1.curl).  
Data does have some professions with companies, but its showing missing for  
all.
2. Is it possible to filter on root documents and only get facets for  
nested documents matching some more conditions. Query I was trying to  
generate for this was [https://gist.github.com/1357430#file\_query2.curl](https://gist.github.com/1357430#file_query2.curl)

I would appreciate any help I can get. Please let me know if I information  
provided is not sufficient.

---

<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:** [November 13, 2011, 8:41am UTC](https://discuss.elastic.co/t/confusion-problems-working-with-facets-for-nested-documents/5842/2 "2011-11-13T08:41:43Z")

</div>

Hey,

Yea, check the nested part described here:  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/) (at the  
bottom).

-shay.banon

On Fri, Nov 11, 2011 at 10:27 AM, rubish gupta \<[rubish.gupta@almaconnect.com](mailto:rubish.gupta@almaconnect.com)

> wrote:

> I am trying to implement faceted search for users.
> 
> Relevant part of mapping for users can be seen at  
> [elasticsearch nested facets problem · GitHub](https://gist.github.com/1357430#file_mapping.json). Each user has some  
> personal\_info, alma\_info and many professional details. I want to filter  
> users based on name, course/branch(alma\_info) and professional details.  
> Professions are nested documents in a user.
> 
> Sample document for the user can be seen at  
> [elasticsearch nested facets problem · GitHub](https://gist.github.com/1357430#file_sample_document.json).
> 
> I have three use cases for facets on company names of users:
> 
> 1. Facet on all past and current(independently) company names of  
> matched users in the query
> 2. Facet on past and current company names matching a string(using  
> edgeNGram) of matched users
> 3. Facet on company names excluding documents matching certain names  
> of matched users
> 
> Questions:
> 
> 1. Is it possible to filter on root documents and only get facets for  
> nested types for the filtered root documents. Query I was trying to  
> generate for this was [elasticsearch nested facets problem · GitHub](https://gist.github.com/1357430#file_query1.curl).  
> Data does have some professions with companies, but its showing missing for  
> all.
> 2. Is it possible to filter on root documents and only get facets for  
> nested documents matching some more conditions. Query I was trying to  
> generate for this was [elasticsearch nested facets problem · GitHub](https://gist.github.com/1357430#file_query2.curl)
> 
> I would appreciate any help I can get. Please let me know if I information  
> provided is not sufficient.

---

<div class="post-metadata">

**Author:** ![Rubish\_Gupta](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@Rubish\_Gupta](https://discuss.elastic.co/u/Rubish_Gupta)\
**Post date:** [November 14, 2011, 7:19am UTC](https://discuss.elastic.co/t/confusion-problems-working-with-facets-for-nested-documents/5842/3 "2011-11-14T07:19:08Z")

</div>

Thanks for the link Shay.

I already visited that page earlier. I guess I was constructing the query  
wrongly earlier. After making some changes to the query(making it pretty  
minimalistic to start with) I am getting the exception,  
ArrayIndexOutOfBound. I have replied to the thread and will try to come up  
with a recreation.

On Sun, Nov 13, 2011 at 2:11 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> Hey,
> 
> Yea, check the nested part described here:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/) (at the  
> bottom).
> 
> -shay.banon
> 
> On Fri, Nov 11, 2011 at 10:27 AM, rubish gupta \<  
> [rubish.gupta@almaconnect.com](mailto:rubish.gupta@almaconnect.com)\> wrote:
> 
> > I am trying to implement faceted search for users.
> > 
> > Relevant part of mapping for users can be seen at  
> > [elasticsearch nested facets problem · GitHub](https://gist.github.com/1357430#file_mapping.json). Each user has some  
> > personal\_info, alma\_info and many professional details. I want to filter  
> > users based on name, course/branch(alma\_info) and professional details.  
> > Professions are nested documents in a user.
> > 
> > Sample document for the user can be seen at  
> > [elasticsearch nested facets problem · GitHub](https://gist.github.com/1357430#file_sample_document.json).
> > 
> > I have three use cases for facets on company names of users:
> > 
> > 1. Facet on all past and current(independently) company names of  
> > matched users in the query
> > 2. Facet on past and current company names matching a string(using  
> > edgeNGram) of matched users
> > 3. Facet on company names excluding documents matching certain names  
> > of matched users
> > 
> > Questions:
> > 
> > 1. Is it possible to filter on root documents and only get facets for  
> > nested types for the filtered root documents. Query I was trying to  
> > generate for this was [elasticsearch nested facets problem · GitHub](https://gist.github.com/1357430#file_query1.curl).  
> > Data does have some professions with companies, but its showing missing for  
> > all.
> > 2. Is it possible to filter on root documents and only get facets for  
> > nested documents matching some more conditions. Query I was trying to  
> > generate for this was [elasticsearch nested facets problem · GitHub](https://gist.github.com/1357430#file_query2.curl)
> > 
> > I would appreciate any help I can get. Please let me know if I  
> > information provided is not sufficient.

---

<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, 3:48am UTC](https://discuss.elastic.co/t/confusion-problems-working-with-facets-for-nested-documents/5842/4 "2017-07-06T03:48:49Z")

</div>


