# Facet values of nested documents?

**URL:** <https://discuss.elastic.co/t/facet-values-of-nested-documents/8780>\
**Category:** Elasticsearch\
**Created:** [August 18, 2012, 3:52pm UTC](https://discuss.elastic.co/t/facet-values-of-nested-documents/8780 "2012-08-18T15:52:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cory\_G\_Watson](https://avatars.discourse-cdn.com/v4/letter/c/779978/32.png) [@Cory\_G\_Watson](https://discuss.elastic.co/u/Cory_G_Watson)\
**Post date:** [August 18, 2012, 3:52pm UTC](https://discuss.elastic.co/t/facet-values-of-nested-documents/8780/1 "2012-08-18T15:52:50Z")

</div>

I've used faceting for years in multiple search products and I've always  
run into the following problem.

If I've a document like:

{  
name: "foo",  
status\_id: 1,  
status\_name: "Super Awesome"  
}

I can facet this document on status\_id, then give my users a link to filter  
by it, appending a status\_id=1 to the URL, for example.

But I always have to make a choice. Facet by the computer-friendly id or  
the human friendly name? I of course want to show the user the  
status\_name, but it's not really appropriate for use in the URL.

If I change my document to:

{  
name: "foo",  
status: {  
id: 1,  
name: "Super Awesome"  
}  
}

It seems I cannot simply say "facet on status" and get back the nested  
object as a value.

What strategies do you guys use to solve this dilemma? Have I been  
overlooking some painfully obvious mechanism to cleanly facet, provide  
users with a friendly facet key and then specify a filter?\*

- I'm trying to avoid getting back a list of "ids" and retrieving them from  
the database.

Thanks!

--

---

<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:** [August 18, 2012, 4:54pm UTC](https://discuss.elastic.co/t/facet-values-of-nested-documents/8780/2 "2012-08-18T16:54:57Z")

</div>

Some thoughts.

- If your number of status ids is really low, you can just render it on the web page as its name.  
(something with a switch like function).

- You can facet on name and encode in BASE64 the name before adding it to the URL.

- You can define your documents by concatenating id and name: "1|Super Awesome" and facet on that. Then, manage it on the interface side.

- you can concatenate (just like above) but only when computing facet using script field: [http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet.html)

HTH

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 18 août 2012 à 17:52, Cory G Watson [jheephat@gmail.com](mailto:jheephat@gmail.com) a écrit :

I've used faceting for years in multiple search products and I've always run into the following problem.

If I've a document like:

{  
name: "foo",  
status\_id: 1,  
status\_name: "Super Awesome"  
}

I can facet this document on status\_id, then give my users a link to filter by it, appending a status\_id=1 to the URL, for example.

But I always have to make a choice. Facet by the computer-friendly id or the human friendly name? I of course want to show the user the status\_name, but it's not really appropriate for use in the URL.

If I change my document to:

{  
name: "foo",  
status: {  
id: 1,  
name: "Super Awesome"  
}  
}

It seems I cannot simply say "facet on status" and get back the nested object as a value.

What strategies do you guys use to solve this dilemma? Have I been overlooking some painfully obvious mechanism to cleanly facet, provide users with a friendly facet key and then specify a filter?\*

- I'm trying to avoid getting back a list of "ids" and retrieving them from the database.

## Thanks!

--

---

<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:15am UTC](https://discuss.elastic.co/t/facet-values-of-nested-documents/8780/3 "2017-07-06T03:15:55Z")

</div>


