# Terms Faceting based on the value of another data point

**URL:** <https://discuss.elastic.co/t/terms-faceting-based-on-the-value-of-another-data-point/12624>\
**Category:** Elasticsearch\
**Created:** [July 2, 2013, 6:53pm UTC](https://discuss.elastic.co/t/terms-faceting-based-on-the-value-of-another-data-point/12624 "2013-07-02T18:53:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonfill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasonfill/32/2254_2.png) [@jasonfill](https://discuss.elastic.co/u/jasonfill)\
**Post date:** [July 2, 2013, 6:53pm UTC](https://discuss.elastic.co/t/terms-faceting-based-on-the-value-of-another-data-point/12624/1 "2013-07-02T18:53:13Z")

</div>

Hello,

I am trying to run a terms facet based on the data below, however the  
condition for inclusion is based on another field. So as an example, in  
the data below, I want to create a facet based on "user.metadata.response"  
BUT only when "user.metadata.parameterid" = key1. Is this possible? I have  
tried several things but I figure out how to get that to work - if it is  
even possible.

{  
"user":{  
"status":{  
"completionpercentage":43  
},  
"metadata":[  
{  
"parameterid":"key1",  
"response":"South"  
},  
{  
"parameterid":"key2",  
"response":"Red"  
}  
]  
}  
}

--  
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:** ![mattweber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattweber/32/44940_2.png) [@mattweber](https://discuss.elastic.co/u/mattweber)\
**Post date:** [July 2, 2013, 7:29pm UTC](https://discuss.elastic.co/t/terms-faceting-based-on-the-value-of-another-data-point/12624/2 "2013-07-02T19:29:11Z")

</div>

Make sure, metadata is a nested field (  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/nested-type/)), then  
use a facet filter. I think something like this might do the trick:

"facets" : {  
"metaResponse" : {  
"terms" : {  
"field" : "user.metadata.response"  
},  
"facet\_filter" : {  
"nested" : {  
"path" : "user.metadata",  
"query" : {  
"term" : {  
"user.metadata.parameterid" : "key1"  
}  
}  
}  
},  
"nested" : "user.metadata"  
}  
}

Thanks,  
Matt Weber

On Tue, Jul 2, 2013 at 11:53 AM, Jason Fill [jasonfill@gmail.com](mailto:jasonfill@gmail.com) wrote:

> Hello,
> 
> I am trying to run a terms facet based on the data below, however the  
> condition for inclusion is based on another field. So as an example, in  
> the data below, I want to create a facet based on "user.metadata.response"  
> BUT only when "user.metadata.parameterid" = key1. Is this possible? I have  
> tried several things but I figure out how to get that to work - if it is  
> even possible.
> 
> {  
> "user":{  
> "status":{  
> "completionpercentage":43  
> },  
> "metadata":[  
> {  
> "parameterid":"key1",  
> "response":"South"  
> },  
> {  
> "parameterid":"key2",  
> "response":"Red"  
> }  
> ]  
> }  
> }
> 
> --  
> 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:** ![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:28am UTC](https://discuss.elastic.co/t/terms-faceting-based-on-the-value-of-another-data-point/12624/3 "2017-07-06T02:28:36Z")

</div>

Closed on July 6, 2017, 2:28am UTC


