# How I can do a multiple TermStats? and with string as value\_field?

**URL:** <https://discuss.elastic.co/t/how-i-can-do-a-multiple-termstats-and-with-string-as-value-field/13619>\
**Category:** Elasticsearch\
**Created:** [September 16, 2013, 1:41pm UTC](https://discuss.elastic.co/t/how-i-can-do-a-multiple-termstats-and-with-string-as-value-field/13619 "2013-09-16T13:41:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabien\_Guiraud](https://avatars.discourse-cdn.com/v4/letter/f/57b2e6/32.png) [@Fabien\_Guiraud](https://discuss.elastic.co/u/Fabien_Guiraud)\
**Post date:** [September 16, 2013, 1:41pm UTC](https://discuss.elastic.co/t/how-i-can-do-a-multiple-termstats-and-with-string-as-value-field/13619/1 "2013-09-16T13:41:22Z")

</div>

Hi,

I have a big problem with ES : I want to do a group by and I want to count  
distinct on a value (string value)

I tried with TermStats but it seems it doesn't support string as value...

any idea?

If it can help, my model :

## table

field\_id  
field\_a (string)  
field\_b (array of ids)  
field\_c (count)

In a SQL way, I want : "SELECT sum(field\_c), COUNT(DISTINCT(field\_a)) FROM  
table GROUP BY field\_b

I have no problem with SUM(field\_c) with TermStats, but impossible to do  
the same thing with a string value, I have an error : 'field\_a is not a  
number'

Thanks

--  
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:** ![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:** [September 16, 2013, 1:56pm UTC](https://discuss.elastic.co/t/how-i-can-do-a-multiple-termstats-and-with-string-as-value-field/13619/2 "2013-09-16T13:56:49Z")

</div>

Not sure on how you can compute min, max, mean values on Strings.  
I don't get it. What are you trying to do?

Could you illustrate your use case with a Gist with actual JSon documents?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 16 sept. 2013 à 15:41, Fabien Guiraud [fabien1909@gmail.com](mailto:fabien1909@gmail.com) a écrit :

> Hi,
> 
> I have a big problem with ES : I want to do a group by and I want to count distinct on a value (string value)
> 
> I tried with TermStats but it seems it doesn't support string as value...
> 
> any idea?
> 
> If it can help, my model :
> 
> ## table
> 
> field\_id  
> field\_a (string)  
> field\_b (array of ids)  
> field\_c (count)
> 
> In a SQL way, I want : "SELECT sum(field\_c), COUNT(DISTINCT(field\_a)) FROM table GROUP BY field\_b
> 
> I have no problem with SUM(field\_c) with TermStats, but impossible to do the same thing with a string value, I have an error : 'field\_a is not a number'
> 
> Thanks
> 
> --  
> 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:** ![Fabien\_Guiraud](https://avatars.discourse-cdn.com/v4/letter/f/57b2e6/32.png) [@Fabien\_Guiraud](https://discuss.elastic.co/u/Fabien_Guiraud)\
**Post date:** [September 16, 2013, 2:25pm UTC](https://discuss.elastic.co/t/how-i-can-do-a-multiple-termstats-and-with-string-as-value-field/13619/3 "2013-09-16T14:25:13Z")

</div>

Yes of course!

Here is the Gist : [https://gist.github.com/zywx/6581246](https://gist.github.com/zywx/6581246)

In fact, I have 2 problems :

1. I would like to get all channel\_id and for each one the sum of  
views\_count, dislikes\_count, likes\_count, comments\_count. I succeed for 1  
with terms stats but I can't do that for each one... Here is the gist of my  
query : [https://gist.github.com/zywx/6581303](https://gist.github.com/zywx/6581303)

2. I would like to get all brand\_id and for each one the sum of  
views\_count, dislikes\_count, likes\_count, comments\_count and the distinct  
count of channel\_id.  
I tried this : [https://gist.github.com/zywx/6581373](https://gist.github.com/zywx/6581373) but the problem is I  
don't have separate sum, and I can't have the distinct count of  
channel\_id...

Any idea to help me to move forward ?

Thanks a lot

Fabien

On Monday, September 16, 2013 3:56:49 PM UTC+2, David Pilato wrote:

> Not sure on how you can compute min, max, mean values on Strings.  
> I don't get it. What are you trying to do?
> 
> Could you illustrate your use case with a Gist with actual JSon documents?
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 16 sept. 2013 à 15:41, Fabien Guiraud \<[fabie...@gmail.com](mailto:fabie...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> Hi,
> 
> I have a big problem with ES : I want to do a group by and I want to count  
> distinct on a value (string value)
> 
> I tried with TermStats but it seems it doesn't support string as value...
> 
> any idea?
> 
> If it can help, my model :
> 
> ## table
> 
> field\_id  
> field\_a (string)  
> field\_b (array of ids)  
> field\_c (count)
> 
> In a SQL way, I want : "SELECT sum(field\_c), COUNT(DISTINCT(field\_a)) FROM  
> table GROUP BY field\_b
> 
> I have no problem with SUM(field\_c) with TermStats, but impossible to do  
> the same thing with a string value, I have an error : 'field\_a is not a  
> number'
> 
> Thanks
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> 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:16am UTC](https://discuss.elastic.co/t/how-i-can-do-a-multiple-termstats-and-with-string-as-value-field/13619/4 "2017-07-06T02:16:19Z")

</div>


