# Aggregations for dynamic key value pairs

**URL:** <https://discuss.elastic.co/t/aggregations-for-dynamic-key-value-pairs/200083>\
**Category:** Elasticsearch\
**Created:** [September 18, 2019, 7:51pm UTC](https://discuss.elastic.co/t/aggregations-for-dynamic-key-value-pairs/200083 "2019-09-18T19:51:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkdavis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bkdavis/32/54439_2.png) [@bkdavis](https://discuss.elastic.co/u/bkdavis)\
**Post date:** [September 18, 2019, 7:51pm UTC](https://discuss.elastic.co/t/aggregations-for-dynamic-key-value-pairs/200083/1 "2019-09-18T19:51:19Z")

</div>

Trying to figure out the best way to 'count' values for aggregating dynamic data.

For instance the 2 records below is a sampling of data where 'key' data is not static. Some records may have height:21 and width:28 while others may have input\_position:20.55 and output\_diameter:22.04 and so on. There is an endless number of key value pairs that could require the aggregations.

**SAMPLE DATA**  
{  
"\_index" : "catalog\_seats3",  
"\_type" : "\_doc",  
"\_id" : "16",  
"\_score" : 1.3362663,  
"\_source" : {  
"item\_number" : "sy1236239",  
"description" : "black cloth forklift seat with book box",  
"make" : "ub40",  
"attributes" : {  
"height" : "21",  
"width" : "28"  
"options" : [  
"cloth",  
"seat switch",  
"seat belt"  
]  
}  
},  
{  
"\_index" : "catalog\_seats3",  
"\_type" : "\_doc",  
"\_id" : "4",  
"\_score" : 1.2968898,  
"\_source" : {  
"item\_number" : "sy91825",  
"description" : "black vinyl forklift seat",  
"make" : "grammer",  
"attributes" : {  
"input\_position" : "20.55",  
"output\_diameter" : "22.04"  
"options" : [  
"vinyl",  
"seat adjusters",  
"seat tilt",  
"book box"  
]  
}  
},

Ultimately I would like to have something like buckets that count like this...

**height**  
-key:21  
-count:5

-key:23.5  
-count:12

**width**  
-key:28  
-count:17

-key:27.5  
-count:6

**input\_position**  
-key:20.55  
-count:3

-key:22  
-count:15

**output\_diameter**  
-key:22.04  
-count:3

-key:21  
-count:16

Any help would be very much appreciated. Even if you could point me in the right direction.

Thank you

---

<div class="post-metadata">

**Author:** ![bkdavis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bkdavis/32/54439_2.png) [@bkdavis](https://discuss.elastic.co/u/bkdavis)\
**Post date:** [September 20, 2019, 6:47pm UTC](https://discuss.elastic.co/t/aggregations-for-dynamic-key-value-pairs/200083/2 "2019-09-20T18:47:20Z")

</div>

I think I figured out the best approach by following recommendations in this post..

[https://discuss.elastic.co/t/aggregate-over-multiple-keys-in-the-document-without-knowing-the-key-details/158238](https://discuss.elastic.co/t/aggregate-over-multiple-keys-in-the-document-without-knowing-the-key-details/158238)

Thank you!

---

<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:** [October 18, 2019, 6:58pm UTC](https://discuss.elastic.co/t/aggregations-for-dynamic-key-value-pairs/200083/3 "2019-10-18T18:58:18Z")

</div>

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