# Aggregation problem

**URL:** https://discuss.elastic.co/t/aggregation-problem/17303
**Category:** Elasticsearch
**Created:** [May 1, 2014, 4:37pm UTC](https://discuss.elastic.co/t/aggregation-problem/17303 "2014-05-01T16:37:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Niv\_Penso](https://avatars.discourse-cdn.com/v4/letter/n/b487fb/32.png) [@Niv\_Penso](https://discuss.elastic.co/u/Niv_Penso)
#### Post date: [May 1, 2014, 4:37pm UTC](https://discuss.elastic.co/t/aggregation-problem/17303/1 "2014-05-01T16:37:40Z")

</div>

Hey guys,

I have this mapping:

GET ckdocuments/msv/\_mapping

{  
"ckdocuments": {  
"mappings": {  
"msv": {  
"properties": {  
"MSV": {  
"properties": {  
"country": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"date": {  
"type": "date",  
"format": "YYYY-MM-dd HH:mm:ss"  
},  
"hits": {  
"type": "nested",  
"properties": {  
"click\_type": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
}  
}  
},  
"c": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"doc\_creation\_time": {  
"type": "date",  
"format": "YYYY-MM-dd HH:mm:ss"  
},  
"views": {  
"properties": {  
"country": {  
"type": "string"  
},  
"date": {  
"type": "date",  
"format": "YYYY-MM-dd HH:mm:ss"  
},  
"hits": {  
"properties": {  
"click\_type": {  
"type": "string"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}

Wih these three docs:

PUT ckdocuments/msv/1  
{  
"c":"a",  
"MSV" :  
[  
{  
"country" : "US",  
"date" : "2013-01-01 00:00:00",  
"hits" : [  
{  
"click\_type" : "click"  
}  
]  
}  
],  
"views":[  
{  
"country" : "US",  
"date" : "2013-01-01 00:00:00",  
"hits" : [  
{  
"click\_type" : "click"  
}  
]  
},  
{  
"country" : "IL",  
"date" : "2013-01-01 00:00:00",  
"hits" : [  
{  
"click\_type" : "click"  
}  
]  
}  
]  
}

PUT ckdocuments/msv/2  
{  
"doc\_creation\_time" : "2013-01-01 00:00:00",  
"MSV" :  
[  
{  
"country" : "IL",  
"date" : "2013-01-01 00:00:00",  
"hits" : [  
{  
"click\_type" : "pixel"  
}  
]  
},  
{  
"country" : "US",  
"date" : "2013-01-02 00:00:00",  
"hits" : [  
{  
"click\_type" : "click"  
}  
]  
}  
],  
"views":[  
{  
"country" : "US",  
"date" : "2013-01-01 00:00:00",  
"hits" : []  
},  
{  
"country" : "US",  
"date" : "2013-01-01 00:00:00",  
"hits" : [  
{  
"click\_type" : "pixel"  
},  
{  
"click\_type" : "pixel"  
}  
]  
},  
{  
"country" : "US",  
"date" : "2013-01-02 00:00:00",  
"hits" : [  
{  
"click\_type" : "click"  
}  
]  
}  
]  
}

PUT ckdocuments/msv/3  
{  
"MSV" :  
[  
{  
"country" : "IL",  
"date" : "2013-01-01 00:00:00",  
"hits" : [  
{  
"click\_type" : "click"  
}  
]  
}  
],  
"views":[  
{  
"country" : "US",  
"date" : "2013-01-01 00:00:00",  
"hits" : [  
{  
"click\_type" : "click"  
}  
]  
},  
{  
"country" : "IL",  
"date" : "2013-01-01 00:00:00",  
"hits" : [  
{  
"click\_type" : "click"  
}  
]  
}  
]  
}

When I run:

GET /ckdocuments/msv/\_search  
{  
"aggregations": {  
"MSV":{  
"aggs":{  
"terms":{  
"field" : "MSV.country"  
}  
}  
}  
},  
"size":0  
}  
}

I get these results:

{  
"took": 1,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 3,  
"max\_score": 0,  
"hits": []  
}  
}

I just can't understand why the aggregation sperate the results to  
countries..  
Do you have any idea?

Thnx Niv

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/b928cd7b-042a-435d-9839-ef2bd1cc74fa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b928cd7b-042a-435d-9839-ef2bd1cc74fa%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [May 1, 2014, 8:19pm UTC](https://discuss.elastic.co/t/aggregation-problem/17303/2 "2014-05-01T20:19:56Z")

</div>

Hi,

Your request is not valid, it should be

GET /ckdocuments/msv/\_search  
{  
"aggregations": {  
"MSV":{  
"terms":{  
"field" : "MSV.country"  
}  
}  
},  
"size":0  
}  
}

The next release of Elasticsearch will be less resilient to malformed  
aggregations, so you will hopefully get an error instead of just getting  
empty aggregations.

On Thu, May 1, 2014 at 6:37 PM, Niv Penso [nivp@toonimo.com](mailto:nivp@toonimo.com) wrote:

> Hey guys,
> 
> I have this mapping:
> 
> GET ckdocuments/msv/\_mapping
> 
> {  
> "ckdocuments": {  
> "mappings": {  
> "msv": {  
> "properties": {  
> "MSV": {  
> "properties": {  
> "country": {  
> "type": "string",  
> "index": "not\_analyzed"  
> },  
> "date": {  
> "type": "date",  
> "format": "YYYY-MM-dd HH:mm:ss"  
> },  
> "hits": {  
> "type": "nested",  
> "properties": {  
> "click\_type": {  
> "type": "string",  
> "index": "not\_analyzed"  
> }  
> }  
> }  
> }  
> },  
> "c": {  
> "type": "string",  
> "index": "not\_analyzed"  
> },  
> "doc\_creation\_time": {  
> "type": "date",  
> "format": "YYYY-MM-dd HH:mm:ss"  
> },  
> "views": {  
> "properties": {  
> "country": {  
> "type": "string"  
> },  
> "date": {  
> "type": "date",  
> "format": "YYYY-MM-dd HH:mm:ss"  
> },  
> "hits": {  
> "properties": {  
> "click\_type": {  
> "type": "string"  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }
> 
> Wih these three docs:
> 
> PUT ckdocuments/msv/1  
> {  
> "c":"a",  
> "MSV" :  
> [  
> {  
> "country" : "US",  
> "date" : "2013-01-01 00:00:00",  
> "hits" : [  
> {  
> "click\_type" : "click"  
> }  
> ]  
> }  
> ],  
> "views":[  
> {  
> "country" : "US",  
> "date" : "2013-01-01 00:00:00",  
> "hits" : [  
> {  
> "click\_type" : "click"  
> }  
> ]  
> },  
> {  
> "country" : "IL",  
> "date" : "2013-01-01 00:00:00",  
> "hits" : [  
> {  
> "click\_type" : "click"  
> }  
> ]  
> }  
> ]  
> }
> 
> PUT ckdocuments/msv/2  
> {  
> "doc\_creation\_time" : "2013-01-01 00:00:00",  
> "MSV" :  
> [  
> {  
> "country" : "IL",  
> "date" : "2013-01-01 00:00:00",  
> "hits" : [  
> {  
> "click\_type" : "pixel"  
> }  
> ]  
> },  
> {  
> "country" : "US",  
> "date" : "2013-01-02 00:00:00",  
> "hits" : [  
> {  
> "click\_type" : "click"  
> }  
> ]  
> }  
> ],  
> "views":[  
> {  
> "country" : "US",  
> "date" : "2013-01-01 00:00:00",  
> "hits" :   
> },  
> {  
> "country" : "US",  
> "date" : "2013-01-01 00:00:00",  
> "hits" : [  
> {  
> "click\_type" : "pixel"  
> },  
> {  
> "click\_type" : "pixel"  
> }  
> ]  
> },  
> {  
> "country" : "US",  
> "date" : "2013-01-02 00:00:00",  
> "hits" : [  
> {  
> "click\_type" : "click"  
> }  
> ]  
> }  
> ]  
> }
> 
> PUT ckdocuments/msv/3  
> {  
> "MSV" :  
> [  
> {  
> "country" : "IL",  
> "date" : "2013-01-01 00:00:00",  
> "hits" : [  
> {  
> "click\_type" : "click"  
> }  
> ]  
> }  
> ],  
> "views":[  
> {  
> "country" : "US",  
> "date" : "2013-01-01 00:00:00",  
> "hits" : [  
> {  
> "click\_type" : "click"  
> }  
> ]  
> },  
> {  
> "country" : "IL",  
> "date" : "2013-01-01 00:00:00",  
> "hits" : [  
> {  
> "click\_type" : "click"  
> }  
> ]  
> }  
> ]  
> }
> 
> When I run:
> 
> GET /ckdocuments/msv/\_search  
> {  
> "aggregations": {  
> "MSV":{  
> "aggs":{  
> "terms":{  
> "field" : "MSV.country"  
> }  
> }  
> }  
> },  
> "size":0  
> }  
> }
> 
> I get these results:
> 
> {  
> "took": 1,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 5,  
> "successful": 5,  
> "failed": 0  
> },  
> "hits": {  
> "total": 3,  
> "max\_score": 0,  
> "hits":   
> }  
> }
> 
> I just can't understand why the aggregation sperate the results to  
> countries..  
> Do you have any idea?
> 
> Thnx Niv
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/b928cd7b-042a-435d-9839-ef2bd1cc74fa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b928cd7b-042a-435d-9839-ef2bd1cc74fa%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/b928cd7b-042a-435d-9839-ef2bd1cc74fa%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/b928cd7b-042a-435d-9839-ef2bd1cc74fa%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5tftHAOQ9AKZLobdrrwRHEeQV-yVEJ1Q\_5aTJt29Akig%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5tftHAOQ9AKZLobdrrwRHEeQV-yVEJ1Q_5aTJt29Akig%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [July 6, 2017, 1:32am UTC](https://discuss.elastic.co/t/aggregation-problem/17303/3 "2017-07-06T01:32:15Z")

</div>


