# Counting occurrences of term containing more than one word

**URL:** <https://discuss.elastic.co/t/counting-occurrences-of-term-containing-more-than-one-word/9841>\
**Category:** Elasticsearch\
**Created:** [November 27, 2012, 12:47pm UTC](https://discuss.elastic.co/t/counting-occurrences-of-term-containing-more-than-one-word/9841 "2012-11-27T12:47:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barak\_Yaish](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@Barak\_Yaish](https://discuss.elastic.co/u/Barak_Yaish)\
**Post date:** [November 27, 2012, 12:47pm UTC](https://discuss.elastic.co/t/counting-occurrences-of-term-containing-more-than-one-word/9841/1 "2012-11-27T12:47:34Z")

</div>

Hi,

I would like to count occurrences of a term what that term may contain more  
than one word. For example I’ve a field with a text like “this is a nice  
simple text, very nice text” and I need to count the occurrences of “simple  
text”.

I’m able to search such documents by using QueryBuilders.textPhraseQuery(  
field, “simple text” ), but when it comes to TermsFacet, the count is per  
word. Is it possible to have facet for such case?

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:** [November 27, 2012, 1:06pm UTC](https://discuss.elastic.co/t/counting-occurrences-of-term-containing-more-than-one-word/9841/2 "2012-11-27T13:06:21Z")

</div>

You can set a specific analyzer for facets.  
Using a multifield type, you can define an analyzer for your searches and one  
for the facets.

Then, you have to find the analyzer that answer to your needs.  
For example, il you use a keyword analyzer, your facet will count the occurences  
of "this is a nice simple text, very nice text"

Problem is here to find the right analyzer that can combine two words (like the  
ngram but for words)!  
I don't know if it exist.

David

Le 27 novembre 2012 à 13:47, barak [barak.yaish@gmail.com](mailto:barak.yaish@gmail.com) a écrit :

> Hi,
> 
> I would like to count occurrences of a term what that term may contain more  
> than one word. For example I’ve a field with a text like “this is a nice  
> simple text, very nice text” and I need to count the occurrences of “simple  
> text”.
> 
> I’m able to search such documents by using QueryBuilders.textPhraseQuery(  
> field, “simple text” ), but when it comes to TermsFacet, the count is per  
> word. Is it possible to have facet for such case?
> 
> Thanks.
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<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:02am UTC](https://discuss.elastic.co/t/counting-occurrences-of-term-containing-more-than-one-word/9841/3 "2017-07-06T03:02:44Z")

</div>

Closed on July 6, 2017, 3:02am UTC


