# How to count all occurences in ES via search api call?

**URL:** <https://discuss.elastic.co/t/how-to-count-all-occurences-in-es-via-search-api-call/21645>\
**Category:** Elasticsearch\
**Created:** [January 14, 2015, 7:35pm UTC](https://discuss.elastic.co/t/how-to-count-all-occurences-in-es-via-search-api-call/21645 "2015-01-14T19:35:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bhumir\_Jhaveri](https://avatars.discourse-cdn.com/v4/letter/b/9d8465/32.png) [@Bhumir\_Jhaveri](https://discuss.elastic.co/u/Bhumir_Jhaveri)\
**Post date:** [January 14, 2015, 7:35pm UTC](https://discuss.elastic.co/t/how-to-count-all-occurences-in-es-via-search-api-call/21645/1 "2015-01-14T19:35:06Z")

</div>

Hey,

I have data stored in ES(1.4.2) as  
1st document :  
{  
"col1":"123","col2":"tag1,tag2,tag4"  
}  
2nd...  
{  
"col1":"333","col2":"tag1,tag4,tag5"  
}  
3rd...  
{  
"col1":"111","col2":"tag1,tag1,tag5,tag5"  
}

now when I am searching it via making search api call - Search is for tag1

- it returns me the count of 3 where as I am looking for 4 since 3rd  
document is having tag1 two times -  
I am generating the stats data via kibana (3.1.2) so thats my client who  
makes call to ES?

Is there any analyzer or tokenizer that I should be using while creating an  
index?  
Though I am not using any special tokenizer or anything while creating  
index - I am creating index on both col1 and col2.

Any workaround on this?

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/74315594-b2e8-4b3d-972d-3891af6bc06b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/74315594-b2e8-4b3d-972d-3891af6bc06b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ed\_Kim](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@Ed\_Kim](https://discuss.elastic.co/u/Ed_Kim)\
**Post date:** [January 14, 2015, 8:00pm UTC](https://discuss.elastic.co/t/how-to-count-all-occurences-in-es-via-search-api-call/21645/2 "2015-01-14T20:00:16Z")

</div>

Perhaps use nested documents for your tag list?

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

I don't think you can aggregate substrings in a single field since normal  
aggregation is based on matches against the entire document. By having  
nested (or parent child), now you have documents for each tag that you can  
aggregate against.

On Wednesday, January 14, 2015 at 11:35:07 AM UTC-8, Bhumir Jhaveri wrote:

> Hey,
> 
> I have data stored in ES(1.4.2) as  
> 1st document :  
> {  
> "col1":"123","col2":"tag1,tag2,tag4"  
> }  
> 2nd...  
> {  
> "col1":"333","col2":"tag1,tag4,tag5"  
> }  
> 3rd...  
> {  
> "col1":"111","col2":"tag1,tag1,tag5,tag5"  
> }
> 
> now when I am searching it via making search api call - Search is for tag1
> 
> - it returns me the count of 3 where as I am looking for 4 since 3rd  
> document is having tag1 two times -  
> I am generating the stats data via kibana (3.1.2) so thats my client who  
> makes call to ES?
> 
> Is there any analyzer or tokenizer that I should be using while creating  
> an index?  
> Though I am not using any special tokenizer or anything while creating  
> index - I am creating index on both col1 and col2.
> 
> Any workaround on this?

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f31b587c-0dae-4f4c-a317-62d81265338b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f31b587c-0dae-4f4c-a317-62d81265338b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Bhumir\_Jhaveri](https://avatars.discourse-cdn.com/v4/letter/b/9d8465/32.png) [@Bhumir\_Jhaveri](https://discuss.elastic.co/u/Bhumir_Jhaveri)\
**Post date:** [January 14, 2015, 8:57pm UTC](https://discuss.elastic.co/t/how-to-count-all-occurences-in-es-via-search-api-call/21645/3 "2015-01-14T20:57:15Z")

</div>

Is there any other alternate since this particular field would be accessed  
from kibana? and I dont think kibana has support for such aggregation or  
may be I have not explored enough - to say it better.

On Wednesday, January 14, 2015 at 12:00:17 PM UTC-8, Ed Kim wrote:

> Perhaps use nested documents for your tag list?
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html)
> 
> I don't think you can aggregate substrings in a single field since normal  
> aggregation is based on matches against the entire document. By having  
> nested (or parent child), now you have documents for each tag that you can  
> aggregate against.
> 
> On Wednesday, January 14, 2015 at 11:35:07 AM UTC-8, Bhumir Jhaveri wrote:
> 
> > Hey,
> > 
> > I have data stored in ES(1.4.2) as  
> > 1st document :  
> > {  
> > "col1":"123","col2":"tag1,tag2,tag4"  
> > }  
> > 2nd...  
> > {  
> > "col1":"333","col2":"tag1,tag4,tag5"  
> > }  
> > 3rd...  
> > {  
> > "col1":"111","col2":"tag1,tag1,tag5,tag5"  
> > }
> > 
> > now when I am searching it via making search api call - Search is for  
> > tag1 - it returns me the count of 3 where as I am looking for 4 since 3rd  
> > document is having tag1 two times -  
> > I am generating the stats data via kibana (3.1.2) so thats my client who  
> > makes call to ES?
> > 
> > Is there any analyzer or tokenizer that I should be using while creating  
> > an index?  
> > Though I am not using any special tokenizer or anything while creating  
> > index - I am creating index on both col1 and col2.
> > 
> > Any workaround on this?

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/54bd81ec-9766-4868-8ca5-05cd6dbccb6a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/54bd81ec-9766-4868-8ca5-05cd6dbccb6a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:38am UTC](https://discuss.elastic.co/t/how-to-count-all-occurences-in-es-via-search-api-call/21645/4 "2017-07-06T00:38:52Z")

</div>


