# Number of results in aggregate

**URL:** <https://discuss.elastic.co/t/number-of-results-in-aggregate/21003>\
**Category:** Elasticsearch\
**Created:** [December 1, 2014, 11:08am UTC](https://discuss.elastic.co/t/number-of-results-in-aggregate/21003 "2014-12-01T11:08:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![isart\_montane](https://avatars.discourse-cdn.com/v4/letter/i/2bfe46/32.png) [@isart\_montane](https://discuss.elastic.co/u/isart_montane)\
**Post date:** [December 1, 2014, 11:08am UTC](https://discuss.elastic.co/t/number-of-results-in-aggregate/21003/1 "2014-12-01T11:08:31Z")

</div>

Hi All,

At the company I work for we are evaluating ES to replace certain type of  
queries that we run now on DB. On database we have more than 40k tables and  
we run queries like this one.

SELECT  
t1.user\_id  
FROM  
table1 t1 join table2 t2 on t1.user\_id = t2.user\_id  
WHERE  
t1.name like "%am%"  
AND t2.followers\_count\>1;

For that query we need the user\_id and the number of users affected (count).

On ES I've created an index with an extra field that contains the table  
name, and I've managed to write the query like that:

{  
"query": {  
"bool": {  
"should": [  
{  
"terms": {  
"table\_name": ["t1"],  
"minimum\_should\_match": 1  
}  
},  
{  
"terms": {  
"table\_name": ["t2"],  
"minimum\_should\_match": 1  
}  
}  
]  
}  
},  
"size": 0,  
"aggs" : {  
"user\_ids": {  
"terms" : {  
"field" : "user\_id",  
"min\_doc\_count": 2  
}  
}  
}  
}

The problem I'm facing here is that I cannot get the number of user user\_id  
affected. I get the user\_ids as an aggregate, but I couldn't find the way  
to get the number of them. I've tried to get the count on the client side,  
but sometimes that list can get really big (millions) so it's quite a waste  
of memory.

Any help? Is there a better way to do that?

Thanks,  
Isart Montane Mogas

--  
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/05ecf5f0-6313-4ee4-84a7-d36c0cc844ff%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/05ecf5f0-6313-4ee4-84a7-d36c0cc844ff%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:46am UTC](https://discuss.elastic.co/t/number-of-results-in-aggregate/21003/2 "2017-07-06T00:46:53Z")

</div>


