How to filter subindex for aggregation in Elasticsearch?

Viewed 463

I query an index with wildcard (interactive*) to get all documents for the two indices interactive-foo* & interactive-bar*.

For some of my aggregations all of the indices are relevant but for others only interactive-foo* OR interactive-bar*. So I just want to filter for these 'subindices' in the aggregation.

GET _search
{
  "query":{
    "bool": {
      "must": [
        {
          "range": {
            "timestamp": {
              "gte": "2017-08-01 00:00:00",
              "lte": "2017-08-31 23:59:59"
            }
          }
        },
        {
          "match": {
            "key": "SOME_KEY"
          }
        }
      ]
    }
  },
  "size":0,
  "aggs": {
    // This one should be filtered and just count for interactive-bar*
    "bar_count": {
      "value_count": {
        "field": "SOME_FIELD"
      }
    },
    // This one should be filtered and just count for interactive-foo*
    "foo_count": {
      "value_count": {
        "field": "SOME_FIELD"
      }
    }
  }
}
1 Answers
Related