Types 按类型限制ElasticSearch聚合?
如何为特定类型执行ElasticSearch聚合?我知道您可以在请求Url中指定索引和/或类型,但我想对两种不同的类型执行聚合Types 按类型限制ElasticSearch聚合?,types,elasticsearch,aggregation,Types,elasticsearch,Aggregation,如何为特定类型执行ElasticSearch聚合?我知道您可以在请求Url中指定索引和/或类型,但我想对两种不同的类型执行聚合 谢谢大家! 您可以按类型筛选聚合,然后使用子聚合。例如: { "aggs": { "Test 1": { "filter": { "type": { "value": "type1" } }, "aggs": { "agg_name": {
谢谢大家! 您可以按类型筛选聚合,然后使用子聚合。例如:
{
"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
}
}
}
}
}
}
如果可以按所有类型的字段进行聚合:
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"
}
}
}
}
}
}
}
}'
这应该发布到你的服务器url/index/search上(url中没有输入)