# Key\_script for histogram using java

**URL:** <https://discuss.elastic.co/t/key-script-for-histogram-using-java/9377>\
**Category:** Elasticsearch\
**Created:** [October 16, 2012, 11:11am UTC](https://discuss.elastic.co/t/key-script-for-histogram-using-java/9377 "2012-10-16T11:11:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deny\_H](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@Deny\_H](https://discuss.elastic.co/u/Deny_H)\
**Post date:** [October 16, 2012, 11:11am UTC](https://discuss.elastic.co/t/key-script-for-histogram-using-java/9377/1 "2012-10-16T11:11:01Z")

</div>

Hello, everyone.

I am quite new with elasticsearch, but it is quite an interesting tool to  
work with, indeed.

However, I encountered the following problem : I had to build a facet that  
would tell me the number of docs indexed in the hours 0-2, 2-4, ... 22-24,  
no matter the date.  
I have a date field for this purpose.  
I was able to find a way to do it in another thread, using an histogram  
facet assorted with a key\_script and a value\_script. And that works great  
with mobz.  
My problem is that I must do it using the Java API, and I can't seem to  
find a way to do it.  
I can find a method to set a value\_script, but nothing to set a key\_script.  
Is it even possible?

Thanks.  
Deny

--

---

<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, 3:08am UTC](https://discuss.elastic.co/t/key-script-for-histogram-using-java/9377/2 "2017-07-06T03:08:34Z")

</div>


