2014-03-24 61 views

回答

7

您可以按类型过滤聚合,然后使用子聚合。例如:

{ 
    "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 
      } 
     } 
     } 
    } 
    } 
} 
+0

真棒,就像一个魅力! – Stephen

+0

这应该发布到'your_server_url/index/_search'(URL中没有类型) – alf

0

如果您可以通过现场聚集在所有类型:

curl -XGET 'localhost:9200/index/type1,type2,type3,typeN/_search/?pretty=true' -d '{ 
     "query": { 
     "filtered": { 
      "query": { 
      "match_all": {} 
      } 
     } 
     }, 
     "size": 0, 
     "aggs": { 
     "field_aggs": { 
      "terms": { 
      "size": 0, 
      "field": "field_common_on_all_types" 
      }, 
      "aggs": { 
      "testing": { 
       "terms": { 
       "field": "_type" 
       }, 
       "aggs": { 
       "testing": { 
        "date_histogram": { 
        "field": "date_start", 
        "interval": "month", 
        "format": "yyyy-MM-dd HH:mm:ss" 
        } 
       } 
       } 
      } 
      } 
     } 
     } 
    }'