# Can't make include/exclude patterns on aggregation work

**URL:** https://discuss.elastic.co/t/cant-make-include-exclude-patterns-on-aggregation-work/43537
**Category:** Elasticsearch
**Created:** [March 4, 2016, 5:11pm UTC](https://discuss.elastic.co/t/cant-make-include-exclude-patterns-on-aggregation-work/43537 "2016-03-04T17:11:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![eadauto](https://avatars.discourse-cdn.com/v4/letter/e/8baadc/32.png) [@eadauto](https://discuss.elastic.co/u/eadauto)
#### Post date: [March 4, 2016, 5:11pm UTC](https://discuss.elastic.co/t/cant-make-include-exclude-patterns-on-aggregation-work/43537/1 "2016-03-04T17:11:51Z")

</div>

I have been trying to use include/exclude patterns on aggregations but I can't understand what the problem is. I want to include only the results that on PLAN\_TYPE have the word DATOS. I really don't understand why it gives me results I don't expect. Here are some of the things I have tried:

Request1:

GET \_search  
{  
"size": 0,  
"query": {  
"query\_string": {  
"query": "\*",  
"analyze\_wildcard": true  
}  
},  
"aggs": {  
"2": {  
"terms": {  
"field": "PLAN\_TYPE",  
"include": {  
"pattern": "._DA_."  
},  
"size": 105,  
"order": {  
"1": "desc"  
}  
},  
"aggs": {  
"1": {  
"sum": {  
"field": "SUB\_POSTPAGO"  
}  
}  
}  
}  
}  
}

Response1:

GET \_search  
{  
"size": 0,  
"query": {  
"query\_string": {  
"query": "\*",  
"analyze\_wildcard": true  
}  
},  
"aggs": {  
"2": {  
"terms": {  
"field": "PLAN\_TYPE",  
"include": {  
"pattern": "._DA_."  
},  
"size": 105,  
"order": {  
"1": "desc"  
}  
},  
"aggs": {  
"1": {  
"sum": {  
"field": "SUB\_POSTPAGO"  
}  
}  
}  
}  
}  
}

If I add a T to make something close to DATOS I get an error:

Request2:

GET \_search  
{  
"size": 0,  
"query": {  
"query\_string": {  
"query": "\*",  
"analyze\_wildcard": true  
}  
},  
"aggs": {  
"2": {  
"terms": {  
"field": "PLAN\_TYPE",  
"include": {  
"pattern": "._DAT_."  
},  
"size": 105,  
"order": {  
"1": "desc"  
}  
},  
"aggs": {  
"1": {  
"sum": {  
"field": "SUB\_POSTPAGO"  
}  
}  
}  
}  
}  
}

Response2:  
{  
"took": 3,  
"timed\_out": false,  
"\_shards": {  
"total": 11,  
"successful": 11,  
"failed": 0  
},  
"hits": {  
"total": 3487,  
"max\_score": 0,  
"hits": []  
},  
"aggregations": {  
"2": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets": []  
}  
}  
}

Any idea?

---

<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 5, 2017, 11:11pm UTC](https://discuss.elastic.co/t/cant-make-include-exclude-patterns-on-aggregation-work/43537/2 "2017-07-05T23:11:10Z")

</div>


