# API call to find frequency of occurrence of values of a given field

**URL:** <https://discuss.elastic.co/t/api-call-to-find-frequency-of-occurrence-of-values-of-a-given-field/154836>\
**Category:** Logstash\
**Created:** [October 31, 2018, 12:13pm UTC](https://discuss.elastic.co/t/api-call-to-find-frequency-of-occurrence-of-values-of-a-given-field/154836 "2018-10-31T12:13:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GitSpree23](https://avatars.discourse-cdn.com/v4/letter/g/65b543/32.png) [@GitSpree23](https://discuss.elastic.co/u/GitSpree23)\
**Post date:** [October 31, 2018, 12:13pm UTC](https://discuss.elastic.co/t/api-call-to-find-frequency-of-occurrence-of-values-of-a-given-field/154836/1 "2018-10-31T12:13:21Z")

</div>

My index contains the "IP" field. While there are ~4000 records in my index, there are only ~10 unique IPs in it. I want an API call which will return the frequency of occurrence of each IP in the index.

I have developed a visualization for the same, but I need the API call too.

 ![Screenshot%20(219)](https://us1.discourse-cdn.com/elastic/original/3X/0/0/00c4d176eb9404e3a82979b44b8c0dddf5ab154d.png)

Also, is there a way to extract API calls used in the visualizations?

---

<div class="post-metadata">

**Author:** ![GitSpree23](https://avatars.discourse-cdn.com/v4/letter/g/65b543/32.png) [@GitSpree23](https://discuss.elastic.co/u/GitSpree23)\
**Post date:** [October 31, 2018, 1:19pm UTC](https://discuss.elastic.co/t/api-call-to-find-frequency-of-occurrence-of-values-of-a-given-field/154836/2 "2018-10-31T13:19:46Z")

</div>

Here's a solution I've tried.

```
GET /trial23/_search
{
  "aggs": {
    "path_count": {
      "terms": {
        "field": "path.keyword",
        "size": 35
      }
    }
  },
  "size": 0
}

```

The output is like:

```
{
  "took": 247,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 47673976,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "path_count": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 103,
      "buckets": [
        {
          "key": "/home/xyz/data/day=2018-09-20/hour=13/abc_000000_0.gz",
          "doc_count": 8166850
        },
        {
          "key": "/home/xyz/data/day=2018-09-20/hour=13/abc_6713_000002_0.gz",
          "doc_count": 8162160
        },
...

```

But I want to remove the initial fields like took, timed\_out etc., and only keep the buckets field.  
Any suggestions?

---

<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:** [November 28, 2018, 1:19pm UTC](https://discuss.elastic.co/t/api-call-to-find-frequency-of-occurrence-of-values-of-a-given-field/154836/3 "2018-11-28T13:19:56Z")

</div>

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