# How to filter document count?

**URL:** <https://discuss.elastic.co/t/how-to-filter-document-count/140245>\
**Category:** Elasticsearch\
**Created:** [July 17, 2018, 4:53am UTC](https://discuss.elastic.co/t/how-to-filter-document-count/140245 "2018-07-17T04:53:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![f26227279](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/f26227279/32/21296_2.png) [@f26227279](https://discuss.elastic.co/u/f26227279)\
**Post date:** [July 17, 2018, 4:53am UTC](https://discuss.elastic.co/t/how-to-filter-document-count/140245/1 "2018-07-17T04:53:35Z")

</div>

Hi, I want to filter document count. If there's an IP which document count doesn't exceed 10 then I want to filter it out.  
my REST API query:

```
GET /_search
  {
  "size" : 0,
  "query": {
    "bool": {
      "should": [
        {
            "match":{"IPV4_DST_ADDR":"192.168.0.0/16"}
        },
        {
            "match":{"IPV4_SRC_ADDR":"192.168.0.0/16"}
        },
        {
          "range":{
            "@timestamp":{
            "gte":"2017-10-20T11:00:00",
            "lt":"now"
            }
          }
        }
      ],
      "minimum_should_match": 2
    }
  },
    "aggs": {
      "DST_Local_IP": {
      "filter": {
        "bool": {
          "filter": {
              "match":{"IPV4_DST_ADDR":"192.168.0.0/16"}
            }
          }
        },
      "aggs": {
         "dst_local_ip" : {
             "terms" : {
                 "field" : "IPV4_DST_ADDR",
                 "size": 100000
              }
            }
         }
      }, 
      "SRC_Local_IP": {
      "filter": {
        "bool": {
          "filter": {
              "match":{"IPV4_SRC_ADDR":"192.168.0.0/16"}
            }
          }
        },
      "aggs": {
         "src_local_ip" : {
             "terms" : {
                 "field" : "IPV4_SRC_ADDR",
                 "size": 100000
              }
            }
         }
      }
   }
}

```

thank you in advance!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 14, 2018, 5:14am UTC](https://discuss.elastic.co/t/how-to-filter-document-count/140245/3 "2018-08-14T05:14:33Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
