# Terms facet question

**URL:** <https://discuss.elastic.co/t/terms-facet-question/10272>\
**Category:** Elasticsearch\
**Created:** [January 8, 2013, 10:36pm UTC](https://discuss.elastic.co/t/terms-facet-question/10272 "2013-01-08T22:36:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![logstashuserx](https://avatars.discourse-cdn.com/v4/letter/l/ed655f/32.png) [@logstashuserx](https://discuss.elastic.co/u/logstashuserx)\
**Post date:** [January 8, 2013, 10:36pm UTC](https://discuss.elastic.co/t/terms-facet-question/10272/1 "2013-01-08T22:36:13Z")

</div>

Hi all,

Is it possible to do a terms facet of the terms matching a query (not on  
the whole field) ? Like doing a terms facet on only the terms what would be  
highlighted if I used the highlight feature with my query.

/DG

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [January 9, 2013, 12:46am UTC](https://discuss.elastic.co/t/terms-facet-question/10272/2 "2013-01-09T00:46:28Z")

</div>

If you can easily identify the terms and there are not too many of them,  
you can add a filter facet[http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html)for each term.

On Tuesday, January 8, 2013 5:36:13 PM UTC-5, [logsta...@gmail.com](mailto:logsta...@gmail.com) wrote:

> Hi all,
> 
> Is it possible to do a terms facet of the terms matching a query (not on  
> the whole field) ? Like doing a terms facet on only the terms what would be  
> highlighted if I used the highlight feature with my query.
> 
> /DG

--

---

<div class="post-metadata">

**Author:** ![logstashuserx](https://avatars.discourse-cdn.com/v4/letter/l/ed655f/32.png) [@logstashuserx](https://discuss.elastic.co/u/logstashuserx)\
**Post date:** [January 9, 2013, 8:59am UTC](https://discuss.elastic.co/t/terms-facet-question/10272/3 "2013-01-09T08:59:32Z")

</div>

Thank you for your answer Igor,  
You mean doing this in two steps ?

- a query with highlighting to identify the matching terms
- a terms facet with a filter facet consisting of the list of highlighted  
terms  
So, is there a way to easily identify all the distinct matching terms of a  
query (in all the results), to put them in an array ? Additional work would  
be needed to collect highlighted terms and create an array of them.

However, isn't there a way to do what I want in one step ? (a facet on the  
matching TERMS (not results) of a query) ?

Le mercredi 9 janvier 2013 01:46:28 UTC+1, Igor Motov a écrit :

> If you can easily identify the terms and there are not too many of them,  
> you can add a filter facet[http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html)for each term.
> 
> On Tuesday, January 8, 2013 5:36:13 PM UTC-5, [logsta...@gmail.com](mailto:logsta...@gmail.com) wrote:
> 
> > Hi all,
> > 
> > Is it possible to do a terms facet of the terms matching a query (not on  
> > the whole field) ? Like doing a terms facet on only the terms what would be  
> > highlighted if I used the highlight feature with my query.
> > 
> > /DG

--

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [January 9, 2013, 3:45pm UTC](https://discuss.elastic.co/t/terms-facet-question/10272/4 "2013-01-09T15:45:43Z")

</div>

Unless I understood the original problem incorrectly, you could use a facet  
with a facet filter, the filter being the original query that determines  
the terms.

On Wed, Jan 9, 2013 at 12:59 AM, [logstashuserx@gmail.com](mailto:logstashuserx@gmail.com) wrote:

> Thank you for your answer Igor,  
> You mean doing this in two steps ?
> 
> - a query with highlighting to identify the matching terms
> - a terms facet with a filter facet consisting of the list of highlighted  
> terms  
> So, is there a way to easily identify all the distinct matching terms of a  
> query (in all the results), to put them in an array ? Additional work would  
> be needed to collect highlighted terms and create an array of them.
> 
> However, isn't there a way to do what I want in one step ? (a facet on the  
> matching TERMS (not results) of a query) ?
> 
> Le mercredi 9 janvier 2013 01:46:28 UTC+1, Igor Motov a écrit :
> 
> > If you can easily identify the terms and there are not too many of them,  
> > you can add a filter facet[http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html)for each term.
> > 
> > On Tuesday, January 8, 2013 5:36:13 PM UTC-5, [logsta...@gmail.com](mailto:logsta...@gmail.com) wrote:
> > 
> > > Hi all,
> > > 
> > > Is it possible to do a terms facet of the terms matching a query (not on  
> > > the whole field) ? Like doing a terms facet on only the terms what would be  
> > > highlighted if I used the highlight feature with my query.
> > > 
> > > /DG
> > 
> > --

--

---

<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:57am UTC](https://discuss.elastic.co/t/terms-facet-question/10272/5 "2017-07-06T02:57:13Z")

</div>


