在 Mapping 里面,将 dynamic 参数设置成 strict 可以拒绝索引包含未知字段的文档。 此条 Tips 由 medcl 贡献。

如何实现嵌套统计查询?

Elasticsearch | 作者 hel2o | 发布于2020年12月15日 | 阅读数:1128

{
"mapping": {
"wafsecuritylog": {
"attack_type": {
"type": "keyword"
},
"dst_ip": {
"type": "keyword"
}
}
}
}
}

以上是我的map结构,我想实现统计dst_ip这个字段前10的数据,然后根据前10查出来的内容再统计出这个内容的attack_type前10的数据,有办法做到吗?
 
{
"aggs": {
"dst_ip_aggs": {
"terms": { "field": "dst_ip" }
}
}
, "size": 0
}
以上查询只能查出dst_ip的数据,查询结果如下:
"buckets" : [
{
"key" : "172.25.1.111",
"doc_count" : 7839
},
{
"key" : "192.168.90.50",
"doc_count" : 6576
},
{
"key" : "-",
"doc_count" : 1690
}
]
,如何再根据出来的结果里的Key查attack_type的统计?
已邀请:

a2dou

赞同来自: hel2o

{
  "aggs": {
    "dst_ip_aggs": {
      "terms": {
        "field": "dst_ip"
      },
      "aggs": {
        "attack_type_aggs": {
          "terms": {
            "field":"attack_type"
          }
        }
      }
    }
  },
  "size": 0
}

要回复问题请先登录注册