# Count of term occurrences in fields?

**URL:** <https://discuss.elastic.co/t/count-of-term-occurrences-in-fields/12558>\
**Category:** Elasticsearch\
**Created:** [June 27, 2013, 8:42am UTC](https://discuss.elastic.co/t/count-of-term-occurrences-in-fields/12558 "2013-06-27T08:42:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rob\_Styles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rob_styles/32/1612_2.png) [@Rob\_Styles](https://discuss.elastic.co/u/Rob_Styles)\
**Post date:** [June 27, 2013, 8:42am UTC](https://discuss.elastic.co/t/count-of-term-occurrences-in-fields/12558/1 "2013-06-27T08:42:09Z")

</div>

Hi,

I'm wondering if I might be able to use es to help solve an entity  
classification problem I'm working on. I'm trying to classify words or  
phrases by type based on a corpus of data. For example...

We might have a corpus of people

{ "first\_name": "John", "last\_name": "Jones", "state": "CA", }  
{ "first\_name": "John", "last\_name": "Terry", "state": "CA", }  
{ "first\_name": "Richard", "last\_name": "John", "state": "CA", }

With an incoming search term of "John" I want to understand how often it  
occurs in which fields. The information I want back is something like

{ "first\_name": 2, "last\_name": 1 }

That would allow me to understand that "John" is most likely a first name,  
but may be a last name.

Can anyone think of a way to achieve this with es?

thanks

rob

--  
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:** ![Valentin\_Pletzer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/valentin_pletzer/32/105548_2.png) [@Valentin\_Pletzer](https://discuss.elastic.co/u/Valentin_Pletzer)\
**Post date:** [June 27, 2013, 9:23am UTC](https://discuss.elastic.co/t/count-of-term-occurrences-in-fields/12558/2 "2013-06-27T09:23:15Z")

</div>

Hi,

for your "simple" example I would use a Filter Facet

> **[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.

{  
"facets" : {  
"first\_name\_facet" : {  
"filter" : {  
"term" : { "first\_name" : "john" }  
}  
},  
"last\_name\_facet" : {  
"filter" : {  
"term" : { "first\_name" : "john" }  
}  
}  
}  
}

I hope this helps.

Cheers  
Valentin

On Thursday, June 27, 2013 10:42:09 AM UTC+2, Rob Styles wrote:

> Hi,
> 
> I'm wondering if I might be able to use es to help solve an entity  
> classification problem I'm working on. I'm trying to classify words or  
> phrases by type based on a corpus of data. For example...
> 
> We might have a corpus of people
> 
> { "first\_name": "John", "last\_name": "Jones", "state": "CA", }  
> { "first\_name": "John", "last\_name": "Terry", "state": "CA", }  
> { "first\_name": "Richard", "last\_name": "John", "state": "CA", }
> 
> With an incoming search term of "John" I want to understand how often it  
> occurs in which fields. The information I want back is something like
> 
> { "first\_name": 2, "last\_name": 1 }
> 
> That would allow me to understand that "John" is most likely a first name,  
> but may be a last name.
> 
> Can anyone think of a way to achieve this with es?
> 
> thanks
> 
> rob

--  
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:** ![Rob\_Styles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rob_styles/32/1612_2.png) [@Rob\_Styles](https://discuss.elastic.co/u/Rob_Styles)\
**Post date:** [June 27, 2013, 10:00am UTC](https://discuss.elastic.co/t/count-of-term-occurrences-in-fields/12558/3 "2013-06-27T10:00:15Z")

</div>

That's exactly what I needed - combined with size 0 to return only the  
facet counts it works exactly as I want 🙂

Thanks a lot

rob

On 27 June 2013 10:23, Valentin [pletzer@gmail.com](mailto:pletzer@gmail.com) wrote:

> Hi,
> 
> for your "simple" example I would use a Filter Facet  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet/)
> 
> {  
> "facets" : {  
> "first\_name\_facet" : {  
> "filter" : {  
> "term" : { "first\_name" : "john" }  
> }  
> },  
> "last\_name\_facet" : {  
> "filter" : {  
> "term" : { "first\_name" : "john" }  
> }  
> }  
> }  
> }
> 
> I hope this helps.
> 
> Cheers  
> Valentin
> 
> On Thursday, June 27, 2013 10:42:09 AM UTC+2, Rob Styles wrote:
> 
> > Hi,
> > 
> > I'm wondering if I might be able to use es to help solve an entity  
> > classification problem I'm working on. I'm trying to classify words or  
> > phrases by type based on a corpus of data. For example...
> > 
> > We might have a corpus of people
> > 
> > { "first\_name": "John", "last\_name": "Jones", "state": "CA", }  
> > { "first\_name": "John", "last\_name": "Terry", "state": "CA", }  
> > { "first\_name": "Richard", "last\_name": "John", "state": "CA", }
> > 
> > With an incoming search term of "John" I want to understand how often it  
> > occurs in which fields. The information I want back is something like
> > 
> > { "first\_name": 2, "last\_name": 1 }
> > 
> > That would allow me to understand that "John" is most likely a first  
> > name, but may be a last name.
> > 
> > Can anyone think of a way to achieve this with es?
> > 
> > thanks
> > 
> > rob
> 
> --  
> 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).

--  
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:29am UTC](https://discuss.elastic.co/t/count-of-term-occurrences-in-fields/12558/4 "2017-07-06T02:29:16Z")

</div>


