Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict ElasticSearch aggregation by type?

How do you perform an ElasticSearch aggregation for a specific type? I realize that you can specify the index and/or type in the request Url, but I want to perform aggregations on two distinct types.

Thank you!

like image 940
Stephen Avatar asked Mar 24 '14 23:03

Stephen


1 Answers

You could filter the aggregation by type, and then use sub-aggregations. For example:

{
  "aggs": {
    "Test 1": {
      "filter": {
        "type": {
          "value": "type1"
        }
      },
      "aggs": {
        "agg_name": {
          "terms": {
            "field": "field1",
            "size": 10
          }
        }
      }
    },
    "Test 2": {
      "filter": {
        "type": {
          "value": "type2"
        }
      },
      "aggs": {
        "agg_name": {
          "terms": {
            "field": "field2",
            "size": 10
          }
        }
      }
    }
  }
}
like image 70
Akshay Avatar answered Sep 22 '22 15:09

Akshay