# Is it possible to filter facets via a "terms lookup"?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-filter-facets-via-a-terms-lookup/12498>\
**Category:** Elasticsearch\
**Created:** [June 20, 2013, 9:31pm UTC](https://discuss.elastic.co/t/is-it-possible-to-filter-facets-via-a-terms-lookup/12498 "2013-06-20T21:31:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveey](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@daveey](https://discuss.elastic.co/u/daveey)\
**Post date:** [June 20, 2013, 9:31pm UTC](https://discuss.elastic.co/t/is-it-possible-to-filter-facets-via-a-terms-lookup/12498/1 "2013-06-20T21:31:46Z")

</div>

For example, let's say I follow the tweet's example in the facets  
documentation:

curl -X DELETE "[http://localhost:9200/articles](http://localhost:9200/articles)"  
curl -X POST "[http://localhost:9200/articles/article](http://localhost:9200/articles/article)" -d '{"title" :  
"One", "tags" : ["foo"]}'  
curl -X POST "[http://localhost:9200/articles/article](http://localhost:9200/articles/article)" -d '{"title" :  
"Two", "tags" : ["foo", "bar"]}'  
curl -X POST "[http://localhost:9200/articles/article](http://localhost:9200/articles/article)" -d '{"title" :  
"Three", "tags" : ["foo", "bar", "baz"]}'

curl -X POST "[http://localhost:9200/articles/\_search?pretty=true](http://localhost:9200/articles/_search?pretty=true)" -d '  
{  
"size": 0,  
"facets" : {  
"tags" : { "terms" : {"field" : "tags"} }  
}  
}  
'

The documentation suggests I can use a regexp, or a script, or an  
explicit "exclude" clause to control which facets get returned.

However, what I want is to have an explicit list, per user, of valid  
tags, and filter down the facets to just that list. Similarly to how  
the "terms" filter supports a lookup in another index/document.

We currently do this via 2 roundtrips, first fetching the allowed  
tags, then fetching the facets, and then intersecting the two. But it  
would be great if there was a way to do this from within ES.

Thanks for your help!

--  
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:30am UTC](https://discuss.elastic.co/t/is-it-possible-to-filter-facets-via-a-terms-lookup/12498/2 "2017-07-06T02:30:08Z")

</div>

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


