如同磁铁吸引四周的铁粉,热情也能吸引周围的人,改变周围的情况。

如何统计nested字段下所有子文档数

Elasticsearch | 作者 haoyanfeiyun | 发布于2019年12月17日 | 阅读数:2595

以官网文档为例,里面有一个user是nested类型,我要统计user下的所有子文档数,需要怎么写呢?求大佬指点~
官网地址: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"
}
]
}
已邀请:

Garf

赞同来自:

GET my_index/_search
{
  "size": 0, 
  "aggs": {
    "nest_user": {
      "nested": {
        "path": "user"
      },
      "aggs": {
        "user_count": {
          "value_count": {
            "field": "user.first"
          }
        }
      }
    }
  }
}
 

要回复问题请先登录注册