# Elasticsearch query aggregation only terms with a specific pattern

**URL:** <https://discuss.elastic.co/t/elasticsearch-query-aggregation-only-terms-with-a-specific-pattern/82540>\
**Category:** Elasticsearch\
**Created:** [April 17, 2017, 7:53am UTC](https://discuss.elastic.co/t/elasticsearch-query-aggregation-only-terms-with-a-specific-pattern/82540 "2017-04-17T07:53:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Melvyn\_Peignon](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@Melvyn\_Peignon](https://discuss.elastic.co/u/Melvyn_Peignon)\
**Post date:** [April 17, 2017, 7:53am UTC](https://discuss.elastic.co/t/elasticsearch-query-aggregation-only-terms-with-a-specific-pattern/82540/1 "2017-04-17T07:53:44Z")

</div>

I have done this query:

```
{
  "size": 0,
  "query": {
    "query_string": {
      "query": "*",
      "analyze_wildcard": true
    }
  },
  "_source": {
    "excludes": []
  },
  "aggs": {
    "2": {
      "terms": {
        "field": "tokens.keyword",
        "size": 50,
        "order": {
          "_count": "desc"
        }
      }
    }
  }
}

```

This return me the 50 most frequents keywords in my tokens (list of token). I tried to do a request to get the 50 most frequents keywords that start with the characters: "@" how can I do so?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [April 17, 2017, 8:30am UTC](https://discuss.elastic.co/t/elasticsearch-query-aggregation-only-terms-with-a-specific-pattern/82540/2 "2017-04-17T08:30:51Z")

</div>

See the include clause: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#\_filtering\_values\_with\_regular\_expressions](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_filtering_values_with_regular_expressions)

---

<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:** [May 15, 2017, 8:35am UTC](https://discuss.elastic.co/t/elasticsearch-query-aggregation-only-terms-with-a-specific-pattern/82540/3 "2017-05-15T08:35:08Z")

</div>

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