# Scripted histogram facets

**URL:** <https://discuss.elastic.co/t/scripted-histogram-facets/21033>\
**Category:** Elasticsearch\
**Created:** [December 2, 2014, 1:49pm UTC](https://discuss.elastic.co/t/scripted-histogram-facets/21033 "2014-12-02T13:49:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DH1](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@DH1](https://discuss.elastic.co/u/DH1)\
**Post date:** [December 2, 2014, 1:49pm UTC](https://discuss.elastic.co/t/scripted-histogram-facets/21033/1 "2014-12-02T13:49:40Z")

</div>

Hi everyone,

I'm trying to figure out how to do an histogram facet :

{  
"query" : {  
"match\_all" : {}  
},  
"facets" : {  
"histo1" : {  
"histogram" : {  
"field" : "field\_name",  
"interval" : 100  
}  
}  
}  
}

where the field is, in fact, the substraction of two fields.

I have a native script that works wonder for a terms facet, but I can't  
seem to find how I should apply it for an Histogram facet.  
A terms facet return too many differentes results.

I could, In the native script, create the buckets myself and use a tems  
facet anyway (thus mimicking an histogram), but it seems an ugly way to  
achieve what I want (and maybe a bit expensive..I think).

I'd prefer using an Histogram facet, as that's what they are here for.

Is it possible? Did I miss something?

Any infos on the matter would be tremendously useful.  
Thanks.

--  
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/422de6b5-fd32-4d31-8619-dd969f943cb9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/422de6b5-fd32-4d31-8619-dd969f943cb9%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:** [December 3, 2014, 1:36pm UTC](https://discuss.elastic.co/t/scripted-histogram-facets/21033/2 "2014-12-03T13:36:30Z")

</div>

I don't know much about facets, but the new histogram aggregation supports  
scripts, maybe you can try it out?

On Tue, Dec 2, 2014 at 2:49 PM, DH [ciddp195@gmail.com](mailto:ciddp195@gmail.com) wrote:

> Hi everyone,
> 
> I'm trying to figure out how to do an histogram facet :
> 
> {  
> "query" : {  
> "match\_all" : {}  
> },  
> "facets" : {  
> "histo1" : {  
> "histogram" : {  
> "field" : "field\_name",  
> "interval" : 100  
> }  
> }  
> }  
> }
> 
> where the field is, in fact, the substraction of two fields.
> 
> I have a native script that works wonder for a terms facet, but I can't  
> seem to find how I should apply it for an Histogram facet.  
> A terms facet return too many differentes results.
> 
> I could, In the native script, create the buckets myself and use a tems  
> facet anyway (thus mimicking an histogram), but it seems an ugly way to  
> achieve what I want (and maybe a bit expensive..I think).
> 
> I'd prefer using an Histogram facet, as that's what they are here for.
> 
> Is it possible? Did I miss something?
> 
> Any infos on the matter would be tremendously useful.  
> Thanks.
> 
> --  
> 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/422de6b5-fd32-4d31-8619-dd969f943cb9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/422de6b5-fd32-4d31-8619-dd969f943cb9%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/422de6b5-fd32-4d31-8619-dd969f943cb9%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/422de6b5-fd32-4d31-8619-dd969f943cb9%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/CAL6Z4j5fcKSUOq%3Dsi4zv\_%2Bi4g%3DwF93w1r7heb1YiyqD\_qxmncQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5fcKSUOq%3Dsi4zv_%2Bi4g%3DwF93w1r7heb1YiyqD_qxmncQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![DH1](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@DH1](https://discuss.elastic.co/u/DH1)\
**Post date:** [December 3, 2014, 1:54pm UTC](https://discuss.elastic.co/t/scripted-histogram-facets/21033/3 "2014-12-03T13:54:30Z")

</div>

Hi, and thanks for the reply.

I should have said that, for reasons I (sadly) have no power over, I'm  
stuck with ES v0.90.5, and thus don't get to use those impressives  
aggregations.  
I'm beginnig to think that the only way of doing what I want is indeed  
using a native script that will carve my buckets for me.  
Thanks, anyway !

Le mardi 2 décembre 2014 14:49:40 UTC+1, DH a écrit :

> Hi everyone,
> 
> I'm trying to figure out how to do an histogram facet :
> 
> {  
> "query" : {  
> "match\_all" : {}  
> },  
> "facets" : {  
> "histo1" : {  
> "histogram" : {  
> "field" : "field\_name",  
> "interval" : 100  
> }  
> }  
> }  
> }
> 
> where the field is, in fact, the substraction of two fields.
> 
> I have a native script that works wonder for a terms facet, but I can't  
> seem to find how I should apply it for an Histogram facet.  
> A terms facet return too many differentes results.
> 
> I could, In the native script, create the buckets myself and use a tems  
> facet anyway (thus mimicking an histogram), but it seems an ugly way to  
> achieve what I want (and maybe a bit expensive..I think).
> 
> I'd prefer using an Histogram facet, as that's what they are here for.
> 
> Is it possible? Did I miss something?
> 
> Any infos on the matter would be tremendously useful.  
> Thanks.

--  
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/261641b7-e7a3-411d-b055-ce4f66b1008b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/261641b7-e7a3-411d-b055-ce4f66b1008b%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, 12:46am UTC](https://discuss.elastic.co/t/scripted-histogram-facets/21033/4 "2017-07-06T00:46:13Z")

</div>


