# Histogram facets with a query

**URL:** <https://discuss.elastic.co/t/histogram-facets-with-a-query/3087>\
**Category:** Elasticsearch\
**Created:** [July 12, 2010, 5:43am UTC](https://discuss.elastic.co/t/histogram-facets-with-a-query/3087 "2010-07-12T05:43:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Harvey\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_harvey_2/32/3328_2.png) [@Andrew\_Harvey\_2](https://discuss.elastic.co/u/Andrew_Harvey_2)\
**Post date:** [July 12, 2010, 5:43am UTC](https://discuss.elastic.co/t/histogram-facets-with-a-query/3087/1 "2010-07-12T05:43:14Z")

</div>

Hey there,

I've been playing around a little more with facets and I think I've come up against a limitation in the histogram facet. I'm looking to produce a histogram facet which has a query. Basically imagine the query facet and the histogram facet made sweet sweet love, then you'd have this.

Unless of course, I've missed the fact that this kind of facet already exists...

I've tried doing things like:

```
"facets": {
    "foo": {
        "histogram": {
            "time_interval": "24H",
            "key_field": "published",
            "query": {
                "query_string": {
                    "query": "foo"
                }
            }
        }
    } ,
    "bar": {
        "histogram": {
            "time_interval": "24H",
            "key_field": "published",
            "query": {
                "query_string": {
                    "query": "bar"
                }
            }
        }
    }
}

```

But to no avail. Have I just missed this feature, or should I open a bug for it?

I understand that I could do this using multiple requests, but that seems incredibly wasteful.

Any help would be much appreciated.

Andrew

## Andrew Harvey / Developer lexer m/ t/ +61 2 9019 6379 w/ [http://lexer.com.au](http://lexer.com.au) Help put an end to whaling. Visit [http://www.givewhalesavoice.com.au/](http://www.givewhalesavoice.com.au/)

Please consider the environment before printing this email  
This email transmission is confidential and intended solely for the person or organisation to whom it is addressed. If you are not the intended recipient, you must not copy, distribute or disseminate the information, or take any action in relation to it and please delete this e-mail. Any views expressed in this message are those of the individual sender, except where the send specifically states them to be the views of any organisation or employer. If you have received this message in error, do not open any attachment but please notify the sender (above). This message has been checked for all known viruses powered by McAfee.

For further information visit [http://www.mcafee.com/us/threat\_center/default.asp](http://www.mcafee.com/us/threat_center/default.asp)  
Please rely on your own virus check as no responsibility is taken by the sender for any damage rising out of any virus infection this communication may contain.

This message has been scanned for malware by Websense. [www.websense.com](http://www.websense.com)

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 12, 2010, 6:01pm UTC](https://discuss.elastic.co/t/histogram-facets-with-a-query/3087/2 "2010-07-12T18:01:50Z")

</div>

Can you explain a bit what you are trying to do exactly? There is no option  
in the histogram facet to provide a query, but you can provide a filter to  
further filter the hits the histogram (or any other facet) will run on. Is  
that what you are after?

-shay.banon

On Mon, Jul 12, 2010 at 8:43 AM, Andrew Harvey  
[Andrew.Harvey@lexer.com.au](mailto:Andrew.Harvey@lexer.com.au)wrote:

> Hey there,
> 
> I've been playing around a little more with facets and I think I've come up  
> against a limitation in the histogram facet. I'm looking to produce a  
> histogram facet which has a query. Basically imagine the query facet and the  
> histogram facet made sweet sweet love, then you'd have this.
> 
> Unless of course, I've missed the fact that this kind of facet already  
> exists...
> 
> I've tried doing things like:
> 
> "facets": {  
> "foo": {  
> "histogram": {  
> "time\_interval": "24H",  
> "key\_field": "published",  
> "query": {  
> "query\_string": {  
> "query": "foo"  
> }  
> }  
> }  
> } ,  
> "bar": {  
> "histogram": {  
> "time\_interval": "24H",  
> "key\_field": "published",  
> "query": {  
> "query\_string": {  
> "query": "bar"  
> }  
> }  
> }  
> }  
> }
> 
> But to no avail. Have I just missed this feature, or should I open a bug  
> for it?
> 
> I understand that I could do this using multiple requests, but that seems  
> incredibly wasteful.
> 
> Any help would be much appreciated.
> 
> Andrew
> 
> ## Andrew Harvey / Developer lexer m/ t/ +61 2 9019 6379 w/ [http://lexer.com.au](http://lexer.com.au) Help put an end to whaling. Visit [http://www.givewhalesavoice.com.au/](http://www.givewhalesavoice.com.au/)
> 
> Please consider the environment before printing this email  
> This email transmission is confidential and intended solely for the person  
> or organisation to whom it is addressed. If you are not the intended  
> recipient, you must not copy, distribute or disseminate the information, or  
> take any action in relation to it and please delete this e-mail. Any views  
> expressed in this message are those of the individual sender, except where  
> the send specifically states them to be the views of any organisation or  
> employer. If you have received this message in error, do not open any  
> attachment but please notify the sender (above). This message has been  
> checked for all known viruses powered by McAfee.
> 
> For further information visit  
> [Advanced Research Center | Trellix](http://www.mcafee.com/us/threat_center/default.asp)  
> Please rely on your own virus check as no responsibility is taken by the  
> sender for any damage rising out of any virus infection this communication  
> may contain.
> 
> This message has been scanned for malware by Websense. [www.websense.com](http://www.websense.com)

---

<div class="post-metadata">

**Author:** ![Andrew\_Harvey\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_harvey_2/32/3328_2.png) [@Andrew\_Harvey\_2](https://discuss.elastic.co/u/Andrew_Harvey_2)\
**Post date:** [July 12, 2010, 11:11pm UTC](https://discuss.elastic.co/t/histogram-facets-with-a-query/3087/3 "2010-07-12T23:11:09Z")

</div>

Not quite what I'm looking for.

Say I want to have histograms for the results of up to 4 queries, all of which being queries. A single global query wouldn't split things up the way I want.

In the earlier example, I was trying to have a histogram for the query "foo" and for the query "bar" across the same result set. A filter on each individual facet would also work, but there doesn't seem to be possible on a per facet basis. Am I wrong in that assumption?

Andrew

On 13/07/2010, at 4:01 AM, Shay Banon wrote:

Can you explain a bit what you are trying to do exactly? There is no option in the histogram facet to provide a query, but you can provide a filter to further filter the hits the histogram (or any other facet) will run on. Is that what you are after?

-shay.banon

On Mon, Jul 12, 2010 at 8:43 AM, Andrew Harvey \<Andrew.Harvey@lexer.com.au[mailto:Andrew.Harvey@lexer.com.au](mailto:Andrew.Harvey@lexer.com.au)\> wrote:  
Hey there,

I've been playing around a little more with facets and I think I've come up against a limitation in the histogram facet. I'm looking to produce a histogram facet which has a query. Basically imagine the query facet and the histogram facet made sweet sweet love, then you'd have this.

Unless of course, I've missed the fact that this kind of facet already exists...

I've tried doing things like:

"facets": {  
"foo": {  
"histogram": {  
"time\_interval": "24H",  
"key\_field": "published",  
"query": {  
"query\_string": {  
"query": "foo"  
}  
}  
}  
} ,  
"bar": {  
"histogram": {  
"time\_interval": "24H",  
"key\_field": "published",  
"query": {  
"query\_string": {  
"query": "bar"  
}  
}  
}  
}  
}

But to no avail. Have I just missed this feature, or should I open a bug for it?

I understand that I could do this using multiple requests, but that seems incredibly wasteful.

Any help would be much appreciated.

Andrew

## Andrew Harvey / Developer lexer m/ t/ +61 2 9019 6379 w/ [http://lexer.com.au](http://lexer.com.au)[http://lexer.com.au/](http://lexer.com.au/) Help put an end to whaling. Visit [http://www.givewhalesavoice.com.au/](http://www.givewhalesavoice.com.au/)

Please consider the environment before printing this email  
This email transmission is confidential and intended solely for the person or organisation to whom it is addressed. If you are not the intended recipient, you must not copy, distribute or disseminate the information, or take any action in relation to it and please delete this e-mail. Any views expressed in this message are those of the individual sender, except where the send specifically states them to be the views of any organisation or employer. If you have received this message in error, do not open any attachment but please notify the sender (above). This message has been checked for all known viruses powered by McAfee.

For further information visit [http://www.mcafee.com/us/threat\_center/default.asp](http://www.mcafee.com/us/threat_center/default.asp)  
Please rely on your own virus check as no responsibility is taken by the sender for any damage rising out of any virus infection this communication may contain.

This message has been scanned for malware by Websense. [www.websense.com](http://www.websense.com)[http://www.websense.com/](http://www.websense.com/)

Click here[https://www.mailcontrol.com/sr/ZmHw4mchlAfTndxI!oX7Ul4TPWxlZJ1auzCPBn9Prj9fIW+ZgW8tKv+78wAJHus16o5Dvy9BQPV8TccP!XTbKg==](https://www.mailcontrol.com/sr/ZmHw4mchlAfTndxI!oX7Ul4TPWxlZJ1auzCPBn9Prj9fIW+ZgW8tKv+78wAJHus16o5Dvy9BQPV8TccP!XTbKg==) to report this email as spam.

Andrew Harvey / Developer  
lexer

m/  
t/ +61 2 9019 6379  
w/ [http://lexer.com.au](http://lexer.com.au)

Help put an end to whaling. Visit www.givewhalesavoice.com.au[http://www.givewhalesavoice.com.au/](http://www.givewhalesavoice.com.au/)

* * *

Please consider the environment before printing this email  
This email transmission is confidential and intended solely for the person or organisation to whom it is addressed. If you are not the intended recipient, you must not copy, distribute or disseminate the information, or take any action in relation to it and please delete this e-mail. Any views expressed in this message are those of the individual sender, except where the send specifically states them to be the views of any organisation or employer. If you have received this message in error, do not open any attachment but please notify the sender (above). This message has been checked for all known viruses powered by McAfee.

For further information visit [http://www.mcafee.com/us/threat\_center/default.asp](http://www.mcafee.com/us/threat_center/default.asp)  
Please rely on your own virus check as no responsibility is taken by the sender for any damage rising out of any virus infection this communication may contain.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 13, 2010, 7:15am UTC](https://discuss.elastic.co/t/histogram-facets-with-a-query/3087/4 "2010-07-13T07:15:48Z")

</div>

Not sure that I still managed to follow exactly what you are after, but let  
me guess ;). In a facet, you can define it as a global one (running on all  
data, not constrained by the query you execute for search) and then define  
filters on it. Is that what you are after?

-shay.banon

On Tue, Jul 13, 2010 at 2:11 AM, Andrew Harvey  
[Andrew.Harvey@lexer.com.au](mailto:Andrew.Harvey@lexer.com.au)wrote:

> Not quite what I'm looking for.
> 
> Say I want to have histograms for the results of up to 4 queries, all of  
> which being queries. A single global query wouldn't split things up the way  
> I want.
> 
> In the earlier example, I was trying to have a histogram for the query  
> "foo" and for the query "bar" across the same result set. A filter on each  
> individual facet would also work, but there doesn't seem to be possible on a  
> per facet basis. Am I wrong in that assumption?
> 
> Andrew
> 
> On 13/07/2010, at 4:01 AM, Shay Banon wrote:
> 
> Can you explain a bit what you are trying to do exactly? There is no option  
> in the histogram facet to provide a query, but you can provide a filter to  
> further filter the hits the histogram (or any other facet) will run on. Is  
> that what you are after?
> 
> -shay.banon
> 
> On Mon, Jul 12, 2010 at 8:43 AM, Andrew Harvey \<Andrew.Harvey@lexer.com.au
> 
> > wrote:
> 
> > Hey there,
> > 
> > I've been playing around a little more with facets and I think I've come  
> > up against a limitation in the histogram facet. I'm looking to produce a  
> > histogram facet which has a query. Basically imagine the query facet and the  
> > histogram facet made sweet sweet love, then you'd have this.
> > 
> > Unless of course, I've missed the fact that this kind of facet already  
> > exists...
> > 
> > I've tried doing things like:
> > 
> > "facets": {  
> > "foo": {  
> > "histogram": {  
> > "time\_interval": "24H",  
> > "key\_field": "published",  
> > "query": {  
> > "query\_string": {  
> > "query": "foo"  
> > }  
> > }  
> > }  
> > } ,  
> > "bar": {  
> > "histogram": {  
> > "time\_interval": "24H",  
> > "key\_field": "published",  
> > "query": {  
> > "query\_string": {  
> > "query": "bar"  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > But to no avail. Have I just missed this feature, or should I open a bug  
> > for it?
> > 
> > I understand that I could do this using multiple requests, but that seems  
> > incredibly wasteful.
> > 
> > Any help would be much appreciated.
> > 
> > Andrew
> > 
> > ## Andrew Harvey / Developer lexer m/ t/ +61 2 9019 6379 w/ [http://lexer.com.au](http://lexer.com.au) Help put an end to whaling. Visit [http://www.givewhalesavoice.com.au/](http://www.givewhalesavoice.com.au/)
> > 
> > Please consider the environment before printing this email  
> > This email transmission is confidential and intended solely for the person  
> > or organisation to whom it is addressed. If you are not the intended  
> > recipient, you must not copy, distribute or disseminate the information, or  
> > take any action in relation to it and please delete this e-mail. Any views  
> > expressed in this message are those of the individual sender, except where  
> > the send specifically states them to be the views of any organisation or  
> > employer. If you have received this message in error, do not open any  
> > attachment but please notify the sender (above). This message has been  
> > checked for all known viruses powered by McAfee.
> > 
> > For further information visit  
> > [Advanced Research Center | Trellix](http://www.mcafee.com/us/threat_center/default.asp)  
> > Please rely on your own virus check as no responsibility is taken by the  
> > sender for any damage rising out of any virus infection this communication  
> > may contain.
> > 
> > This message has been scanned for malware by Websense. [www.websense.com](http://www.websense.com)
> 
> Click here[https://www.mailcontrol.com/sr/ZmHw4mchlAfTndxI!oX7Ul4TPWxlZJ1auzCPBn9Prj9fIW+ZgW8tKv+78wAJHus16o5Dvy9BQPV8TccP!XTbKg==](https://www.mailcontrol.com/sr/ZmHw4mchlAfTndxI!oX7Ul4TPWxlZJ1auzCPBn9Prj9fIW+ZgW8tKv+78wAJHus16o5Dvy9BQPV8TccP!XTbKg==)to report this email as spam.
> 
> Andrew Harvey / Developer _lexer_
> 
> _m/__t/_ +61 2 9019 6379 _w/_[http://lexer.com.au](http://lexer.com.au)
> 
> ## Help put an end to whaling. Visit www.givewhalesavoice.com.au
> 
> Please consider the environment before printing this email  
> This email transmission is confidential and intended solely for the person  
> or organisation to whom it is addressed. If you are not the intended  
> recipient, you must not copy, distribute or disseminate the information, or  
> take any action in relation to it and please delete this e-mail. Any views  
> expressed in this message are those of the individual sender, except where  
> the send specifically states them to be the views of any organisation or  
> employer. If you have received this message in error, do not open any  
> attachment but please notify the sender (above). This message has been  
> checked for all known viruses powered by McAfee.
> 
> For further information visit  
> [Advanced Research Center | Trellix](http://www.mcafee.com/us/threat_center/default.asp)  
> Please rely on your own virus check as no responsibility is taken by the  
> sender for any damage rising out of any virus infection this communication  
> may contain.

---

<div class="post-metadata">

**Author:** ![Andrew\_Harvey\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_harvey_2/32/3328_2.png) [@Andrew\_Harvey\_2](https://discuss.elastic.co/u/Andrew_Harvey_2)\
**Post date:** [July 13, 2010, 7:19am UTC](https://discuss.elastic.co/t/histogram-facets-with-a-query/3087/5 "2010-07-13T07:19:42Z")

</div>

Something like that. The facet can be constrained by the query, it doesn't matter much. I'm just interested in having multiple histograms from multiple queries from one request.

Sorry if I'm not expressing myself very clearly.

Andrew.

Sent on the run.

On 13/07/2010, at 17:16, "Shay Banon" \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)[mailto:shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:

Not sure that I still managed to follow exactly what you are after, but let me guess ;). In a facet, you can define it as a global one (running on all data, not constrained by the query you execute for search) and then define filters on it. Is that what you are after?

-shay.banon

On Tue, Jul 13, 2010 at 2:11 AM, Andrew Harvey \<[mailto:Andrew.Harvey@lexer.com.au](mailto:Andrew.Harvey@lexer.com.au)Andrew.Harvey@lexer.com.au[mailto:Andrew.Harvey@lexer.com.au](mailto:Andrew.Harvey@lexer.com.au)\> wrote:

Not quite what I'm looking for.

Say I want to have histograms for the results of up to 4 queries, all of which being queries. A single global query wouldn't split things up the way I want.

In the earlier example, I was trying to have a histogram for the query "foo" and for the query "bar" across the same result set. A filter on each individual facet would also work, but there doesn't seem to be possible on a per facet basis. Am I wrong in that assumption?

Andrew

On 13/07/2010, at 4:01 AM, Shay Banon wrote:

Can you explain a bit what you are trying to do exactly? There is no option in the histogram facet to provide a query, but you can provide a filter to further filter the hits the histogram (or any other facet) will run on. Is that what you are after?

-shay.banon

On Mon, Jul 12, 2010 at 8:43 AM, Andrew Harvey \<[mailto:Andrew.Harvey@lexer.com.au](mailto:Andrew.Harvey@lexer.com.au)Andrew.Harvey@lexer.com.au[mailto:Andrew.Harvey@lexer.com.au](mailto:Andrew.Harvey@lexer.com.au)\> wrote:  
Hey there,

I've been playing around a little more with facets and I think I've come up against a limitation in the histogram facet. I'm looking to produce a histogram facet which has a query. Basically imagine the query facet and the histogram facet made sweet sweet love, then you'd have this.

Unless of course, I've missed the fact that this kind of facet already exists...

I've tried doing things like:

"facets": {  
"foo": {  
"histogram": {  
"time\_interval": "24H",  
"key\_field": "published",  
"query": {  
"query\_string": {  
"query": "foo"  
}  
}  
}  
} ,  
"bar": {  
"histogram": {  
"time\_interval": "24H",  
"key\_field": "published",  
"query": {  
"query\_string": {  
"query": "bar"  
}  
}  
}  
}  
}

But to no avail. Have I just missed this feature, or should I open a bug for it?

I understand that I could do this using multiple requests, but that seems incredibly wasteful.

Any help would be much appreciated.

Andrew

## Andrew Harvey / Developer lexer m/ t/ +61 2 9019 6379 w/ [http://lexer.com.au/](http://lexer.com.au/) [http://lexer.com.au](http://lexer.com.au) Help put an end to whaling. Visit [http://www.givewhalesavoice.com.au/](http://www.givewhalesavoice.com.au/) [http://www.givewhalesavoice.com.au/](http://www.givewhalesavoice.com.au/)

Please consider the environment before printing this email  
This email transmission is confidential and intended solely for the person or organisation to whom it is addressed. If you are not the intended recipient, you must not copy, distribute or disseminate the information, or take any action in relation to it and please delete this e-mail. Any views expressed in this message are those of the individual sender, except where the send specifically states them to be the views of any organisation or employer. If you have received this message in error, do not open any attachment but please notify the sender (above). This message has been checked for all known viruses powered by McAfee.

For further information visit [http://www.mcafee.com/us/threat\_center/default.asp](http://www.mcafee.com/us/threat_center/default.asp) [http://www.mcafee.com/us/threat\_center/default.asp](http://www.mcafee.com/us/threat_center/default.asp)  
Please rely on your own virus check as no responsibility is taken by the sender for any damage rising out of any virus infection this communication may contain.

This message has been scanned for malware by Websense. [http://www.websense.com/](http://www.websense.com/) [www.websense.com](http://www.websense.com)[http://www.websense.com](http://www.websense.com)

Click here[https://www.mailcontrol.com/sr/ZmHw4mchlAfTndxI!oX7Ul4TPWxlZJ1auzCPBn9Prj9fIW+ZgW8tKv+78wAJHus16o5Dvy9BQPV8TccP!XTbKg==](https://www.mailcontrol.com/sr/ZmHw4mchlAfTndxI!oX7Ul4TPWxlZJ1auzCPBn9Prj9fIW+ZgW8tKv+78wAJHus16o5Dvy9BQPV8TccP!XTbKg==) to report this email as spam.

Andrew Harvey / Developer  
lexer

m/  
t/ +61 2 9019 6379  
w/ [http://lexer.com.au](http://lexer.com.au) [http://lexer.com.au](http://lexer.com.au)

Help put an end to whaling. Visit www.givewhalesavoice.com.au[http://www.givewhalesavoice.com.au/](http://www.givewhalesavoice.com.au/)

* * *

Please consider the environment before printing this email  
This email transmission is confidential and intended solely for the person or organisation to whom it is addressed. If you are not the intended recipient, you must not copy, distribute or disseminate the information, or take any action in relation to it and please delete this e-mail. Any views expressed in this message are those of the individual sender, except where the send specifically states them to be the views of any organisation or employer. If you have received this message in error, do not open any attachment but please notify the sender (above). This message has been checked for all known viruses powered by McAfee.

For further information visit [http://www.mcafee.com/us/threat\_center/default.asp](http://www.mcafee.com/us/threat_center/default.asp) [http://www.mcafee.com/us/threat\_center/default.asp](http://www.mcafee.com/us/threat_center/default.asp)  
Please rely on your own virus check as no responsibility is taken by the sender for any damage rising out of any virus infection this communication may contain.

Andrew Harvey / Developer  
lexer

m/  
t/ +61 2 9019 6379  
w/ [http://lexer.com.au](http://lexer.com.au)

Help put an end to whaling. Visit www.givewhalesavoice.com.au[http://www.givewhalesavoice.com.au/](http://www.givewhalesavoice.com.au/)

* * *

Please consider the environment before printing this email  
This email transmission is confidential and intended solely for the person or organisation to whom it is addressed. If you are not the intended recipient, you must not copy, distribute or disseminate the information, or take any action in relation to it and please delete this e-mail. Any views expressed in this message are those of the individual sender, except where the send specifically states them to be the views of any organisation or employer. If you have received this message in error, do not open any attachment but please notify the sender (above). This message has been checked for all known viruses powered by McAfee.

For further information visit [http://www.mcafee.com/us/threat\_center/default.asp](http://www.mcafee.com/us/threat_center/default.asp)  
Please rely on your own virus check as no responsibility is taken by the sender for any damage rising out of any virus infection this communication may contain.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 13, 2010, 7:22am UTC](https://discuss.elastic.co/t/histogram-facets-with-a-query/3087/6 "2010-07-13T07:22:55Z")

</div>

Yes, you can do that with the ability to provide facets with both filters  
and define if they are global or not. In terms of filters, there is a filter  
that can wrap a query, so all the query power is there with filters as well.

-shay.banon

On Tue, Jul 13, 2010 at 10:19 AM, Andrew Harvey  
[Andrew.Harvey@lexer.com.au](mailto:Andrew.Harvey@lexer.com.au)wrote:

> Something like that. The facet can be constrained by the query, it  
> doesn't matter much. I'm just interested in having multiple histograms from  
> multiple queries from one request.
> 
> Sorry if I'm not expressing myself very clearly.
> 
> Andrew.
> 
> Sent on the run.
> 
> On 13/07/2010, at 17:16, "Shay Banon" [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)  
> wrote:
> 
> Not sure that I still managed to follow exactly what you are after, but let  
> me guess ;). In a facet, you can define it as a global one (running on all  
> data, not constrained by the query you execute for search) and then define  
> filters on it. Is that what you are after?
> 
> -shay.banon
> 
> On Tue, Jul 13, 2010 at 2:11 AM, Andrew Harvey \<[Andrew.Harvey@lexer.com.au](mailto:Andrew.Harvey@lexer.com.au)  
> Andrew.Harvey@lexer.com.au\> wrote:
> 
> > Not quite what I'm looking for.
> > 
> > Say I want to have histograms for the results of up to 4 queries, all of  
> > which being queries. A single global query wouldn't split things up the way  
> > I want.
> > 
> > In the earlier example, I was trying to have a histogram for the query  
> > "foo" and for the query "bar" across the same result set. A filter on each  
> > individual facet would also work, but there doesn't seem to be possible on a  
> > per facet basis. Am I wrong in that assumption?
> > 
> > Andrew
> > 
> > On 13/07/2010, at 4:01 AM, Shay Banon wrote:
> > 
> > Can you explain a bit what you are trying to do exactly? There is no  
> > option in the histogram facet to provide a query, but you can provide a  
> > filter to further filter the hits the histogram (or any other facet) will  
> > run on. Is that what you are after?
> > 
> > -shay.banon
> > 
> > On Mon, Jul 12, 2010 at 8:43 AM, Andrew Harvey \<[Andrew.Harvey@lexer.com.au](mailto:Andrew.Harvey@lexer.com.au)  
> > Andrew.Harvey@lexer.com.au\> wrote:
> > 
> > > Hey there,
> > > 
> > > I've been playing around a little more with facets and I think I've come  
> > > up against a limitation in the histogram facet. I'm looking to produce a  
> > > histogram facet which has a query. Basically imagine the query facet and the  
> > > histogram facet made sweet sweet love, then you'd have this.
> > > 
> > > Unless of course, I've missed the fact that this kind of facet already  
> > > exists...
> > > 
> > > I've tried doing things like:
> > > 
> > > "facets": {  
> > > "foo": {  
> > > "histogram": {  
> > > "time\_interval": "24H",  
> > > "key\_field": "published",  
> > > "query": {  
> > > "query\_string": {  
> > > "query": "foo"  
> > > }  
> > > }  
> > > }  
> > > } ,  
> > > "bar": {  
> > > "histogram": {  
> > > "time\_interval": "24H",  
> > > "key\_field": "published",  
> > > "query": {  
> > > "query\_string": {  
> > > "query": "bar"  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > But to no avail. Have I just missed this feature, or should I open a bug  
> > > for it?
> > > 
> > > I understand that I could do this using multiple requests, but that seems  
> > > incredibly wasteful.
> > > 
> > > Any help would be much appreciated.
> > > 
> > > Andrew
> > > 
> > > Andrew Harvey / Developer  
> > > lexer  
> > > m/  
> > > t/ +61 2 9019 6379  
> > > w/ [http://lexer.com.au/](http://lexer.com.au/)[http://lexer.com.au](http://lexer.com.au)  
> > > Help put an end to whaling. Visit [http://www.givewhalesavoice.com.au/](http://www.givewhalesavoice.com.au/)  
> > > [http://www.givewhalesavoice.com.au/](http://www.givewhalesavoice.com.au/)
> > > 
> > > * * *
> > > 
> > > Please consider the environment before printing this email  
> > > This email transmission is confidential and intended solely for the  
> > > person or organisation to whom it is addressed. If you are not the intended  
> > > recipient, you must not copy, distribute or disseminate the information, or  
> > > take any action in relation to it and please delete this e-mail. Any views  
> > > expressed in this message are those of the individual sender, except where  
> > > the send specifically states them to be the views of any organisation or  
> > > employer. If you have received this message in error, do not open any  
> > > attachment but please notify the sender (above). This message has been  
> > > checked for all known viruses powered by McAfee.
> > > 
> > > For further information visit  
> > > [http://www.mcafee.com/us/threat\_center/default.asp](http://www.mcafee.com/us/threat_center/default.asp)  
> > > [Advanced Research Center | Trellix](http://www.mcafee.com/us/threat_center/default.asp)  
> > > Please rely on your own virus check as no responsibility is taken by the  
> > > sender for any damage rising out of any virus infection this communication  
> > > may contain.
> > > 
> > > This message has been scanned for malware by Websense.  
> > > [http://www.websense.com/](http://www.websense.com/)[www.websense.com](http://www.websense.com)
> > 
> > Click here[https://www.mailcontrol.com/sr/ZmHw4mchlAfTndxI!oX7Ul4TPWxlZJ1auzCPBn9Prj9fIW+ZgW8tKv+78wAJHus16o5Dvy9BQPV8TccP!XTbKg==](https://www.mailcontrol.com/sr/ZmHw4mchlAfTndxI!oX7Ul4TPWxlZJ1auzCPBn9Prj9fIW+ZgW8tKv+78wAJHus16o5Dvy9BQPV8TccP!XTbKg==)to report this email as spam.
> > 
> > Andrew Harvey / Developer _lexer_
> > 
> > _m/__t/_ +61 2 9019 6379 _w/_[http://lexer.com.au](http://lexer.com.au)  
> > [http://lexer.com.au](http://lexer.com.au)
> > 
> > ## Help put an end to whaling. Visit www.givewhalesavoice.com.au
> > 
> > Please consider the environment before printing this email  
> > This email transmission is confidential and intended solely for the person  
> > or organisation to whom it is addressed. If you are not the intended  
> > recipient, you must not copy, distribute or disseminate the information, or  
> > take any action in relation to it and please delete this e-mail. Any views  
> > expressed in this message are those of the individual sender, except where  
> > the send specifically states them to be the views of any organisation or  
> > employer. If you have received this message in error, do not open any  
> > attachment but please notify the sender (above). This message has been  
> > checked for all known viruses powered by McAfee.
> > 
> > For further information visit  
> > [http://www.mcafee.com/us/threat\_center/default.asp](http://www.mcafee.com/us/threat_center/default.asp)  
> > [Advanced Research Center | Trellix](http://www.mcafee.com/us/threat_center/default.asp)  
> > Please rely on your own virus check as no responsibility is taken by the  
> > sender for any damage rising out of any virus infection this communication  
> > may contain.
> 
> Andrew Harvey / Developer _lexer_
> 
> _m/__t/_ +61 2 9019 6379 _w/_[http://lexer.com.au](http://lexer.com.au)
> 
> ## Help put an end to whaling. Visit www.givewhalesavoice.com.au
> 
> Please consider the environment before printing this email  
> This email transmission is confidential and intended solely for the person  
> or organisation to whom it is addressed. If you are not the intended  
> recipient, you must not copy, distribute or disseminate the information, or  
> take any action in relation to it and please delete this e-mail. Any views  
> expressed in this message are those of the individual sender, except where  
> the send specifically states them to be the views of any organisation or  
> employer. If you have received this message in error, do not open any  
> attachment but please notify the sender (above). This message has been  
> checked for all known viruses powered by McAfee.
> 
> For further information visit  
> [Advanced Research Center | Trellix](http://www.mcafee.com/us/threat_center/default.asp)  
> Please rely on your own virus check as no responsibility is taken by the  
> sender for any damage rising out of any virus infection this communication  
> may contain.

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [July 13, 2010, 9:34am UTC](https://discuss.elastic.co/t/histogram-facets-with-a-query/3087/7 "2010-07-13T09:34:59Z")

</div>

> ï»¿I've been playing around a little more with facets and I think I've  
> come up against a limitation in the histogram facet. I'm looking to  
> produce a histogram facet which has a query. Basically imagine the  
> query facet and the histogram facet made sweet sweet love, then you'd  
> have this.

I haven't tried facets yet, but I think this should do what you want  
(untested):

1. I've used a match\_all query to match all docs - you can change this  
to whatever is relevant

2. histograms need X and Y values, so I've added the \_id field to give  
it something to count

3. I've filtered each histogram using a constant\_score filter, which  
can wrap any query.

{  
"query": { "match\_all": {}},  
"facets": {  
"foo": {  
"histogram": {  
"time\_interval": "24H",  
"key\_field": "published",  
"value\_field": "\_id"  
},  
"filter": {  
"constant\_score" : {  
"filter" : {  
"query" : {  
"query\_string" : {  
"query" : "foo"  
}  
}  
}  
}  
}  
} ,  
"bar": {  
"histogram": {  
"time\_interval": "24H",  
"key\_field": "published",  
"value\_field": "\_id"  
},  
"filter": {  
"constant\_score" : {  
"filter" : {  
"query" : {  
"query\_string" : {  
"query" : "bar"  
}  
}  
}  
}  
}  
}  
}  
}

---

<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, 4:22am UTC](https://discuss.elastic.co/t/histogram-facets-with-a-query/3087/8 "2017-07-06T04:22:22Z")

</div>


