# How to filter unique value in REST API

**URL:** <https://discuss.elastic.co/t/how-to-filter-unique-value-in-rest-api/119573>\
**Category:** Elasticsearch\
**Created:** [February 13, 2018, 4:18am UTC](https://discuss.elastic.co/t/how-to-filter-unique-value-in-rest-api/119573 "2018-02-13T04:18:02Z")\
**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:** [February 13, 2018, 4:18am UTC](https://discuss.elastic.co/t/how-to-filter-unique-value-in-rest-api/119573/1 "2018-02-13T04:18:03Z")

</div>

I want to filter unique IP regardless it's in DST\_Local\_IP or in SRC\_Local\_IP.  
this is my REST API:

```
GET /_search
  {
  "size" : 0,
  "query": {
    "bool": {
      "should": [
        {
            "match":{"IPV4_DST_ADDR":"120.127.0.0/16"}
        },
        {
            "match":{"IPV4_SRC_ADDR":"120.127.0.0/16"}
        },
        {
          "range" : {
            "LAST_SWITCHED" : {
                "gte" : 0
             }
          }
        }
      ],
      "minimum_should_match": 2
    }
  },
    "aggs": {
      "DST_Local_IP": {
      "filter": {
        "bool": {
          "filter": {
              "match":{"IPV4_DST_ADDR":"120.127.0.0/16"}
            }
          }
        },
      "aggs": {
         "dst_local_ip" : {
             "terms" : {
                 "field" : "IPV4_DST_ADDR",
                 "size": 10000
              }
            }
         }
      }, 
      "SRC_Local_IP": {
      "filter": {
        "bool": {
          "filter": {
              "match":{"IPV4_SRC_ADDR":"120.127.0.0/16"}
            }
          }
        },
      "aggs": {
         "src_local_ip" : {
             "terms" : {
                 "field" : "IPV4_SRC_ADDR",
                 "size": 10000
              }
            }
         }
      }
   }
}

```

I want the return value is distinct because the ip in DST\_Local\_IP may be in SRC\_Local\_IP duplicated, but I just want the unique ip regardless the ip is in DST\_Local\_IP or SRC\_Local\_IP.

How can I do?could you give me some idea:）

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:** [March 13, 2018, 4:18am UTC](https://discuss.elastic.co/t/how-to-filter-unique-value-in-rest-api/119573/2 "2018-03-13T04:18:12Z")

</div>

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