以官网文档为例,里面有一个user是nested类型,我要统计user下的所有子文档数,需要怎么写呢?求大佬指点~
官网地址:https://www.elastic.co/guide/e ... .html
																				官网地址:https://www.elastic.co/guide/e ... .html
PUT my_index
{
  "mappings": {
    "properties": {
      "user": {
        "type": "nested" 
      }
    }
  }
}
PUT my_index/_doc/1
{
  "group" : "fans",
  "user" : [
    {
      "first" : "John",
      "last" :  "Smith"
    },
    {
      "first" : "Alice",
      "last" :  "White"
    }
  ]
}
 
	
1 个回复
Garf
赞同来自:
{
"size": 0,
"aggs": {
"nest_user": {
"nested": {
"path": "user"
},
"aggs": {
"user_count": {
"value_count": {
"field": "user.first"
}
}
}
}
}
}