# Terms aggregation with include ".\*x.\*" times out

**URL:** <https://discuss.elastic.co/t/terms-aggregation-with-include-x-times-out/152787>\
**Category:** Elasticsearch\
**Created:** [October 17, 2018, 9:38am UTC](https://discuss.elastic.co/t/terms-aggregation-with-include-x-times-out/152787 "2018-10-17T09:38:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![newnewb](https://avatars.discourse-cdn.com/v4/letter/n/c37758/32.png) [@newnewb](https://discuss.elastic.co/u/newnewb)\
**Post date:** [October 17, 2018, 9:38am UTC](https://discuss.elastic.co/t/terms-aggregation-with-include-x-times-out/152787/1 "2018-10-17T09:38:29Z")

</div>

Hello everybody,

The goal I'm trying to achieve is to aggregate on all words which contain a specific character. Query example:

```
  "query": {
    "constant_score": {
      "filter": {
        "bool": {
          "must": [
            {"match_phrase": {"word.ngrams": "sex"}}
          ]
        }
      }
    }
  },
  "aggs": {
    "clusters": {
      "terms": {
        "field": "word",
        "include": ".*?.*", 
        "size": 100
      }
    }
  },
  "size": 0
}

```

It works fine if the include parameter contains regex in a form: _ **".\*?"** _ or **_"?.\*"_** , but when searching from both sides **_".?."_** , the request tends to time out (error: Gateway Time-out). I guess too much resources are used for processing such a query.

Is there any other way to achieve this?

I also tried using regexp, as an aggregation, it does return the total amount of hits, but not a list of keywords that actually contain the searched character. Example also below:

```
  "query": {
    "constant_score": {
      "filter": {
        "bool": {
          "must": [
            {"match_phrase": {"word.ngrams": "sex"}}
          ]
        }
      }
    }
  },
  "aggs": {
    "regex_query": {
      "filter": {
        "regexp": {
          "word": {
            "value": ".*?.*"
          }
        }
      }
    }
  },
  "size": 0
}
```

---

<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:** [November 14, 2018, 9:43am UTC](https://discuss.elastic.co/t/terms-aggregation-with-include-x-times-out/152787/2 "2018-11-14T09:43:30Z")

</div>

Closed on November 14, 2018, 9:43am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
