I want to aggregate my documents over the different keys in the field "categories". Here are two documents:
"date": 1470271301,
"categories": {
"1": [blabla],
"2": [blala]
}
"date": 144343545,
"categories": {
"1": [blabla],
"2": [coco]
"3": [rat, saouth]
}
Mapping for categories:
"categories" : {
"properties" : {
"1" : {
"type" : "long"
And i want get something like this:
"buckets" : [ {
"key" : "1",
"doc_count" : 2
}, {
"key" : "2",
"doc_count" : 2
{
"key" : "3",
"doc_count" : 1
}
Is there a good way to do this whithout changing the mapping of my documents?
One could use the meta-field _field_names for this purpose.
Running aggregate on this as shown in the example below would give you the document count.
Example :
Result :