Is it possible to filter aggregation return result?

Hi,

I got example 2 documents

doc: 1

{
...
author: ['mike', 'adam', 'julie']
}

doc: 2

{
...
author: ['mike', 'mike stephen', 'apple']
}

in keyword search scenario, user will search "mike" with query below

{
    "query": {
        "match": {
            "author": "mike"
        }
    },
    "aggs": {
        "field2_terms": {
            "terms": {
                "field": "author"
            }
        }
    }
}

Output for aggregation is

[
    {
        "key": "mike",
        "doc_count": 2
    },
    {
        "key": "adam",
        "doc_count": 1
    },
    {
        "key": "julie",
        "doc_count": 1
    },
    {
        "key": "mike stephen",
        "doc_count": 1
    },
    {
        "key": "apple",
        "doc_count": 1
    }
]

the question is how do I get only MIKE* for aggregation. I would like the aggregation result look like this. is it possible in elasticsearch query?

[
    {
        "key": "mike",
        "doc_count": 2
    },
    {
        "key": "mike stephen",
        "doc_count": 1
    },
]

Hi J_Kit,

Yes it's possible to filter aggregation results with regular expressions:

GET agg-test/_search
{
  "query": {
    "match": {
      "author": "mike"
    }
  },
  "aggs": {
    "field2_terms": {
      "terms": {
        "field": "author",
        "include": "mike.*"
      }
    }
  }
}

Result:

  ...
  "aggregations": {
    "field2_terms": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "mike",
          "doc_count": 2
        },
        {
          "key": "mike stephen",
          "doc_count": 1
        }
      ]
    }
  }