# Facet on phrases

**URL:** https://discuss.elastic.co/t/facet-on-phrases/5324
**Category:** Elasticsearch
**Created:** [September 7, 2011, 3:32pm UTC](https://discuss.elastic.co/t/facet-on-phrases/5324 "2011-09-07T15:32:26Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Kartavya](https://avatars.discourse-cdn.com/v4/letter/k/65b543/32.png) [@Kartavya](https://discuss.elastic.co/u/Kartavya)
#### Post date: [September 7, 2011, 3:32pm UTC](https://discuss.elastic.co/t/facet-on-phrases/5324/1 "2011-09-07T15:32:26Z")

</div>

Hi

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

Now I need some help to get facet count like "abc xyz"- count:"2" ,  
"abc"-count:"2", "xyz"- count:"2", "def" - count:"2".

Is it possible with elasticsearch? I think elasticsearch is a awesome  
product there must be something to get this.

Thanks in advance.

Pulkit Agrawal

---

<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: [September 7, 2011, 4:31pm UTC](https://discuss.elastic.co/t/facet-on-phrases/5324/2 "2011-09-07T16:31:27Z")

</div>

Yea, tokenize the field into shingles:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Thanks,  
Matt Weber

On Wed, Sep 7, 2011 at 8:32 AM, Pulkit Agrawal [pulkitdotcom@gmail.com](mailto:pulkitdotcom@gmail.com)wrote:

> Hi
> 
> I am looking for facet on phrases.  
> e.g: suppose I have field text with value "abc xyz def" and "abc xyz ghi  
> def"
> 
> Now I need some help to get facet count like "abc xyz"- count:"2" ,  
> "abc"-count:"2", "xyz"- count:"2", "def" - count:"2".
> 
> Is it possible with elasticsearch? I think elasticsearch is a awesome  
> product there must be something to get this.
> 
> Thanks in advance.
> 
> Pulkit Agrawal

---

<div class="post-metadata">

### Author: ![Kartavya](https://avatars.discourse-cdn.com/v4/letter/k/65b543/32.png) [@Kartavya](https://discuss.elastic.co/u/Kartavya)
#### Post date: [September 7, 2011, 5:15pm UTC](https://discuss.elastic.co/t/facet-on-phrases/5324/3 "2011-09-07T17:15:43Z")

</div>

Thanks Matt.

Can you please give me one example for implementation?  
It would be very great.

Regards,  
Pulkit Agrawal

On Wed, Sep 7, 2011 at 10:01 PM, Matt Weber [matt@mattweber.org](mailto:matt@mattweber.org) wrote:

> Yea, tokenize the field into shingles:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/shingle-tokenfilter.html)
> 
> Thanks,  
> Matt Weber
> 
> On Wed, Sep 7, 2011 at 8:32 AM, Pulkit Agrawal [pulkitdotcom@gmail.com](mailto:pulkitdotcom@gmail.com)wrote:
> 
> > Hi
> > 
> > I am looking for facet on phrases.  
> > e.g: suppose I have field text with value "abc xyz def" and "abc xyz ghi  
> > def"
> > 
> > Now I need some help to get facet count like "abc xyz"- count:"2" ,  
> > "abc"-count:"2", "xyz"- count:"2", "def" - count:"2".
> > 
> > Is it possible with elasticsearch? I think elasticsearch is a awesome  
> > product there must be something to get this.
> > 
> > Thanks in advance.
> > 
> > Pulkit Agrawal

---

<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: [September 8, 2011, 10:09pm UTC](https://discuss.elastic.co/t/facet-on-phrases/5324/4 "2011-09-08T22:09:16Z")

</div>

Wouldn't the shingles need to be the same size?

On Wed, Sep 7, 2011 at 12:31 PM, Matt Weber [matt@mattweber.org](mailto:matt@mattweber.org) wrote:

> Yea, tokenize the field into shingles:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/shingle-tokenfilter.html)  
> Thanks,  
> Matt Weber
> 
> On Wed, Sep 7, 2011 at 8:32 AM, Pulkit Agrawal [pulkitdotcom@gmail.com](mailto:pulkitdotcom@gmail.com)  
> wrote:
> 
> > Hi  
> > I am looking for facet on phrases.  
> > e.g: suppose I have field text with value "abc xyz def" and "abc xyz ghi  
> > def"  
> > Now I need some help to get facet count like "abc xyz"- count:"2" ,  
> > "abc"-count:"2", "xyz"- count:"2", "def" - count:"2".
> > 
> > Is it possible with elasticsearch? I think elasticsearch is a awesome  
> > product there must be something to get this.
> > 
> > Thanks in advance.  
> > Pulkit Agrawal

---

<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: [September 9, 2011, 12:11am UTC](https://discuss.elastic.co/t/facet-on-phrases/5324/5 "2011-09-09T00:11:20Z")

</div>

Not sure what you mean by same size. If you have "a b c" and "a b d c" and  
set a max\_shingle\_size = 4 and output\_unigrams = true, we should get these  
facets:

2 - a  
2 - b  
2 - c  
2 - a b  
1 - d  
1 - b c  
1 - b d  
1 - d c  
1 - a b c  
1 - a b d  
1 - b d c  
1 - a b d c

Thanks,  
Matt Weber

On Thu, Sep 8, 2011 at 3:09 PM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> Wouldn't the shingles need to be the same size?
> 
> On Wed, Sep 7, 2011 at 12:31 PM, Matt Weber [matt@mattweber.org](mailto:matt@mattweber.org) wrote:
> 
> > Yea, tokenize the field into shingles:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/shingle-tokenfilter.html)
> 
> > Thanks,  
> > Matt Weber
> > 
> > On Wed, Sep 7, 2011 at 8:32 AM, Pulkit Agrawal [pulkitdotcom@gmail.com](mailto:pulkitdotcom@gmail.com)  
> > wrote:
> > 
> > > Hi  
> > > I am looking for facet on phrases.  
> > > e.g: suppose I have field text with value "abc xyz def" and "abc xyz ghi  
> > > def"  
> > > Now I need some help to get facet count like "abc xyz"- count:"2" ,  
> > > "abc"-count:"2", "xyz"- count:"2", "def" - count:"2".
> > > 
> > > Is it possible with elasticsearch? I think elasticsearch is a awesome  
> > > product there must be something to get this.
> > > 
> > > Thanks in advance.  
> > > Pulkit Agrawal

---

<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: [September 9, 2011, 3:13am UTC](https://discuss.elastic.co/t/facet-on-phrases/5324/6 "2011-09-09T03:13:45Z")

</div>

I guess the word "max" in "max\_shingle\_size" should have given me a  
clue on how it operates! The example confused me since it did not list  
the shingles with one term.

Need to play around with it, I might have a use for it as well.

--  
Ivan

On Thu, Sep 8, 2011 at 8:11 PM, Matt Weber [matt@mattweber.org](mailto:matt@mattweber.org) wrote:

> Not sure what you mean by same size. If you have "a b c" and "a b d c" and  
> set a max\_shingle\_size = 4 and output\_unigrams = true, we should get these  
> facets:  
> 2 - a  
> 2 - b  
> 2 - c  
> 2 - a b  
> 1 - d  
> 1 - b c  
> 1 - b d  
> 1 - d c  
> 1 - a b c  
> 1 - a b d  
> 1 - b d c  
> 1 - a b d c  
> Thanks,  
> Matt Weber
> 
> On Thu, Sep 8, 2011 at 3:09 PM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:
> 
> > Wouldn't the shingles need to be the same size?
> > 
> > On Wed, Sep 7, 2011 at 12:31 PM, Matt Weber [matt@mattweber.org](mailto:matt@mattweber.org) wrote:
> > 
> > > Yea, tokenize the field into shingles:
> > > 
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/shingle-tokenfilter.html)  
> > > Thanks,  
> > > Matt Weber
> > > 
> > > On Wed, Sep 7, 2011 at 8:32 AM, Pulkit Agrawal [pulkitdotcom@gmail.com](mailto:pulkitdotcom@gmail.com)  
> > > wrote:
> > > 
> > > > Hi  
> > > > I am looking for facet on phrases.  
> > > > e.g: suppose I have field text with value "abc xyz def" and "abc xyz  
> > > > ghi  
> > > > def"  
> > > > Now I need some help to get facet count like "abc xyz"- count:"2" ,  
> > > > "abc"-count:"2", "xyz"- count:"2", "def" - count:"2".
> > > > 
> > > > Is it possible with elasticsearch? I think elasticsearch is a awesome  
> > > > product there must be something to get this.
> > > > 
> > > > Thanks in advance.  
> > > > Pulkit Agrawal

---

<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:54am UTC](https://discuss.elastic.co/t/facet-on-phrases/5324/7 "2017-07-06T03:54:59Z")

</div>


