# Kibana range agg. show wired result

**URL:** https://discuss.elastic.co/t/kibana-range-agg-show-wired-result/160052
**Category:** Kibana
**Created:** [December 9, 2018, 2:57pm UTC](https://discuss.elastic.co/t/kibana-range-agg-show-wired-result/160052 "2018-12-09T14:57:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Hyojoung\_Shin](https://avatars.discourse-cdn.com/v4/letter/h/6a8cbe/32.png) [@Hyojoung\_Shin](https://discuss.elastic.co/u/Hyojoung_Shin)
#### Post date: [December 9, 2018, 2:57pm UTC](https://discuss.elastic.co/t/kibana-range-agg-show-wired-result/160052/1 "2018-12-09T14:57:44Z")

</div>

Hi!  
I used sample data(kibana\_sample\_data\_ecommerce) to study functions.

Range query agg. shows something wired result and I could not understand it.

I hope someone gives me a clue to understand result.

Total number of documents is 4,675.  
When I apply range agg. total number of documents is 4,672+275 which is exceed 4,675.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/8/b82730f48c2d4cef09fd98b50c5fff1efda65fc2.png)

![image](https://us1.discourse-cdn.com/elastic/original/3X/c/5/c51e0981f68cea3730c3a024e784600ec71e7236.png)

Here is request and result.

**request**

```auto
{
  "aggs": {
    "2": {
      "range": {
        "field": "products.base_price",
        "ranges": [
          {
            "from": 0,
            "to": 100
          },
          {
            "from": 100,
            "to": 400
          }
        ],
        "keyed": true
      }
    }
  },
  "size": 0,
  "_source": {
    "excludes": []
  },
  "stored_fields": [
    "*"
  ],
  "script_fields": {},
  "docvalue_fields": [
    {
      "field": "customer_birth_date",
      "format": "date_time"
    },
    {
      "field": "order_date",
      "format": "date_time"
    },
    {
      "field": "products.created_on",
      "format": "date_time"
    }
  ],
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        },
        {
          "range": {
            "order_date": {
              "gte": 1514732400000,
              "lte": 1546268399999,
              "format": "epoch_millis"
            }
          }
        }
      ],
      "filter": [],
      "should": [],
      "must_not": []
    }
  }
}

```

**result**

```auto
{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 4675,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "2": {
      "buckets": {
        "0.0-100.0": {
          "from": 0,
          "to": 100,
          "doc_count": 4672
        },
        "100.0-400.0": {
          "from": 100,
          "to": 400,
          "doc_count": 275
        }
      }
    }
  },
  "status": 200
}

```

I could not understand the result. total hits is 4675 but sum of agg. bucket is exceed total hits.  
Is it right behavior of range agg.?

Thanks.  
HJ Shin.

---

<div class="post-metadata">

### Author: ![bryan\_stuhlsatz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bryan_stuhlsatz/32/49123_2.png) [@bryan\_stuhlsatz](https://discuss.elastic.co/u/bryan_stuhlsatz)
#### Post date: [December 9, 2018, 5:45pm UTC](https://discuss.elastic.co/t/kibana-range-agg-show-wired-result/160052/2 "2018-12-09T17:45:39Z")

</div>

This is expected. You are making an assumption that each record contains 1 item purchased. Not the case. Some documents contain multiple items (purchases). So your range query is picking up multiple documents. You can have a high priced item and a low priced item show up in the same document, and therefore be counted in your low range and higher range. To prove, change your range from 0-10,000 dollars. You now have a complete document set because all the docs fall into that price range.

Make sense?

---

<div class="post-metadata">

### Author: ![Hyojoung\_Shin](https://avatars.discourse-cdn.com/v4/letter/h/6a8cbe/32.png) [@Hyojoung\_Shin](https://discuss.elastic.co/u/Hyojoung_Shin)
#### Post date: [December 10, 2018, 4:04am UTC](https://discuss.elastic.co/t/kibana-range-agg-show-wired-result/160052/3 "2018-12-10T04:04:17Z")

</div>

Thanks Bryan!

You gave me a very clear answer.

Thank you so much.

---

<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: [January 7, 2019, 4:04am UTC](https://discuss.elastic.co/t/kibana-range-agg-show-wired-result/160052/4 "2019-01-07T04:04:23Z")

</div>

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