# Migrating From Facets to Aggregations (Both Key & Value Scripts)

**URL:** <https://discuss.elastic.co/t/migrating-from-facets-to-aggregations-both-key-value-scripts/18741>\
**Category:** Elasticsearch\
**Created:** [July 18, 2014, 3:23pm UTC](https://discuss.elastic.co/t/migrating-from-facets-to-aggregations-both-key-value-scripts/18741 "2014-07-18T15:23:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nariman\_Haghighi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nariman_haghighi/32/1065_2.png) [@Nariman\_Haghighi](https://discuss.elastic.co/u/Nariman_Haghighi)\
**Post date:** [July 18, 2014, 3:23pm UTC](https://discuss.elastic.co/t/migrating-from-facets-to-aggregations-both-key-value-scripts/18741/1 "2014-07-18T15:23:49Z")

</div>

Facets supported both key\_script and value\_script in this manner:  
{  
"size": 0,  
"facets": {  
"by-hour": {  
"histogram": {  
"key\_script": "doc['media.created\_time'].date.hourOfDay",  
"value\_script": "doc['media.likes.count'].value +  
doc['media.comments.count'].value"  
}  
}  
},  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"stream\_id": {  
"value": "1b883b7b-364b-4b5d-b099-9e7ef329a445"  
}  
}  
}  
]  
}  
}  
}

What's the equivalent of this for aggregations under 1.2.2.?

--  
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/fb3df9e3-2a96-4b94-8247-1c6f896c455f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fb3df9e3-2a96-4b94-8247-1c6f896c455f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![ElasticSearch\_Users\_](https://avatars.discourse-cdn.com/v4/letter/e/b4bc9f/32.png) [@ElasticSearch\_Users\_](https://discuss.elastic.co/u/ElasticSearch_Users_)\
**Post date:** [July 19, 2014, 2:14am UTC](https://discuss.elastic.co/t/migrating-from-facets-to-aggregations-both-key-value-scripts/18741/2 "2014-07-19T02:14:32Z")

</div>

The equivalent would likely be a terms agg on the key\_script expression  
(using the terms agg script capability), and then followed by a nested  
stats agg on the value\_script expression (using the stats agg script  
capability). Something like this:

"aggs": {  
"by-hour": {  
"terms": {  
"script": "doc['media.created\_time'].date.hourOfDay"  
},  
"aggs": {  
"bytes\_stats": {  
"stats": {  
"script": "doc['media.likes.count'].value +  
doc['media.comments.count'].value"  
}  
}  
}  
}  
}

--  
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/7d285a99-84f0-430b-a86d-1365cc05e13f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7d285a99-84f0-430b-a86d-1365cc05e13f%40googlegroups.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:14am UTC](https://discuss.elastic.co/t/migrating-from-facets-to-aggregations-both-key-value-scripts/18741/3 "2017-07-06T01:14:48Z")

</div>

Closed on July 6, 2017, 1:14am UTC


