# Facet Query on Phrase

**URL:** <https://discuss.elastic.co/t/facet-query-on-phrase/7375>\
**Category:** Elasticsearch\
**Created:** [April 18, 2012, 8:53am UTC](https://discuss.elastic.co/t/facet-query-on-phrase/7375 "2012-04-18T08:53:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sumit\_Guptaa](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Sumit\_Guptaa](https://discuss.elastic.co/u/Sumit_Guptaa)\
**Post date:** [April 18, 2012, 8:53am UTC](https://discuss.elastic.co/t/facet-query-on-phrase/7375/1 "2012-04-18T08:53:08Z")

</div>

Hi all,

I am looking for facet on phrases.  
suppose I have field text with value "abc xyz def" and "abc xyz ghi def"

i need some help to get facet count like "abc xyz"- count:"2" , "abc"-count:"2", "xyz"- count:"2", "def" - count:"2","ghi" -count:"1"....

Thanks

Regards,  
Sumit Gupta

---

<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:** [April 19, 2012, 2:57pm UTC](https://discuss.elastic.co/t/facet-query-on-phrase/7375/2 "2012-04-19T14:57:45Z")

</div>

Facets are working on tokens. So, you need to define analyzer that is going  
to split your values into proper tokens. I don't quite understand your  
requirements here though. Do you want to split your string values into  
words and pairs of words? For example, would "xyz def" be a proper facet?

On Wednesday, April 18, 2012 4:53:08 AM UTC-4, Sumit Gupta wrote:

> Hi all,
> 
> I am looking for facet on phrases.  
> suppose I have field text with value "abc xyz def" and "abc xyz ghi def"
> 
> i need some help to get facet count like "abc xyz"- count:"2" ,  
> "abc"-count:"2", "xyz"- count:"2", "def" - count:"2","ghi" -count:"1"....
> 
> Thanks
> 
> Regards,  
> Sumit Gupta
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Facet-Query-on-Phrase-tp3919427p3919427.html](http://elasticsearch-users.115913.n3.nabble.com/Facet-Query-on-Phrase-tp3919427p3919427.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Sumit\_Guptaa](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Sumit\_Guptaa](https://discuss.elastic.co/u/Sumit_Guptaa)\
**Post date:** [April 20, 2012, 5:17am UTC](https://discuss.elastic.co/t/facet-query-on-phrase/7375/3 "2012-04-20T05:17:34Z")

</div>

hi Igor Motov

i am new in elasticsearch so please can u give me one example for this implementation....it would be very helpful to me for understading...

i just only want suppose we have a index that has only one filed like message and the value is in message is "abc xyz def" and "abc xyz ghi def" and when we search for "abc xyz" we get the following result like  
"abc xyz"- count:"2" , "abc"-count:"2", "xyz"- count:"2", "def" - count:"2","ghi" -count:"1"

thanx...  
Regards  
Sumit Gupta

---

<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:** [April 20, 2012, 10:26am UTC](https://discuss.elastic.co/t/facet-query-on-phrase/7375/4 "2012-04-20T10:26:58Z")

</div>

Sorry, it seems that I misunderstood your question then. I am afraid, what  
you are trying to do is not possible with elasticsearch. In elasticsearch,  
facets are computed on complete records, not on only on the parts that  
matched.

On Friday, April 20, 2012 1:17:34 AM UTC-4, Sumit Gupta wrote:

> hi Igor Motov
> 
> i am new in elasticsearch so please can u give me one example for this  
> implementation....it would be very helpful to me for understading...
> 
> i just only want suppose we have a index that has only one filed like  
> message and the value is in message is "abc xyz def" and "abc xyz ghi def"  
> and when we search for "abc xyz" we get the following result like  
> "abc xyz"- count:"2" , "abc"-count:"2", "xyz"- count:"2", "def" -  
> count:"2","ghi" -count:"1"
> 
> thanx...  
> Regards  
> Sumit Gupta
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Facet-Query-on-Phrase-tp3919427p3925174.html](http://elasticsearch-users.115913.n3.nabble.com/Facet-Query-on-Phrase-tp3919427p3925174.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![pulkitsinghal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pulkitsinghal/32/802_2.png) [@pulkitsinghal](https://discuss.elastic.co/u/pulkitsinghal)\
**Post date:** [May 28, 2012, 12:48pm UTC](https://discuss.elastic.co/t/facet-query-on-phrase/7375/5 "2012-05-28T12:48:58Z")

</div>

I agree with Igor but I wonder it is possible to change the indexing  
approach? You can write a script that takes your document field and then  
breaks down and stores the string "abc def abc hij" into a temporary new  
index where you PUT each word as a new document and then do your search on  
that new temporary index?

On Fri, Apr 20, 2012 at 5:26 AM, Igor Motov [imotov@gmail.com](mailto:imotov@gmail.com) wrote:

> Sorry, it seems that I misunderstood your question then. I am afraid, what  
> you are trying to do is not possible with elasticsearch. In elasticsearch,  
> facets are computed on complete records, not on only on the parts that  
> matched.
> 
> On Friday, April 20, 2012 1:17:34 AM UTC-4, Sumit Gupta wrote:
> 
> > hi Igor Motov
> > 
> > i am new in elasticsearch so please can u give me one example for this  
> > implementation....it would be very helpful to me for understading...
> > 
> > i just only want suppose we have a index that has only one filed like  
> > message and the value is in message is "abc xyz def" and "abc xyz ghi  
> > def"  
> > and when we search for "abc xyz" we get the following result like  
> > "abc xyz"- count:"2" , "abc"-count:"2", "xyz"- count:"2", "def" -  
> > count:"2","ghi" -count:"1"
> > 
> > thanx...  
> > Regards  
> > Sumit Gupta
> > 
> > --  
> > View this message in context: [http://elasticsearch-users](http://elasticsearch-users).\*\*  
> > [115913.n3.nabble.com/Facet-\*\*Query-on-Phrase-\*\*tp3919427p3925174.html](http://115913.n3.nabble.com/Facet- **Query-on-Phrase-** tp3919427p3925174.html)[http://elasticsearch-users.115913.n3.nabble.com/Facet-Query-on-Phrase-tp3919427p3925174.html](http://elasticsearch-users.115913.n3.nabble.com/Facet-Query-on-Phrase-tp3919427p3925174.html)  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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:26am UTC](https://discuss.elastic.co/t/facet-query-on-phrase/7375/6 "2017-07-06T03:26:41Z")

</div>


