# Aggregation document count issue

**URL:** <https://discuss.elastic.co/t/aggregation-document-count-issue/141031>\
**Category:** Elasticsearch\
**Created:** [July 22, 2018, 12:21pm UTC](https://discuss.elastic.co/t/aggregation-document-count-issue/141031 "2018-07-22T12:21:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kushal\_Goyal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kushal_goyal/32/33609_2.png) [@Kushal\_Goyal](https://discuss.elastic.co/u/Kushal_Goyal)\
**Post date:** [July 22, 2018, 12:21pm UTC](https://discuss.elastic.co/t/aggregation-document-count-issue/141031/1 "2018-07-22T12:21:35Z")

</div>

Hi

I am new in ELK stack, need your advice.

I am using nested aggregation.

GET account\_credit/person/\_search  
{  
"aggs": {  
"count\_by\_gender": {  
"terms": {  
"field": "creditcard\_number.keyword"

```
  },
  "aggs": {
    "ip_address": {
      "terms": {
        "field": "ip_address.keyword"
      }
    }
  }
}

```

}  
}

result is

{  
"key": "3555539887215424",  
"doc\_count": 3,  
"ip\_address": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets": [  
{  
"key": "6.202.255.220",  
"doc\_count": 3

but when I am using below DSL

GET account\_credit/person/\_search  
{

"query" : {

```
			"term" : {"creditcard_number.keyword":"3555539887215424"}
	
},
"sort": [
  {
    "ip_address.keyword": {
      "order": "desc"
    }
  }
]

```

}

response

{  
"took": 3,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 8,  
"max\_score": null,  
"hits": [  
{  
"\_index": "account\_credit",  
"\_type": "person",  
"\_id": "3jupwWQBCxMvYbonq5dD",  
"\_score": null,  
"\_source": {  
"id": 2000001,  
"first\_name": "Felicle",  
"last\_name": "Evitt",  
"email": "fevitt0@ustream.tv",  
"gender": "Female",  
"ip\_address": "75.73.29.197",  
"creditcard\_type": "switch",  
"creditcard\_number": "3555539887215424",  
"balance": "96862289.14"  
},  
"sort": [  
"75.73.29.197"  
]  
},  
{  
"\_index": "account\_credit",  
"\_type": "person",  
"\_id": "B76hwWQBR\_kMIhVB6dfC",  
"\_score": null,  
"\_source": {  
"id": 1,  
"first\_name": "Felicle",  
"last\_name": "Evitt",  
"email": "fevitt0@ustream.tv",  
"gender": "Female",  
"ip\_address": "75.73.29.197",  
"creditcard\_type": "switch",  
"creditcard\_number": "3555539887215424",  
"balance": "96862289.14"  
},  
"sort": [  
"75.73.29.197"  
]  
},  
{  
"\_index": "account\_credit",  
"\_type": "person",  
"\_id": "Db6qwWQBR\_kMIhVBPtcE",  
"\_score": null,  
"\_source": {  
"id": 2000001,  
"first\_name": "Felicle",  
"last\_name": "Evitt",  
"email": "fevitt0@ustream.tv",  
"gender": "Female",  
"ip\_address": "75.73.21.197",  
"creditcard\_type": "switch",  
"creditcard\_number": "3555539887215424",  
"balance": "96862289.14"  
},  
"sort": [  
"75.73.21.197"  
]  
},  
{  
"\_index": "account\_credit",  
"\_type": "person",  
"\_id": "9TutwWQBCxMvYbonBpey",  
"\_score": null,  
"\_source": {  
"id": 222,  
"first\_name": "Felicle",  
"last\_name": "Evitt",  
"email": "fevitt0@ustream.tv",  
"gender": "Female",  
"ip\_address": "75.73.21.197",  
"creditcard\_type": "switch",  
"creditcard\_number": "3555539887215424",  
"balance": "96862289.14"  
},  
"sort": [  
"75.73.21.197"  
]  
},  
{  
"\_index": "account\_credit",  
"\_type": "person",  
"\_id": "-TutwWQBCxMvYbonZZfA",  
"\_score": null,  
"\_source": {  
"id": 222,  
"first\_name": "Felicle",  
"last\_name": "Evitt",  
"email": "fevitt0@ustream.tv",  
"gender": "Female",  
"ip\_address": "75.73.20.197",  
"creditcard\_type": "switch",  
"creditcard\_number": "3555539887215424",  
"balance": "96862289.14"  
},  
"sort": [  
"75.73.20.197"  
]  
},  
{  
"\_index": "account\_credit",  
"\_type": "person",  
"\_id": "pr7yjGQBR\_kMIhVBbaCL",  
"\_score": null,  
"\_source": {  
"id": 222,  
"first\_name": "Darryl",  
"last\_name": "Cabrales",  
"email": "dcabrales65@cafepress.com",  
"gender": "Male",  
"ip\_address": "6.202.255.220",  
"creditcard\_type": "jcb",  
"creditcard\_number": "3555539887215424",  
"balance": "7367624.70"  
},  
"sort": [  
"6.202.255.220"  
]  
},  
{  
"\_index": "account\_credit",  
"\_type": "person",  
"\_id": "6DuCwWQBCxMvYbonP4\_Y",  
"\_score": null,  
"\_source": {  
"id": 222,  
"first\_name": "Darryl",  
"last\_name": "Cabrales",  
"email": "dcabrales65@cafepress.com",  
"gender": "Male",  
"ip\_address": "6.202.255.220",  
"creditcard\_type": "visa",  
"creditcard\_number": "3555539887215424",  
"balance": "7367624.70"  
},  
"sort": [  
"6.202.255.220"  
]  
},  
{  
"\_index": "account\_credit",  
"\_type": "person",  
"\_id": "2DuDwWQBCxMvYboncpPM",  
"\_score": null,  
"\_source": {  
"id": 222,  
"first\_name": "Darryl",  
"last\_name": "Cabrales",  
"email": "dcabrales65@cafepress.com",  
"gender": "Male",  
"ip\_address": "6.202.255.220",  
"creditcard\_type": "visa",  
"creditcard\_number": "3555539887215424",  
"balance": "7367624.70"  
},  
"sort": [  
"6.202.255.220"  
]  
}  
]  
}  
}

why in aggregation I am not getting all ip address.

Please help on this

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 22, 2018, 12:41pm UTC](https://discuss.elastic.co/t/aggregation-document-count-issue/141031/2 "2018-07-22T12:41:23Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.  
Please update your post.

I'm not sure if the first result is truncated or not. Could you paste it entirely?

---

<div class="post-metadata">

**Author:** ![Kushal\_Goyal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kushal_goyal/32/33609_2.png) [@Kushal\_Goyal](https://discuss.elastic.co/u/Kushal_Goyal)\
**Post date:** [July 22, 2018, 1:02pm UTC](https://discuss.elastic.co/t/aggregation-document-count-issue/141031/3 "2018-07-22T13:02:47Z")

</div>

Hi

I am new in ELK stack, need your advice.

I am using nested aggregation.

```auto
  GET account_credit/person/_search
   { "aggs": { 
"count_by_gender": {
"terms": {
"field": "creditcard_number.keyword"
 },
 "aggs": {
   "ip_address": {
     "terms": {
       "field": "ip_address.keyword"
     }
   }
 }
}
}
}

```

result is

```auto
"key": "3555539887215424",
"doc_count": 3,
"ip_address": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "6.202.255.220",
"doc_count": 3

```

but when I am using below DSL

```auto

GET account_credit/person/_search
{

"query" : {

			"term" : {"creditcard_number.keyword":"3555539887215424"}
	
},
"sort": [
  {
    "ip_address.keyword": {
      "order": "desc"
    }
  }
]
}

```

response is

```auto
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 8,
"max_score": null,
"hits": [
{
"_index": "account_credit",
"_type": "person",
"_id": "3jupwWQBCxMvYbonq5dD",
"_score": null,
"_source": {
"id": 2000001,
"first_name": "Felicle",
"last_name": "Evitt",
"email": "fevitt0@ustream.tv",
"gender": "Female",
"ip_address": "75.73.29.197",
"creditcard_type": "switch",
"creditcard_number": "3555539887215424",
"balance": "96862289.14"
},
"sort": [
"75.73.29.197"
]
},
{
"_index": "account_credit",
"_type": "person",
"_id": "B76hwWQBR_kMIhVB6dfC",
"_score": null,
"_source": {
"id": 1,
"first_name": "Felicle",
"last_name": "Evitt",
"email": "fevitt0@ustream.tv",
"gender": "Female",
"ip_address": "75.73.29.197",
"creditcard_type": "switch",
"creditcard_number": "3555539887215424",
"balance": "96862289.14"
},
"sort": [
"75.73.29.197"
]
},
{
"_index": "account_credit",
"_type": "person",
"_id": "Db6qwWQBR_kMIhVBPtcE",
"_score": null,
"_source": {
"id": 2000001,
"first_name": "Felicle",
"last_name": "Evitt",
"email": "fevitt0@ustream.tv",
"gender": "Female",
"ip_address": "75.73.21.197",
"creditcard_type": "switch",
"creditcard_number": "3555539887215424",
"balance": "96862289.14"
},
"sort": [
"75.73.21.197"
]
},
{
"_index": "account_credit",
"_type": "person",
"_id": "9TutwWQBCxMvYbonBpey",
"_score": null,
"_source": {
"id": 222,
"first_name": "Felicle",
"last_name": "Evitt",
"email": "fevitt0@ustream.tv",
"gender": "Female",
"ip_address": "75.73.21.197",
"creditcard_type": "switch",
"creditcard_number": "3555539887215424",
"balance": "96862289.14"
},
"sort": [
"75.73.21.197"
]
},
{
"_index": "account_credit",
"_type": "person",
"_id": "-TutwWQBCxMvYbonZZfA",
"_score": null,
"_source": {
"id": 222,
"first_name": "Felicle",
"last_name": "Evitt",
"email": "fevitt0@ustream.tv",
"gender": "Female",
"ip_address": "75.73.20.197",
"creditcard_type": "switch",
"creditcard_number": "3555539887215424",
"balance": "96862289.14"
},
"sort": [
"75.73.20.197"
]
},
{
"_index": "account_credit",
"_type": "person",
"_id": "pr7yjGQBR_kMIhVBbaCL",
"_score": null,
"_source": {
"id": 222,
"first_name": "Darryl",
"last_name": "Cabrales",
"email": "dcabrales65@cafepress.com",
"gender": "Male",
"ip_address": "6.202.255.220",
"creditcard_type": "jcb",
"creditcard_number": "3555539887215424",
"balance": "7367624.70"
},
"sort": [
"6.202.255.220"
]
},
{
"_index": "account_credit",
"_type": "person",
"_id": "6DuCwWQBCxMvYbonP4_Y",
"_score": null,
"_source": {
"id": 222,
"first_name": "Darryl",
"last_name": "Cabrales",
"email": "dcabrales65@cafepress.com",
"gender": "Male",
"ip_address": "6.202.255.220",
"creditcard_type": "visa",
"creditcard_number": "3555539887215424",
"balance": "7367624.70"
},
"sort": [
"6.202.255.220"
]
},
{
"_index": "account_credit",
"_type": "person",
"_id": "2DuDwWQBCxMvYboncpPM",
"_score": null,
"_source": {
"id": 222,
"first_name": "Darryl",
"last_name": "Cabrales",
"email": "dcabrales65@cafepress.com",
"gender": "Male",
"ip_address": "6.202.255.220",
"creditcard_type": "visa",
"creditcard_number": "3555539887215424",
"balance": "7367624.70"
},
"sort": [
"6.202.255.220"
]
}
]
}
}

```

why in aggregation I am not getting all ip address count correctly.

Please help on this

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 22, 2018, 7:41pm UTC](https://discuss.elastic.co/t/aggregation-document-count-issue/141031/4 "2018-07-22T19:41:18Z")

</div>

Better. Sadly not well indented which makes it hard to read.

Anyway, could you answer the question I asked?

> I'm not sure if the first result is truncated or not. Could you paste it entirely?

---

<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 19, 2018, 7:41pm UTC](https://discuss.elastic.co/t/aggregation-document-count-issue/141031/5 "2018-08-19T19:41:27Z")

</div>

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