# Terms aggregation and regex filter

**URL:** <https://discuss.elastic.co/t/terms-aggregation-and-regex-filter/22791>\
**Category:** Elasticsearch\
**Created:** [March 21, 2015, 8:32am UTC](https://discuss.elastic.co/t/terms-aggregation-and-regex-filter/22791 "2015-03-21T08:32:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JZ1](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@JZ1](https://discuss.elastic.co/u/JZ1)\
**Post date:** [March 21, 2015, 8:32am UTC](https://discuss.elastic.co/t/terms-aggregation-and-regex-filter/22791/1 "2015-03-21T08:32:40Z")

</div>

Hi all,

With the terms aggregation, you can use include/exclude to filter the  
buckets with regular expressions as described here:  
[http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html](http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html)  
.

I am wondering whether it is possible to do the regex filtering before the  
buckets are returned? I have used the include/exclude option now, but I am  
getting incorrect total document counts.Could someone share an example  
query on how to do this?

Thanks in advance!

/JZ

--  
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/CAA%2BD3eXKangrYSiT29ACka%3DJ3PZborkPJvHjr4Ms-Tw9Me7Qww%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA%2BD3eXKangrYSiT29ACka%3DJ3PZborkPJvHjr4Ms-Tw9Me7Qww%40mail.gmail.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:25am UTC](https://discuss.elastic.co/t/terms-aggregation-and-regex-filter/22791/2 "2017-07-06T00:25:14Z")

</div>


