# Combination of Date Histogram Facet and Term Facet

**URL:** <https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422>\
**Category:** Elasticsearch\
**Created:** [April 20, 2012, 2:46pm UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422 "2012-04-20T14:46:25Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)\
**Post date:** [April 20, 2012, 2:46pm UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422/1 "2012-04-20T14:46:25Z")

</div>

Hi,  
I am using DateHistogram Facet for getting the Daterange and  
items. For Example

In DateHistogram Facet we can get the number of data or count  
within the selected date range. In my application I need to get both  
the

1. Daterange and the count of matches similar to

createddate" : {  
"\_type" : "statistical",  
"count" : 158,  
"total" : 2.10720682311E14,  
"min" : 1.3332708E12,  
"max" : 1.3340484E12,  
"mean" : 1.3336752045E12,  
"sum\_of\_squares" : 2.8103295903276077E26,  
"variance" : 6.30332803714792E16,  
"std\_deviation" : 2.510642952940127E8  
}

1. The number number of items and the matches count similar to

"facets" : {  
"itemscount" : {  
"\_type" : "terms",  
"missing" : 0,  
"total" : 3492,  
"other" : 0,  
"terms" : [ {  
"term" : 1,  
"count" : 3022  
}, {  
"term" : 2,  
"count" : 247  
}, {  
"term" : 6,  
"count" : 154  
}, {  
"term" : 3,  
"count" : 28  
}, {  
"term" : 5,  
"count" : 27  
}, {  
"term" : 4,  
"count" : 14  
} ]  
},

Can this two things will get by a single facet? How can I get this  
using facet?

Cheers!

George

---

<div class="post-metadata">

**Author:** ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)\
**Post date:** [April 21, 2012, 11:41am UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422/2 "2012-04-21T11:41:22Z")

</div>

Hi,  
How to combine two type of facets together as a single facet in  
elasticsearch?

Cheers!

George

On Apr 20, 7:46 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:

> Hi,  
> I am using DateHistogram Facet for getting the Daterange and  
> items. For Example
> 
> In DateHistogram Facet we can get the number of data or count  
> within the selected date range. In my application I need to get both  
> the
> 
> 1. Daterange and the count of matches similar to
> 
> createddate" : {  
> "\_type" : "statistical",  
> "count" : 158,  
> "total" : 2.10720682311E14,  
> "min" : 1.3332708E12,  
> "max" : 1.3340484E12,  
> "mean" : 1.3336752045E12,  
> "sum\_of\_squares" : 2.8103295903276077E26,  
> "variance" : 6.30332803714792E16,  
> "std\_deviation" : 2.510642952940127E8  
> }
> 
> 1. The number number of items and the matches count similar to
> 
> "facets" : {  
> "itemscount" : {  
> "\_type" : "terms",  
> "missing" : 0,  
> "total" : 3492,  
> "other" : 0,  
> "terms" : [ {  
> "term" : 1,  
> "count" : 3022  
> }, {  
> "term" : 2,  
> "count" : 247  
> }, {  
> "term" : 6,  
> "count" : 154  
> }, {  
> "term" : 3,  
> "count" : 28  
> }, {  
> "term" : 5,  
> "count" : 27  
> }, {  
> "term" : 4,  
> "count" : 14  
> } ]  
> },
> 
> Can this two things will get by a single facet? How can I get this  
> using facet?
> 
> Cheers!
> 
> George

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [April 23, 2012, 3:30pm UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422/3 "2012-04-23T15:30:50Z")

</div>

Not sure I understood your question. If you are trying to combine  
statistical and histogram facets in the same facet, it's not possible.  
However, you can send multiple facet requests in the same search request:

{  
"query" : {  
"match\_all" : {}  
},  
"facets" : {  
"stat1" : {  
"statistical" : {  
. . .  
}  
},  
"histo1" : {  
"date\_histogram" : {  
. . .  
}  
}  
}  
}

On Saturday, April 21, 2012 7:41:22 AM UTC-4, George Viju wrote:

> Hi,  
> How to combine two type of facets together as a single facet in  
> elasticsearch?
> 
> Cheers!
> 
> George
> 
> On Apr 20, 7:46 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> 
> > Hi,  
> > I am using DateHistogram Facet for getting the Daterange and  
> > items. For Example
> > 
> > In DateHistogram Facet we can get the number of data or count  
> > within the selected date range. In my application I need to get both  
> > the
> > 
> > 1. Daterange and the count of matches similar to
> > 
> > createddate" : {  
> > "\_type" : "statistical",  
> > "count" : 158,  
> > "total" : 2.10720682311E14,  
> > "min" : 1.3332708E12,  
> > "max" : 1.3340484E12,  
> > "mean" : 1.3336752045E12,  
> > "sum\_of\_squares" : 2.8103295903276077E26,  
> > "variance" : 6.30332803714792E16,  
> > "std\_deviation" : 2.510642952940127E8  
> > }
> > 
> > 1. The number number of items and the matches count similar to
> > 
> > "facets" : {  
> > "itemscount" : {  
> > "\_type" : "terms",  
> > "missing" : 0,  
> > "total" : 3492,  
> > "other" : 0,  
> > "terms" : [ {  
> > "term" : 1,  
> > "count" : 3022  
> > }, {  
> > "term" : 2,  
> > "count" : 247  
> > }, {  
> > "term" : 6,  
> > "count" : 154  
> > }, {  
> > "term" : 3,  
> > "count" : 28  
> > }, {  
> > "term" : 5,  
> > "count" : 27  
> > }, {  
> > "term" : 4,  
> > "count" : 14  
> > } ]  
> > },
> > 
> > Can this two things will get by a single facet? How can I get this  
> > using facet?
> > 
> > Cheers!
> > 
> > George

---

<div class="post-metadata">

**Author:** ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)\
**Post date:** [April 24, 2012, 3:51am UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422/4 "2012-04-24T03:51:26Z")

</div>

Thank you Igor Motov! In my case, I need to combine the Date  
Histogram and Term Facet

It is like.

1. Daterange and the count of matches similar to  
createddate" : {  
"\_type" : "statistical",  
"count" : 158,  
"total" : 2.10720682311E14,  
"min" : 1.3332708E12,  
"max" : 1.3340484E12,  
"mean" : 1.3336752045E12,  
"sum\_of\_squares" : 2.8103295903276077E26,  
"variance" : 6.30332803714792E16,  
"std\_deviation" : 2.510642952940127E8  
}
2. The number number of items and the matches count similar to  
"facets" : {  
"itemscount" : {  
"\_type" : "terms",  
"missing" : 0,  
"total" : 3492,  
"other" : 0,  
"terms" : [ {  
"term" : 1,  
"count" : 3022  
}, {  
"term" : 2,  
"count" : 247  
}, {  
"term" : 6,  
"count" : 154  
}, {  
"term" : 3,  
"count" : 28  
}, {  
"term" : 5,  
"count" : 27  
}, {  
"term" : 4,  
"count" : 14  
} ]  
},

How can I combine these two as a single Facet?

Cheers!

George

On Apr 23, 8:30 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:

> Not sure I understood your question. If you are trying to combine  
> statistical and histogram facets in the same facet, it's not possible.  
> However, you can send multiple facet requests in the same search request:
> 
> {  
> "query" : {  
> "match\_all" : {}  
> },  
> "facets" : {  
> "stat1" : {  
> "statistical" : {  
> . . .  
> }  
> },  
> "histo1" : {  
> "date\_histogram" : {  
> . . .  
> }  
> }  
> }
> 
> }  
> On Saturday, April 21, 2012 7:41:22 AM UTC-4, George Viju wrote:
> 
> > Hi,  
> > How to combine two type of facets together as a single facet in  
> > elasticsearch?
> 
> > Cheers!
> 
> > George
> 
> > On Apr 20, 7:46 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> > 
> > > Hi,  
> > > I am using DateHistogram Facet for getting the Daterange and  
> > > items. For Example
> 
> > > In DateHistogram Facet we can get the number of data or count  
> > > within the selected date range. In my application I need to get both  
> > > the
> 
> > > 1. Daterange and the count of matches similar to
> 
> > > createddate" : {  
> > > "\_type" : "statistical",  
> > > "count" : 158,  
> > > "total" : 2.10720682311E14,  
> > > "min" : 1.3332708E12,  
> > > "max" : 1.3340484E12,  
> > > "mean" : 1.3336752045E12,  
> > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > "variance" : 6.30332803714792E16,  
> > > "std\_deviation" : 2.510642952940127E8  
> > > }
> 
> > > 1. The number number of items and the matches count similar to
> 
> > > "facets" : {  
> > > "itemscount" : {  
> > > "\_type" : "terms",  
> > > "missing" : 0,  
> > > "total" : 3492,  
> > > "other" : 0,  
> > > "terms" : [ {  
> > > "term" : 1,  
> > > "count" : 3022  
> > > }, {  
> > > "term" : 2,  
> > > "count" : 247  
> > > }, {  
> > > "term" : 6,  
> > > "count" : 154  
> > > }, {  
> > > "term" : 3,  
> > > "count" : 28  
> > > }, {  
> > > "term" : 5,  
> > > "count" : 27  
> > > }, {  
> > > "term" : 4,  
> > > "count" : 14  
> > > } ]  
> > > },
> 
> > > Can this two things will get by a single facet? How can I get this  
> > > using facet?
> 
> > > Cheers!
> 
> > > George

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [April 24, 2012, 2:23pm UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422/5 "2012-04-24T14:23:15Z")

</div>

Your first example looks like statistical facet response, not  
date histogram facet response. So, I am not quite sure what information you  
are trying to retrieve. What's the type of the field that you are running  
these facet queries on? Can you provide a more detailed example of what you  
are trying to achieve?

On Monday, April 23, 2012 11:51:26 PM UTC-4, George Viju wrote:

> Thank you Igor Motov! In my case, I need to combine the Date  
> Histogram and Term Facet
> 
> It is like.
> 
> 1. Daterange and the count of matches similar to  
> createddate" : {  
> "\_type" : "statistical",  
> "count" : 158,  
> "total" : 2.10720682311E14,  
> "min" : 1.3332708E12,  
> "max" : 1.3340484E12,  
> "mean" : 1.3336752045E12,  
> "sum\_of\_squares" : 2.8103295903276077E26,  
> "variance" : 6.30332803714792E16,  
> "std\_deviation" : 2.510642952940127E8  
> }
> 2. The number number of items and the matches count similar to  
> "facets" : {  
> "itemscount" : {  
> "\_type" : "terms",  
> "missing" : 0,  
> "total" : 3492,  
> "other" : 0,  
> "terms" : [ {  
> "term" : 1,  
> "count" : 3022  
> }, {  
> "term" : 2,  
> "count" : 247  
> }, {  
> "term" : 6,  
> "count" : 154  
> }, {  
> "term" : 3,  
> "count" : 28  
> }, {  
> "term" : 5,  
> "count" : 27  
> }, {  
> "term" : 4,  
> "count" : 14  
> } ]  
> },
> 
> How can I combine these two as a single Facet?
> 
> Cheers!
> 
> George
> 
> On Apr 23, 8:30 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> 
> > Not sure I understood your question. If you are trying to combine  
> > statistical and histogram facets in the same facet, it's not possible.  
> > However, you can send multiple facet requests in the same search  
> > request:
> > 
> > {  
> > "query" : {  
> > "match\_all" : {}  
> > },  
> > "facets" : {  
> > "stat1" : {  
> > "statistical" : {  
> > . . .  
> > }  
> > },  
> > "histo1" : {  
> > "date\_histogram" : {  
> > . . .  
> > }  
> > }  
> > }
> > 
> > }  
> > On Saturday, April 21, 2012 7:41:22 AM UTC-4, George Viju wrote:
> > 
> > > Hi,  
> > > How to combine two type of facets together as a single facet in  
> > > elasticsearch?
> > 
> > > Cheers!
> > 
> > > George
> > 
> > > On Apr 20, 7:46 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> > > 
> > > > Hi,  
> > > > I am using DateHistogram Facet for getting the Daterange and  
> > > > items. For Example
> > 
> > > > In DateHistogram Facet we can get the number of data or count  
> > > > within the selected date range. In my application I need to get both  
> > > > the
> > 
> > > > 1. Daterange and the count of matches similar to
> > 
> > > > createddate" : {  
> > > > "\_type" : "statistical",  
> > > > "count" : 158,  
> > > > "total" : 2.10720682311E14,  
> > > > "min" : 1.3332708E12,  
> > > > "max" : 1.3340484E12,  
> > > > "mean" : 1.3336752045E12,  
> > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > "variance" : 6.30332803714792E16,  
> > > > "std\_deviation" : 2.510642952940127E8  
> > > > }
> > 
> > > > 1. The number number of items and the matches count similar to
> > 
> > > > "facets" : {  
> > > > "itemscount" : {  
> > > > "\_type" : "terms",  
> > > > "missing" : 0,  
> > > > "total" : 3492,  
> > > > "other" : 0,  
> > > > "terms" : [ {  
> > > > "term" : 1,  
> > > > "count" : 3022  
> > > > }, {  
> > > > "term" : 2,  
> > > > "count" : 247  
> > > > }, {  
> > > > "term" : 6,  
> > > > "count" : 154  
> > > > }, {  
> > > > "term" : 3,  
> > > > "count" : 28  
> > > > }, {  
> > > > "term" : 5,  
> > > > "count" : 27  
> > > > }, {  
> > > > "term" : 4,  
> > > > "count" : 14  
> > > > } ]  
> > > > },
> > 
> > > > Can this two things will get by a single facet? How can I get this  
> > > > using facet?
> > 
> > > > Cheers!
> > 
> > > > George

---

<div class="post-metadata">

**Author:** ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)\
**Post date:** [April 24, 2012, 3:18pm UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422/6 "2012-04-24T15:18:42Z")

</div>

Thank You Igor Motov! . I have the parameters should be be found  
like -- createddaterange vs sales and items (in the createddaterange)  
vs sales ,

Here I need to find,

1. For each date range the number(amount) of sales.

2. For each items in the date range the number(amount) of sales.

Example:  
From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the  
number of sales is 25  
From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the  
number of sales of item AAA is 30

My Output is Like  
From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
the number of sales is 25 and the sales of item AAA is 30.

How can I get this using Facets Elasticsearch?

Thanks in Advance!

Cheers!

George

That is,

On Apr 24, 7:23 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:

> Your first example looks like statistical facet response, not  
> date histogram facet response. So, I am not quite sure what information you  
> are trying to retrieve. What's the type of the field that you are running  
> these facet queries on? Can you provide a more detailed example of what you  
> are trying to achieve?
> 
> On Monday, April 23, 2012 11:51:26 PM UTC-4, George Viju wrote:
> 
> > Thank you Igor Motov! In my case, I need to combine the Date  
> > Histogram and Term Facet
> 
> > It is like.
> 
> > 1. Daterange and the count of matches similar to  
> > createddate" : {  
> > "\_type" : "statistical",  
> > "count" : 158,  
> > "total" : 2.10720682311E14,  
> > "min" : 1.3332708E12,  
> > "max" : 1.3340484E12,  
> > "mean" : 1.3336752045E12,  
> > "sum\_of\_squares" : 2.8103295903276077E26,  
> > "variance" : 6.30332803714792E16,  
> > "std\_deviation" : 2.510642952940127E8  
> > }
> > 2. The number number of items and the matches count similar to  
> > "facets" : {  
> > "itemscount" : {  
> > "\_type" : "terms",  
> > "missing" : 0,  
> > "total" : 3492,  
> > "other" : 0,  
> > "terms" : [ {  
> > "term" : 1,  
> > "count" : 3022  
> > }, {  
> > "term" : 2,  
> > "count" : 247  
> > }, {  
> > "term" : 6,  
> > "count" : 154  
> > }, {  
> > "term" : 3,  
> > "count" : 28  
> > }, {  
> > "term" : 5,  
> > "count" : 27  
> > }, {  
> > "term" : 4,  
> > "count" : 14  
> > } ]  
> > },
> 
> > How can I combine these two as a single Facet?
> 
> > Cheers!
> 
> > George
> 
> > On Apr 23, 8:30 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > 
> > > Not sure I understood your question. If you are trying to combine  
> > > statistical and histogram facets in the same facet, it's not possible.  
> > > However, you can send multiple facet requests in the same search  
> > > request:
> 
> > > {  
> > > "query" : {  
> > > "match\_all" : {}  
> > > },  
> > > "facets" : {  
> > > "stat1" : {  
> > > "statistical" : {  
> > > . . .  
> > > }  
> > > },  
> > > "histo1" : {  
> > > "date\_histogram" : {  
> > > . . .  
> > > }  
> > > }  
> > > }
> 
> > > }  
> > > On Saturday, April 21, 2012 7:41:22 AM UTC-4, George Viju wrote:
> 
> > > > Hi,  
> > > > How to combine two type of facets together as a single facet in  
> > > > elasticsearch?
> 
> > > > Cheers!
> 
> > > > George
> 
> > > > On Apr 20, 7:46 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> > > > 
> > > > > Hi,  
> > > > > I am using DateHistogram Facet for getting the Daterange and  
> > > > > items. For Example
> 
> > > > > In DateHistogram Facet we can get the number of data or count  
> > > > > within the selected date range. In my application I need to get both  
> > > > > the
> 
> > > > > 1. Daterange and the count of matches similar to
> 
> > > > > createddate" : {  
> > > > > "\_type" : "statistical",  
> > > > > "count" : 158,  
> > > > > "total" : 2.10720682311E14,  
> > > > > "min" : 1.3332708E12,  
> > > > > "max" : 1.3340484E12,  
> > > > > "mean" : 1.3336752045E12,  
> > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > "variance" : 6.30332803714792E16,  
> > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > }
> 
> > > > > 1. The number number of items and the matches count similar to
> 
> > > > > "facets" : {  
> > > > > "itemscount" : {  
> > > > > "\_type" : "terms",  
> > > > > "missing" : 0,  
> > > > > "total" : 3492,  
> > > > > "other" : 0,  
> > > > > "terms" : [ {  
> > > > > "term" : 1,  
> > > > > "count" : 3022  
> > > > > }, {  
> > > > > "term" : 2,  
> > > > > "count" : 247  
> > > > > }, {  
> > > > > "term" : 6,  
> > > > > "count" : 154  
> > > > > }, {  
> > > > > "term" : 3,  
> > > > > "count" : 28  
> > > > > }, {  
> > > > > "term" : 5,  
> > > > > "count" : 27  
> > > > > }, {  
> > > > > "term" : 4,  
> > > > > "count" : 14  
> > > > > } ]  
> > > > > },
> 
> > > > > Can this two things will get by a single facet? How can I get this  
> > > > > using facet?
> 
> > > > > Cheers!
> 
> > > > > George

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [April 24, 2012, 4:00pm UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422/7 "2012-04-24T16:00:01Z")

</div>

Are you going to have multiple ranges per request or a single range per  
request?

On Tuesday, April 24, 2012 11:18:42 AM UTC-4, George Viju wrote:

> Thank You Igor Motov! . I have the parameters should be be found  
> like -- createddaterange vs sales and items (in the createddaterange)  
> vs sales ,
> 
> Here I need to find,
> 
> 1. For each date range the number(amount) of sales.
> 
> 2. For each items in the date range the number(amount) of sales.
> 
> Example:  
> From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the  
> number of sales is 25  
> From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the  
> number of sales of item AAA is 30
> 
> My Output is Like  
> From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> the number of sales is 25 and the sales of item AAA is 30.
> 
> How can I get this using Facets Elasticsearch?
> 
> Thanks in Advance!
> 
> Cheers!
> 
> George
> 
> That is,
> 
> On Apr 24, 7:23 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> 
> > Your first example looks like statistical facet response, not  
> > date histogram facet response. So, I am not quite sure what information  
> > you  
> > are trying to retrieve. What's the type of the field that you are  
> > running  
> > these facet queries on? Can you provide a more detailed example of what  
> > you  
> > are trying to achieve?
> > 
> > On Monday, April 23, 2012 11:51:26 PM UTC-4, George Viju wrote:
> > 
> > > Thank you Igor Motov! In my case, I need to combine the Date  
> > > Histogram and Term Facet
> > 
> > > It is like.
> > 
> > > 1. Daterange and the count of matches similar to  
> > > createddate" : {  
> > > "\_type" : "statistical",  
> > > "count" : 158,  
> > > "total" : 2.10720682311E14,  
> > > "min" : 1.3332708E12,  
> > > "max" : 1.3340484E12,  
> > > "mean" : 1.3336752045E12,  
> > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > "variance" : 6.30332803714792E16,  
> > > "std\_deviation" : 2.510642952940127E8  
> > > }
> > > 2. The number number of items and the matches count similar to  
> > > "facets" : {  
> > > "itemscount" : {  
> > > "\_type" : "terms",  
> > > "missing" : 0,  
> > > "total" : 3492,  
> > > "other" : 0,  
> > > "terms" : [ {  
> > > "term" : 1,  
> > > "count" : 3022  
> > > }, {  
> > > "term" : 2,  
> > > "count" : 247  
> > > }, {  
> > > "term" : 6,  
> > > "count" : 154  
> > > }, {  
> > > "term" : 3,  
> > > "count" : 28  
> > > }, {  
> > > "term" : 5,  
> > > "count" : 27  
> > > }, {  
> > > "term" : 4,  
> > > "count" : 14  
> > > } ]  
> > > },
> > 
> > > How can I combine these two as a single Facet?
> > 
> > > Cheers!
> > 
> > > George
> > 
> > > On Apr 23, 8:30 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > 
> > > > Not sure I understood your question. If you are trying to combine  
> > > > statistical and histogram facets in the same facet, it's not  
> > > > possible.  
> > > > However, you can send multiple facet requests in the same search  
> > > > request:
> > 
> > > > {  
> > > > "query" : {  
> > > > "match\_all" : {}  
> > > > },  
> > > > "facets" : {  
> > > > "stat1" : {  
> > > > "statistical" : {  
> > > > . . .  
> > > > }  
> > > > },  
> > > > "histo1" : {  
> > > > "date\_histogram" : {  
> > > > . . .  
> > > > }  
> > > > }  
> > > > }
> > 
> > > > }  
> > > > On Saturday, April 21, 2012 7:41:22 AM UTC-4, George Viju wrote:
> > 
> > > > > Hi,  
> > > > > How to combine two type of facets together as a single facet  
> > > > > in  
> > > > > elasticsearch?
> > 
> > > > > Cheers!
> > 
> > > > > George
> > 
> > > > > On Apr 20, 7:46 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> > > > > 
> > > > > > Hi,  
> > > > > > I am using DateHistogram Facet for getting the Daterange  
> > > > > > and  
> > > > > > items. For Example
> > 
> > > > > > In DateHistogram Facet we can get the number of data or count  
> > > > > > within the selected date range. In my application I need to get  
> > > > > > both  
> > > > > > the
> > 
> > > > > > 1. Daterange and the count of matches similar to
> > 
> > > > > > createddate" : {  
> > > > > > "\_type" : "statistical",  
> > > > > > "count" : 158,  
> > > > > > "total" : 2.10720682311E14,  
> > > > > > "min" : 1.3332708E12,  
> > > > > > "max" : 1.3340484E12,  
> > > > > > "mean" : 1.3336752045E12,  
> > > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > > "variance" : 6.30332803714792E16,  
> > > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > > }
> > 
> > > > > > 1. The number number of items and the matches count similar to
> > 
> > > > > > "facets" : {  
> > > > > > "itemscount" : {  
> > > > > > "\_type" : "terms",  
> > > > > > "missing" : 0,  
> > > > > > "total" : 3492,  
> > > > > > "other" : 0,  
> > > > > > "terms" : [ {  
> > > > > > "term" : 1,  
> > > > > > "count" : 3022  
> > > > > > }, {  
> > > > > > "term" : 2,  
> > > > > > "count" : 247  
> > > > > > }, {  
> > > > > > "term" : 6,  
> > > > > > "count" : 154  
> > > > > > }, {  
> > > > > > "term" : 3,  
> > > > > > "count" : 28  
> > > > > > }, {  
> > > > > > "term" : 5,  
> > > > > > "count" : 27  
> > > > > > }, {  
> > > > > > "term" : 4,  
> > > > > > "count" : 14  
> > > > > > } ]  
> > > > > > },
> > 
> > > > > > Can this two things will get by a single facet? How can I get  
> > > > > > this  
> > > > > > using facet?
> > 
> > > > > > Cheers!
> > 
> > > > > > George

---

<div class="post-metadata">

**Author:** ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)\
**Post date:** [April 25, 2012, 3:56am UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422/8 "2012-04-25T03:56:46Z")

</div>

Thank You Igor Motov! Here I am using single date range per request.

Cheers!

George

On Apr 24, 9:00 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:

> Are you going to have multiple ranges per request or a single range per  
> request?
> 
> On Tuesday, April 24, 2012 11:18:42 AM UTC-4, George Viju wrote:
> 
> > Thank You Igor Motov! . I have the parameters should be be found  
> > like -- createddaterange vs sales and items (in the createddaterange)  
> > vs sales ,
> 
> > Here I need to find,
> 
> > 1. For each date range the number(amount) of sales.
> 
> > 1. For each items in the date range the number(amount) of sales.
> 
> > Example:  
> > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the  
> > number of sales is 25  
> > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the  
> > number of sales of item AAA is 30
> 
> > My Output is Like  
> > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > the number of sales is 25 and the sales of item AAA is 30.
> 
> > How can I get this using Facets Elasticsearch?
> 
> > Thanks in Advance!
> 
> > Cheers!
> 
> > George
> 
> > That is,
> 
> > On Apr 24, 7:23 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > 
> > > Your first example looks like statistical facet response, not  
> > > date histogram facet response. So, I am not quite sure what information  
> > > you  
> > > are trying to retrieve. What's the type of the field that you are  
> > > running  
> > > these facet queries on? Can you provide a more detailed example of what  
> > > you  
> > > are trying to achieve?
> 
> > > On Monday, April 23, 2012 11:51:26 PM UTC-4, George Viju wrote:
> 
> > > > Thank you Igor Motov! In my case, I need to combine the Date  
> > > > Histogram and Term Facet
> 
> > > > It is like.
> 
> > > > 1. Daterange and the count of matches similar to  
> > > > createddate" : {  
> > > > "\_type" : "statistical",  
> > > > "count" : 158,  
> > > > "total" : 2.10720682311E14,  
> > > > "min" : 1.3332708E12,  
> > > > "max" : 1.3340484E12,  
> > > > "mean" : 1.3336752045E12,  
> > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > "variance" : 6.30332803714792E16,  
> > > > "std\_deviation" : 2.510642952940127E8  
> > > > }
> > > > 2. The number number of items and the matches count similar to  
> > > > "facets" : {  
> > > > "itemscount" : {  
> > > > "\_type" : "terms",  
> > > > "missing" : 0,  
> > > > "total" : 3492,  
> > > > "other" : 0,  
> > > > "terms" : [ {  
> > > > "term" : 1,  
> > > > "count" : 3022  
> > > > }, {  
> > > > "term" : 2,  
> > > > "count" : 247  
> > > > }, {  
> > > > "term" : 6,  
> > > > "count" : 154  
> > > > }, {  
> > > > "term" : 3,  
> > > > "count" : 28  
> > > > }, {  
> > > > "term" : 5,  
> > > > "count" : 27  
> > > > }, {  
> > > > "term" : 4,  
> > > > "count" : 14  
> > > > } ]  
> > > > },
> 
> > > > How can I combine these two as a single Facet?
> 
> > > > Cheers!
> 
> > > > George
> 
> > > > On Apr 23, 8:30 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > 
> > > > > Not sure I understood your question. If you are trying to combine  
> > > > > statistical and histogram facets in the same facet, it's not  
> > > > > possible.  
> > > > > However, you can send multiple facet requests in the same search  
> > > > > request:
> 
> > > > > {  
> > > > > "query" : {  
> > > > > "match\_all" : {}  
> > > > > },  
> > > > > "facets" : {  
> > > > > "stat1" : {  
> > > > > "statistical" : {  
> > > > > . . .  
> > > > > }  
> > > > > },  
> > > > > "histo1" : {  
> > > > > "date\_histogram" : {  
> > > > > . . .  
> > > > > }  
> > > > > }  
> > > > > }
> 
> > > > > }  
> > > > > On Saturday, April 21, 2012 7:41:22 AM UTC-4, George Viju wrote:
> 
> > > > > > Hi,  
> > > > > > How to combine two type of facets together as a single facet  
> > > > > > in  
> > > > > > elasticsearch?
> 
> > > > > > Cheers!
> 
> > > > > > George
> 
> > > > > > On Apr 20, 7:46 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> > > > > > 
> > > > > > > Hi,  
> > > > > > > I am using DateHistogram Facet for getting the Daterange  
> > > > > > > and  
> > > > > > > items. For Example
> 
> > > > > > > In DateHistogram Facet we can get the number of data or count  
> > > > > > > within the selected date range. In my application I need to get  
> > > > > > > both  
> > > > > > > the
> 
> > > > > > > 1. Daterange and the count of matches similar to
> 
> > > > > > > createddate" : {  
> > > > > > > "\_type" : "statistical",  
> > > > > > > "count" : 158,  
> > > > > > > "total" : 2.10720682311E14,  
> > > > > > > "min" : 1.3332708E12,  
> > > > > > > "max" : 1.3340484E12,  
> > > > > > > "mean" : 1.3336752045E12,  
> > > > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > > > "variance" : 6.30332803714792E16,  
> > > > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > > > }
> 
> > > > > > > 1. The number number of items and the matches count similar to
> 
> > > > > > > "facets" : {  
> > > > > > > "itemscount" : {  
> > > > > > > "\_type" : "terms",  
> > > > > > > "missing" : 0,  
> > > > > > > "total" : 3492,  
> > > > > > > "other" : 0,  
> > > > > > > "terms" : [ {  
> > > > > > > "term" : 1,  
> > > > > > > "count" : 3022  
> > > > > > > }, {  
> > > > > > > "term" : 2,  
> > > > > > > "count" : 247  
> > > > > > > }, {  
> > > > > > > "term" : 6,  
> > > > > > > "count" : 154  
> > > > > > > }, {  
> > > > > > > "term" : 3,  
> > > > > > > "count" : 28  
> > > > > > > }, {  
> > > > > > > "term" : 5,  
> > > > > > > "count" : 27  
> > > > > > > }, {  
> > > > > > > "term" : 4,  
> > > > > > > "count" : 14  
> > > > > > > } ]  
> > > > > > > },
> 
> > > > > > > Can this two things will get by a single facet? How can I get  
> > > > > > > this  
> > > > > > > using facet?
> 
> > > > > > > Cheers!
> 
> > > > > > > George

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [April 25, 2012, 6:58am UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422/9 "2012-04-25T06:58:43Z")

</div>

I think I have started to understand what you are trying to achieve, but I  
am still a little bit confused about "sale". In your example, for the same  
period of time the total number of sales (25) is smaller than the number of  
sales for one item (30). How is this possible and how are sales  
represented/stored in your index?

On Tuesday, April 24, 2012 11:56:46 PM UTC-4, George Viju wrote:

> Thank You Igor Motov! Here I am using single date range per request.
> 
> Cheers!
> 
> George
> 
> On Apr 24, 9:00 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> 
> > Are you going to have multiple ranges per request or a single range per  
> > request?
> > 
> > On Tuesday, April 24, 2012 11:18:42 AM UTC-4, George Viju wrote:
> > 
> > > Thank You Igor Motov! . I have the parameters should be be found  
> > > like -- createddaterange vs sales and items (in the createddaterange)  
> > > vs sales ,
> > 
> > > Here I need to find,
> > 
> > > 1. For each date range the number(amount) of sales.
> > 
> > > 1. For each items in the date range the number(amount) of sales.
> > 
> > > Example:  
> > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the  
> > > number of sales is 25  
> > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the  
> > > number of sales of item AAA is 30
> > 
> > > My Output is Like  
> > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > > the number of sales is 25 and the sales of item AAA is 30.
> > 
> > > How can I get this using Facets Elasticsearch?
> > 
> > > Thanks in Advance!
> > 
> > > Cheers!
> > 
> > > George
> > 
> > > That is,
> > 
> > > On Apr 24, 7:23 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > 
> > > > Your first example looks like statistical facet response, not  
> > > > date histogram facet response. So, I am not quite sure what  
> > > > information  
> > > > you  
> > > > are trying to retrieve. What's the type of the field that you are  
> > > > running  
> > > > these facet queries on? Can you provide a more detailed example of  
> > > > what  
> > > > you  
> > > > are trying to achieve?
> > 
> > > > On Monday, April 23, 2012 11:51:26 PM UTC-4, George Viju wrote:
> > 
> > > > > Thank you Igor Motov! In my case, I need to combine the  
> > > > > Date  
> > > > > Histogram and Term Facet
> > 
> > > > > It is like.
> > 
> > > > > 1. Daterange and the count of matches similar to  
> > > > > createddate" : {  
> > > > > "\_type" : "statistical",  
> > > > > "count" : 158,  
> > > > > "total" : 2.10720682311E14,  
> > > > > "min" : 1.3332708E12,  
> > > > > "max" : 1.3340484E12,  
> > > > > "mean" : 1.3336752045E12,  
> > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > "variance" : 6.30332803714792E16,  
> > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > }
> > > > > 2. The number number of items and the matches count similar to  
> > > > > "facets" : {  
> > > > > "itemscount" : {  
> > > > > "\_type" : "terms",  
> > > > > "missing" : 0,  
> > > > > "total" : 3492,  
> > > > > "other" : 0,  
> > > > > "terms" : [ {  
> > > > > "term" : 1,  
> > > > > "count" : 3022  
> > > > > }, {  
> > > > > "term" : 2,  
> > > > > "count" : 247  
> > > > > }, {  
> > > > > "term" : 6,  
> > > > > "count" : 154  
> > > > > }, {  
> > > > > "term" : 3,  
> > > > > "count" : 28  
> > > > > }, {  
> > > > > "term" : 5,  
> > > > > "count" : 27  
> > > > > }, {  
> > > > > "term" : 4,  
> > > > > "count" : 14  
> > > > > } ]  
> > > > > },
> > 
> > > > > How can I combine these two as a single Facet?
> > 
> > > > > Cheers!
> > 
> > > > > George
> > 
> > > > > On Apr 23, 8:30 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > 
> > > > > > Not sure I understood your question. If you are trying to  
> > > > > > combine  
> > > > > > statistical and histogram facets in the same facet, it's not  
> > > > > > possible.  
> > > > > > However, you can send multiple facet requests in the same search  
> > > > > > request:
> > 
> > > > > > {  
> > > > > > "query" : {  
> > > > > > "match\_all" : {}  
> > > > > > },  
> > > > > > "facets" : {  
> > > > > > "stat1" : {  
> > > > > > "statistical" : {  
> > > > > > . . .  
> > > > > > }  
> > > > > > },  
> > > > > > "histo1" : {  
> > > > > > "date\_histogram" : {  
> > > > > > . . .  
> > > > > > }  
> > > > > > }  
> > > > > > }
> > 
> > > > > > }  
> > > > > > On Saturday, April 21, 2012 7:41:22 AM UTC-4, George Viju wrote:
> > 
> > > > > > > Hi,  
> > > > > > > How to combine two type of facets together as a single  
> > > > > > > facet  
> > > > > > > in  
> > > > > > > elasticsearch?
> > 
> > > > > > > Cheers!
> > 
> > > > > > > George
> > 
> > > > > > > On Apr 20, 7:46 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> > > > > > > 
> > > > > > > > Hi,  
> > > > > > > > I am using DateHistogram Facet for getting the  
> > > > > > > > Daterange  
> > > > > > > > and  
> > > > > > > > items. For Example
> > 
> > > > > > > > In DateHistogram Facet we can get the number of data or  
> > > > > > > > count  
> > > > > > > > within the selected date range. In my application I need to  
> > > > > > > > get  
> > > > > > > > both  
> > > > > > > > the
> > 
> > > > > > > > 1. Daterange and the count of matches similar to
> > 
> > > > > > > > createddate" : {  
> > > > > > > > "\_type" : "statistical",  
> > > > > > > > "count" : 158,  
> > > > > > > > "total" : 2.10720682311E14,  
> > > > > > > > "min" : 1.3332708E12,  
> > > > > > > > "max" : 1.3340484E12,  
> > > > > > > > "mean" : 1.3336752045E12,  
> > > > > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > > > > "variance" : 6.30332803714792E16,  
> > > > > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > > > > }
> > 
> > > > > > > > 1. The number number of items and the matches count similar  
> > > > > > > > to
> > 
> > > > > > > > "facets" : {  
> > > > > > > > "itemscount" : {  
> > > > > > > > "\_type" : "terms",  
> > > > > > > > "missing" : 0,  
> > > > > > > > "total" : 3492,  
> > > > > > > > "other" : 0,  
> > > > > > > > "terms" : [ {  
> > > > > > > > "term" : 1,  
> > > > > > > > "count" : 3022  
> > > > > > > > }, {  
> > > > > > > > "term" : 2,  
> > > > > > > > "count" : 247  
> > > > > > > > }, {  
> > > > > > > > "term" : 6,  
> > > > > > > > "count" : 154  
> > > > > > > > }, {  
> > > > > > > > "term" : 3,  
> > > > > > > > "count" : 28  
> > > > > > > > }, {  
> > > > > > > > "term" : 5,  
> > > > > > > > "count" : 27  
> > > > > > > > }, {  
> > > > > > > > "term" : 4,  
> > > > > > > > "count" : 14  
> > > > > > > > } ]  
> > > > > > > > },
> > 
> > > > > > > > Can this two things will get by a single facet? How can I  
> > > > > > > > get  
> > > > > > > > this  
> > > > > > > > using facet?
> > 
> > > > > > > > Cheers!
> > 
> > > > > > > > George

---

<div class="post-metadata">

**Author:** ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)\
**Post date:** [April 25, 2012, 8:58am UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422/10 "2012-04-25T08:58:34Z")

</div>

I am sorry Igor Motov. Thanks for notifying this. Please read the  
Example as:

```
 From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the

```

number of sales is 30  
From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the  
number of sales of item AAA is 25

My Output is Like  
From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
the number of sales is 30 and the sales of item AAA is 25.

Cheers!

George

On Apr 25, 11:58 am, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:

> I think I have started to understand what you are trying to achieve, but I  
> am still a little bit confused about "sale". In your example, for the same  
> period of time the total number of sales (25) is smaller than the number of  
> sales for one item (30). How is this possible and how are sales  
> represented/stored in your index?
> 
> On Tuesday, April 24, 2012 11:56:46 PM UTC-4, George Viju wrote:
> 
> > Thank You Igor Motov! Here I am using single date range per request.
> 
> > Cheers!
> 
> > George
> 
> > On Apr 24, 9:00 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > 
> > > Are you going to have multiple ranges per request or a single range per  
> > > request?
> 
> > > On Tuesday, April 24, 2012 11:18:42 AM UTC-4, George Viju wrote:
> 
> > > > Thank You Igor Motov! . I have the parameters should be be found  
> > > > like -- createddaterange vs sales and items (in the createddaterange)  
> > > > vs sales ,
> 
> > > > Here I need to find,
> 
> > > > 1. For each date range the number(amount) of sales.
> 
> > > > 1. For each items in the date range the number(amount) of sales.
> 
> > > > Example:  
> > > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the  
> > > > number of sales is 25  
> > > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the  
> > > > number of sales of item AAA is 30
> 
> > > > My Output is Like  
> > > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > > > the number of sales is 25 and the sales of item AAA is 30.
> 
> > > > How can I get this using Facets Elasticsearch?
> 
> > > > Thanks in Advance!
> 
> > > > Cheers!
> 
> > > > George
> 
> > > > That is,
> 
> > > > On Apr 24, 7:23 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > 
> > > > > Your first example looks like statistical facet response, not  
> > > > > date histogram facet response. So, I am not quite sure what  
> > > > > information  
> > > > > you  
> > > > > are trying to retrieve. What's the type of the field that you are  
> > > > > running  
> > > > > these facet queries on? Can you provide a more detailed example of  
> > > > > what  
> > > > > you  
> > > > > are trying to achieve?
> 
> > > > > On Monday, April 23, 2012 11:51:26 PM UTC-4, George Viju wrote:
> 
> > > > > > Thank you Igor Motov! In my case, I need to combine the  
> > > > > > Date  
> > > > > > Histogram and Term Facet
> 
> > > > > > It is like.
> 
> > > > > > 1. Daterange and the count of matches similar to  
> > > > > > createddate" : {  
> > > > > > "\_type" : "statistical",  
> > > > > > "count" : 158,  
> > > > > > "total" : 2.10720682311E14,  
> > > > > > "min" : 1.3332708E12,  
> > > > > > "max" : 1.3340484E12,  
> > > > > > "mean" : 1.3336752045E12,  
> > > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > > "variance" : 6.30332803714792E16,  
> > > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > > }
> > > > > > 2. The number number of items and the matches count similar to  
> > > > > > "facets" : {  
> > > > > > "itemscount" : {  
> > > > > > "\_type" : "terms",  
> > > > > > "missing" : 0,  
> > > > > > "total" : 3492,  
> > > > > > "other" : 0,  
> > > > > > "terms" : [ {  
> > > > > > "term" : 1,  
> > > > > > "count" : 3022  
> > > > > > }, {  
> > > > > > "term" : 2,  
> > > > > > "count" : 247  
> > > > > > }, {  
> > > > > > "term" : 6,  
> > > > > > "count" : 154  
> > > > > > }, {  
> > > > > > "term" : 3,  
> > > > > > "count" : 28  
> > > > > > }, {  
> > > > > > "term" : 5,  
> > > > > > "count" : 27  
> > > > > > }, {  
> > > > > > "term" : 4,  
> > > > > > "count" : 14  
> > > > > > } ]  
> > > > > > },
> 
> > > > > > How can I combine these two as a single Facet?
> 
> > > > > > Cheers!
> 
> > > > > > George
> 
> > > > > > On Apr 23, 8:30 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > > 
> > > > > > > Not sure I understood your question. If you are trying to  
> > > > > > > combine  
> > > > > > > statistical and histogram facets in the same facet, it's not  
> > > > > > > possible.  
> > > > > > > However, you can send multiple facet requests in the same search  
> > > > > > > request:
> 
> > > > > > > {  
> > > > > > > "query" : {  
> > > > > > > "match\_all" : {}  
> > > > > > > },  
> > > > > > > "facets" : {  
> > > > > > > "stat1" : {  
> > > > > > > "statistical" : {  
> > > > > > > . . .  
> > > > > > > }  
> > > > > > > },  
> > > > > > > "histo1" : {  
> > > > > > > "date\_histogram" : {  
> > > > > > > . . .  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }
> 
> > > > > > > }  
> > > > > > > On Saturday, April 21, 2012 7:41:22 AM UTC-4, George Viju wrote:
> 
> > > > > > > > Hi,  
> > > > > > > > How to combine two type of facets together as a single  
> > > > > > > > facet  
> > > > > > > > in  
> > > > > > > > elasticsearch?
> 
> > > > > > > > Cheers!
> 
> > > > > > > > George
> 
> > > > > > > > On Apr 20, 7:46 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> > > > > > > > 
> > > > > > > > > Hi,  
> > > > > > > > > I am using DateHistogram Facet for getting the  
> > > > > > > > > Daterange  
> > > > > > > > > and  
> > > > > > > > > items. For Example
> 
> > > > > > > > > In DateHistogram Facet we can get the number of data or  
> > > > > > > > > count  
> > > > > > > > > within the selected date range. In my application I need to  
> > > > > > > > > get  
> > > > > > > > > both  
> > > > > > > > > the
> 
> > > > > > > > > 1. Daterange and the count of matches similar to
> 
> > > > > > > > > createddate" : {  
> > > > > > > > > "\_type" : "statistical",  
> > > > > > > > > "count" : 158,  
> > > > > > > > > "total" : 2.10720682311E14,  
> > > > > > > > > "min" : 1.3332708E12,  
> > > > > > > > > "max" : 1.3340484E12,  
> > > > > > > > > "mean" : 1.3336752045E12,  
> > > > > > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > > > > > "variance" : 6.30332803714792E16,  
> > > > > > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > > > > > }
> 
> > > > > > > > > 1. The number number of items and the matches count similar  
> > > > > > > > > to
> 
> > > > > > > > > "facets" : {  
> > > > > > > > > "itemscount" : {  
> > > > > > > > > "\_type" : "terms",  
> > > > > > > > > "missing" : 0,  
> > > > > > > > > "total" : 3492,  
> > > > > > > > > "other" : 0,  
> > > > > > > > > "terms" : [ {  
> > > > > > > > > "term" : 1,  
> > > > > > > > > "count" : 3022  
> > > > > > > > > }, {  
> > > > > > > > > "term" : 2,  
> > > > > > > > > "count" : 247  
> > > > > > > > > }, {  
> > > > > > > > > "term" : 6,  
> > > > > > > > > "count" : 154  
> > > > > > > > > }, {  
> > > > > > > > > "term" : 3,  
> > > > > > > > > "count" : 28  
> > > > > > > > > }, {  
> > > > > > > > > "term" : 5,  
> > > > > > > > > "count" : 27  
> > > > > > > > > }, {  
> > > > > > > > > "term" : 4,  
> > > > > > > > > "count" : 14  
> > > > > > > > > } ]  
> > > > > > > > > },
> 
> > > > > > > > > Can this two things will get by a single facet? How can I  
> > > > > > > > > get  
> > > > > > > > > this  
> > > > > > > > > using facet?
> 
> > > > > > > > > Cheers!
> 
> > > > > > > > > George

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [April 25, 2012, 1:28pm UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422/11 "2012-04-25T13:28:38Z")

</div>

In this case, all you need to do is to run terms facet with query that  
limits results to your date range. The facets will contain number of sales  
per term, and the total number of sales will be equal to total number of  
hits.

{  
.....  
"hits" : {

- "total" : 7, \<--- This is total number of records\*  
"max\_score" : 1.0,  
"hits" :   
},  
"facets" : {  
"term" : {  
"\_type" : "terms",  
"missing" : 0,  
"total" : 7, \<-- This is total number of terms, it will be equal to  
the number above if you have one term per record  
"other" : 0,  
"terms" : [ {  
"term" : "AAA",  
"count" : 6  
}, {  
"term" : "BBB",  
"count" : 1  
} ]  
}  
}  
}

On Wednesday, April 25, 2012 4:58:34 AM UTC-4, George Viju wrote:

> I am sorry Igor Motov. Thanks for notifying this. Please read the  
> Example as:
> 
> ```
> From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the 
> 
> ```
> 
> number of sales is 30  
> From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the  
> number of sales of item AAA is 25
> 
> My Output is Like  
> From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> the number of sales is 30 and the sales of item AAA is 25.
> 
> Cheers!
> 
> George
> 
> On Apr 25, 11:58 am, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> 
> > I think I have started to understand what you are trying to achieve, but  
> > I  
> > am still a little bit confused about "sale". In your example, for the  
> > same  
> > period of time the total number of sales (25) is smaller than the number  
> > of  
> > sales for one item (30). How is this possible and how are sales  
> > represented/stored in your index?
> > 
> > On Tuesday, April 24, 2012 11:56:46 PM UTC-4, George Viju wrote:
> > 
> > > Thank You Igor Motov! Here I am using single date range per request.
> > 
> > > Cheers!
> > 
> > > George
> > 
> > > On Apr 24, 9:00 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > 
> > > > Are you going to have multiple ranges per request or a single range  
> > > > per  
> > > > request?
> > 
> > > > On Tuesday, April 24, 2012 11:18:42 AM UTC-4, George Viju wrote:
> > 
> > > > > Thank You Igor Motov! . I have the parameters should be be found  
> > > > > like -- createddaterange vs sales and items (in the  
> > > > > createddaterange)  
> > > > > vs sales ,
> > 
> > > > > Here I need to find,
> > 
> > > > > 1. For each date range the number(amount) of sales.
> > 
> > > > > 1. For each items in the date range the number(amount) of sales.
> > 
> > > > > Example:  
> > > > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > > > > the  
> > > > > number of sales is 25  
> > > > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > > > > the  
> > > > > number of sales of item AAA is 30
> > 
> > > > > My Output is Like  
> > > > > From April 20, 2012 11:51:26 to April 23, 2012  
> > > > > 11:51:26  
> > > > > the number of sales is 25 and the sales of item AAA is 30.
> > 
> > > > > How can I get this using Facets Elasticsearch?
> > 
> > > > > Thanks in Advance!
> > 
> > > > > Cheers!
> > 
> > > > > George
> > 
> > > > > That is,
> > 
> > > > > On Apr 24, 7:23 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > 
> > > > > > Your first example looks like statistical facet response, not  
> > > > > > date histogram facet response. So, I am not quite sure what  
> > > > > > information  
> > > > > > you  
> > > > > > are trying to retrieve. What's the type of the field that you  
> > > > > > are  
> > > > > > running  
> > > > > > these facet queries on? Can you provide a more detailed example  
> > > > > > of  
> > > > > > what  
> > > > > > you  
> > > > > > are trying to achieve?
> > 
> > > > > > On Monday, April 23, 2012 11:51:26 PM UTC-4, George Viju wrote:
> > 
> > > > > > > Thank you Igor Motov! In my case, I need to combine the  
> > > > > > > Date  
> > > > > > > Histogram and Term Facet
> > 
> > > > > > > It is like.
> > 
> > > > > > > 1. Daterange and the count of matches similar to  
> > > > > > > createddate" : {  
> > > > > > > "\_type" : "statistical",  
> > > > > > > "count" : 158,  
> > > > > > > "total" : 2.10720682311E14,  
> > > > > > > "min" : 1.3332708E12,  
> > > > > > > "max" : 1.3340484E12,  
> > > > > > > "mean" : 1.3336752045E12,  
> > > > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > > > "variance" : 6.30332803714792E16,  
> > > > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > > > }
> > > > > > > 2. The number number of items and the matches count similar  
> > > > > > > to  
> > > > > > > "facets" : {  
> > > > > > > "itemscount" : {  
> > > > > > > "\_type" : "terms",  
> > > > > > > "missing" : 0,  
> > > > > > > "total" : 3492,  
> > > > > > > "other" : 0,  
> > > > > > > "terms" : [ {  
> > > > > > > "term" : 1,  
> > > > > > > "count" : 3022  
> > > > > > > }, {  
> > > > > > > "term" : 2,  
> > > > > > > "count" : 247  
> > > > > > > }, {  
> > > > > > > "term" : 6,  
> > > > > > > "count" : 154  
> > > > > > > }, {  
> > > > > > > "term" : 3,  
> > > > > > > "count" : 28  
> > > > > > > }, {  
> > > > > > > "term" : 5,  
> > > > > > > "count" : 27  
> > > > > > > }, {  
> > > > > > > "term" : 4,  
> > > > > > > "count" : 14  
> > > > > > > } ]  
> > > > > > > },
> > 
> > > > > > > How can I combine these two as a single Facet?
> > 
> > > > > > > Cheers!
> > 
> > > > > > > George
> > 
> > > > > > > On Apr 23, 8:30 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > > > 
> > > > > > > > Not sure I understood your question. If you are trying to  
> > > > > > > > combine  
> > > > > > > > statistical and histogram facets in the same facet, it's not  
> > > > > > > > possible.  
> > > > > > > > However, you can send multiple facet requests in the same  
> > > > > > > > search  
> > > > > > > > request:
> > 
> > > > > > > > {  
> > > > > > > > "query" : {  
> > > > > > > > "match\_all" : {}  
> > > > > > > > },  
> > > > > > > > "facets" : {  
> > > > > > > > "stat1" : {  
> > > > > > > > "statistical" : {  
> > > > > > > > . . .  
> > > > > > > > }  
> > > > > > > > },  
> > > > > > > > "histo1" : {  
> > > > > > > > "date\_histogram" : {  
> > > > > > > > . . .  
> > > > > > > > }  
> > > > > > > > }  
> > > > > > > > }
> > 
> > > > > > > > }  
> > > > > > > > On Saturday, April 21, 2012 7:41:22 AM UTC-4, George Viju  
> > > > > > > > wrote:
> > 
> > > > > > > > > Hi,  
> > > > > > > > > How to combine two type of facets together as a  
> > > > > > > > > single  
> > > > > > > > > facet  
> > > > > > > > > in  
> > > > > > > > > elasticsearch?
> > 
> > > > > > > > > Cheers!
> > 
> > > > > > > > > George
> > 
> > > > > > > > > On Apr 20, 7:46 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com)  
> > > > > > > > > wrote:
> > > > > > > > > 
> > > > > > > > > > Hi,  
> > > > > > > > > > I am using DateHistogram Facet for getting the  
> > > > > > > > > > Daterange  
> > > > > > > > > > and  
> > > > > > > > > > items. For Example
> > 
> > > > > > > > > > In DateHistogram Facet we can get the number of data  
> > > > > > > > > > or  
> > > > > > > > > > count  
> > > > > > > > > > within the selected date range. In my application I need  
> > > > > > > > > > to  
> > > > > > > > > > get  
> > > > > > > > > > both  
> > > > > > > > > > the
> > 
> > > > > > > > > > 1. Daterange and the count of matches similar to
> > 
> > > > > > > > > > createddate" : {  
> > > > > > > > > > "\_type" : "statistical",  
> > > > > > > > > > "count" : 158,  
> > > > > > > > > > "total" : 2.10720682311E14,  
> > > > > > > > > > "min" : 1.3332708E12,  
> > > > > > > > > > "max" : 1.3340484E12,  
> > > > > > > > > > "mean" : 1.3336752045E12,  
> > > > > > > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > > > > > > "variance" : 6.30332803714792E16,  
> > > > > > > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > > > > > > }
> > 
> > > > > > > > > > 1. The number number of items and the matches count  
> > > > > > > > > > similar  
> > > > > > > > > > to
> > 
> > > > > > > > > > "facets" : {  
> > > > > > > > > > "itemscount" : {  
> > > > > > > > > > "\_type" : "terms",  
> > > > > > > > > > "missing" : 0,  
> > > > > > > > > > "total" : 3492,  
> > > > > > > > > > "other" : 0,  
> > > > > > > > > > "terms" : [ {  
> > > > > > > > > > "term" : 1,  
> > > > > > > > > > "count" : 3022  
> > > > > > > > > > }, {  
> > > > > > > > > > "term" : 2,  
> > > > > > > > > > "count" : 247  
> > > > > > > > > > }, {  
> > > > > > > > > > "term" : 6,  
> > > > > > > > > > "count" : 154  
> > > > > > > > > > }, {  
> > > > > > > > > > "term" : 3,  
> > > > > > > > > > "count" : 28  
> > > > > > > > > > }, {  
> > > > > > > > > > "term" : 5,  
> > > > > > > > > > "count" : 27  
> > > > > > > > > > }, {  
> > > > > > > > > > "term" : 4,  
> > > > > > > > > > "count" : 14  
> > > > > > > > > > } ]  
> > > > > > > > > > },
> > 
> > > > > > > > > > Can this two things will get by a single facet? How can  
> > > > > > > > > > I  
> > > > > > > > > > get  
> > > > > > > > > > this  
> > > > > > > > > > using facet?
> > 
> > > > > > > > > > Cheers!
> > 
> > > > > > > > > > George

---

<div class="post-metadata">

**Author:** ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)\
**Post date:** [April 25, 2012, 1:44pm UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422/12 "2012-04-25T13:44:49Z")

</div>

Thank you Igor Motov! Could it be possible for Multiple date ranges  
per request (in the same Example)?

Thanks in Advance!

Cheers!

George  
On Apr 25, 6:28 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:

> In this case, all you need to do is to run terms facet with query that  
> limits results to your date range. The facets will contain number of sales  
> per term, and the total number of sales will be equal to total number of  
> hits.
> 
> {  
> .....  
> "hits" : {
> 
> - "total" : 7, \<--- This is total number of records\*  
> "max\_score" : 1.0,  
> "hits" :   
> },  
> "facets" : {  
> "term" : {  
> "\_type" : "terms",  
> "missing" : 0,  
> "total" : 7, \<-- This is total number of terms, it will be equal to  
> the number above if you have one term per record  
> "other" : 0,  
> "terms" : [ {  
> "term" : "AAA",  
> "count" : 6  
> }, {  
> "term" : "BBB",  
> "count" : 1  
> } ]  
> }  
> }
> 
> }  
> On Wednesday, April 25, 2012 4:58:34 AM UTC-4, George Viju wrote:
> 
> > I am sorry Igor Motov. Thanks for notifying this. Please read the  
> > Example as:
> 
> > ```
> > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the
> > 
> > ```
> > 
> > number of sales is 30  
> > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the  
> > number of sales of item AAA is 25
> 
> > My Output is Like  
> > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > the number of sales is 30 and the sales of item AAA is 25.
> 
> > Cheers!
> 
> > George
> 
> > On Apr 25, 11:58 am, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > 
> > > I think I have started to understand what you are trying to achieve, but  
> > > I  
> > > am still a little bit confused about "sale". In your example, for the  
> > > same  
> > > period of time the total number of sales (25) is smaller than the number  
> > > of  
> > > sales for one item (30). How is this possible and how are sales  
> > > represented/stored in your index?
> 
> > > On Tuesday, April 24, 2012 11:56:46 PM UTC-4, George Viju wrote:
> 
> > > > Thank You Igor Motov! Here I am using single date range per request.
> 
> > > > Cheers!
> 
> > > > George
> 
> > > > On Apr 24, 9:00 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > 
> > > > > Are you going to have multiple ranges per request or a single range  
> > > > > per  
> > > > > request?
> 
> > > > > On Tuesday, April 24, 2012 11:18:42 AM UTC-4, George Viju wrote:
> 
> > > > > > Thank You Igor Motov! . I have the parameters should be be found  
> > > > > > like -- createddaterange vs sales and items (in the  
> > > > > > createddaterange)  
> > > > > > vs sales ,
> 
> > > > > > Here I need to find,
> 
> > > > > > 1. For each date range the number(amount) of sales.
> 
> > > > > > 1. For each items in the date range the number(amount) of sales.
> 
> > > > > > Example:  
> > > > > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > > > > > the  
> > > > > > number of sales is 25  
> > > > > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > > > > > the  
> > > > > > number of sales of item AAA is 30
> 
> > > > > > My Output is Like  
> > > > > > From April 20, 2012 11:51:26 to April 23, 2012  
> > > > > > 11:51:26  
> > > > > > the number of sales is 25 and the sales of item AAA is 30.
> 
> > > > > > How can I get this using Facets Elasticsearch?
> 
> > > > > > Thanks in Advance!
> 
> > > > > > Cheers!
> 
> > > > > > George
> 
> > > > > > That is,
> 
> > > > > > On Apr 24, 7:23 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > > 
> > > > > > > Your first example looks like statistical facet response, not  
> > > > > > > date histogram facet response. So, I am not quite sure what  
> > > > > > > information  
> > > > > > > you  
> > > > > > > are trying to retrieve. What's the type of the field that you  
> > > > > > > are  
> > > > > > > running  
> > > > > > > these facet queries on? Can you provide a more detailed example  
> > > > > > > of  
> > > > > > > what  
> > > > > > > you  
> > > > > > > are trying to achieve?
> 
> > > > > > > On Monday, April 23, 2012 11:51:26 PM UTC-4, George Viju wrote:
> 
> > > > > > > > Thank you Igor Motov! In my case, I need to combine the  
> > > > > > > > Date  
> > > > > > > > Histogram and Term Facet
> 
> > > > > > > > It is like.
> 
> > > > > > > > 1. Daterange and the count of matches similar to  
> > > > > > > > createddate" : {  
> > > > > > > > "\_type" : "statistical",  
> > > > > > > > "count" : 158,  
> > > > > > > > "total" : 2.10720682311E14,  
> > > > > > > > "min" : 1.3332708E12,  
> > > > > > > > "max" : 1.3340484E12,  
> > > > > > > > "mean" : 1.3336752045E12,  
> > > > > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > > > > "variance" : 6.30332803714792E16,  
> > > > > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > > > > }
> > > > > > > > 2. The number number of items and the matches count similar  
> > > > > > > > to  
> > > > > > > > "facets" : {  
> > > > > > > > "itemscount" : {  
> > > > > > > > "\_type" : "terms",  
> > > > > > > > "missing" : 0,  
> > > > > > > > "total" : 3492,  
> > > > > > > > "other" : 0,  
> > > > > > > > "terms" : [ {  
> > > > > > > > "term" : 1,  
> > > > > > > > "count" : 3022  
> > > > > > > > }, {  
> > > > > > > > "term" : 2,  
> > > > > > > > "count" : 247  
> > > > > > > > }, {  
> > > > > > > > "term" : 6,  
> > > > > > > > "count" : 154  
> > > > > > > > }, {  
> > > > > > > > "term" : 3,  
> > > > > > > > "count" : 28  
> > > > > > > > }, {  
> > > > > > > > "term" : 5,  
> > > > > > > > "count" : 27  
> > > > > > > > }, {  
> > > > > > > > "term" : 4,  
> > > > > > > > "count" : 14  
> > > > > > > > } ]  
> > > > > > > > },
> 
> > > > > > > > How can I combine these two as a single Facet?
> 
> > > > > > > > Cheers!
> 
> > > > > > > > George
> 
> > > > > > > > On Apr 23, 8:30 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > > > > 
> > > > > > > > > Not sure I understood your question. If you are trying to  
> > > > > > > > > combine  
> > > > > > > > > statistical and histogram facets in the same facet, it's not  
> > > > > > > > > possible.  
> > > > > > > > > However, you can send multiple facet requests in the same  
> > > > > > > > > search  
> > > > > > > > > request:
> 
> > > > > > > > > {  
> > > > > > > > > "query" : {  
> > > > > > > > > "match\_all" : {}  
> > > > > > > > > },  
> > > > > > > > > "facets" : {  
> > > > > > > > > "stat1" : {  
> > > > > > > > > "statistical" : {  
> > > > > > > > > . . .  
> > > > > > > > > }  
> > > > > > > > > },  
> > > > > > > > > "histo1" : {  
> > > > > > > > > "date\_histogram" : {  
> > > > > > > > > . . .  
> > > > > > > > > }  
> > > > > > > > > }  
> > > > > > > > > }
> 
> > > > > > > > > }  
> > > > > > > > > On Saturday, April 21, 2012 7:41:22 AM UTC-4, George Viju  
> > > > > > > > > wrote:
> 
> > > > > > > > > > Hi,  
> > > > > > > > > > How to combine two type of facets together as a  
> > > > > > > > > > single  
> > > > > > > > > > facet  
> > > > > > > > > > in  
> > > > > > > > > > elasticsearch?
> 
> > > > > > > > > > Cheers!
> 
> > > > > > > > > > George
> 
> > > > > > > > > > On Apr 20, 7:46 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com)  
> > > > > > > > > > wrote:
> > > > > > > > > > 
> > > > > > > > > > > Hi,  
> > > > > > > > > > > I am using DateHistogram Facet for getting the  
> > > > > > > > > > > Daterange  
> > > > > > > > > > > and  
> > > > > > > > > > > items. For Example
> 
> > > > > > > > > > > In DateHistogram Facet we can get the number of data  
> > > > > > > > > > > or  
> > > > > > > > > > > count  
> > > > > > > > > > > within the selected date range. In my application I need  
> > > > > > > > > > > to  
> > > > > > > > > > > get  
> > > > > > > > > > > both  
> > > > > > > > > > > the
> 
> > > > > > > > > > > 1. Daterange and the count of matches similar to
> 
> > > > > > > > > > > createddate" : {  
> > > > > > > > > > > "\_type" : "statistical",  
> > > > > > > > > > > "count" : 158,  
> > > > > > > > > > > "total" : 2.10720682311E14,  
> > > > > > > > > > > "min" : 1.3332708E12,  
> > > > > > > > > > > "max" : 1.3340484E12,  
> > > > > > > > > > > "mean" : 1.3336752045E12,  
> > > > > > > > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > > > > > > > "variance" : 6.30332803714792E16,  
> > > > > > > > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > > > > > > > }
> 
> > > > > > > > > > > 1. The number number of items and the matches count  
> > > > > > > > > > > similar  
> > > > > > > > > > > to
> 
> > > > > > > > > > > "facets" : {  
> > > > > > > > > > > "itemscount" : {  
> > > > > > > > > > > "\_type" : "terms",  
> > > > > > > > > > > "missing" : 0,  
> > > > > > > > > > > "total" : 3492,  
> > > > > > > > > > > "other" : 0,  
> > > > > > > > > > > "terms" : [ {  
> > > > > > > > > > > "term" : 1,  
> > > > > > > > > > > "count" : 3022  
> > > > > > > > > > > }, {  
> > > > > > > > > > > "term" : 2,  
> > > > > > > > > > > "count" : 247  
> > > > > > > > > > > }, {  
> > > > > > > > > > > "term" : 6,  
> > > > > > > > > > > "count" : 154  
> > > > > > > > > > > }, {  
> > > > > > > > > > > "term" : 3,  
> > > > > > > > > > > "count" : 28  
> > > > > > > > > > > }, {  
> > > > > > > > > > > "term" : 5,  
> > > > > > > > > > > "count" : 27  
> > > > > > > > > > > }, {  
> > > > > > > > > > > "term" : 4,  
> > > > > > > > > > > "count" : 14  
> > > > > > > > > > > } ]  
> > > > > > > > > > > },
> 
> > > > > > > > > > > Can this two things will get by a single facet? How can  
> > > > > > > > > > > I  
> > > > > > > > > > > get  
> > > > > > > > > > > this  
> > > > > > > > > > > using facet?
> 
> > > > > > > > > > > Cheers!
> 
> > > > > > > > > > > George

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [April 25, 2012, 2:00pm UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422/13 "2012-04-25T14:00:42Z")

</div>

I cannot think of any practical way to do it besides combining multiple  
search requests into a single request using Multi Search API.

On Wednesday, April 25, 2012 9:44:49 AM UTC-4, George Viju wrote:

> Thank you Igor Motov! Could it be possible for Multiple date ranges  
> per request (in the same Example)?
> 
> Thanks in Advance!
> 
> Cheers!
> 
> George  
> On Apr 25, 6:28 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> 
> > In this case, all you need to do is to run terms facet with query that  
> > limits results to your date range. The facets will contain number of  
> > sales  
> > per term, and the total number of sales will be equal to total number of  
> > hits.
> > 
> > {  
> > .....  
> > "hits" : {
> > 
> > - "total" : 7, \<--- This is total number of records\*  
> > "max\_score" : 1.0,  
> > "hits" :   
> > },  
> > "facets" : {  
> > "term" : {  
> > "\_type" : "terms",  
> > "missing" : 0,  
> > "total" : 7, \<-- This is total number of terms, it will be equal  
> > to  
> > the number above if you have one term per record  
> > "other" : 0,  
> > "terms" : [ {  
> > "term" : "AAA",  
> > "count" : 6  
> > }, {  
> > "term" : "BBB",  
> > "count" : 1  
> > } ]  
> > }  
> > }
> > 
> > }  
> > On Wednesday, April 25, 2012 4:58:34 AM UTC-4, George Viju wrote:
> > 
> > > I am sorry Igor Motov. Thanks for notifying this. Please read the  
> > > Example as:
> > 
> > > ```
> > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the 
> > > 
> > > ```
> > > 
> > > number of sales is 30  
> > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the  
> > > number of sales of item AAA is 25
> > 
> > > My Output is Like  
> > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > > the number of sales is 30 and the sales of item AAA is 25.
> > 
> > > Cheers!
> > 
> > > George
> > 
> > > On Apr 25, 11:58 am, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > 
> > > > I think I have started to understand what you are trying to achieve,  
> > > > but  
> > > > I  
> > > > am still a little bit confused about "sale". In your example, for  
> > > > the  
> > > > same  
> > > > period of time the total number of sales (25) is smaller than the  
> > > > number  
> > > > of  
> > > > sales for one item (30). How is this possible and how are sales  
> > > > represented/stored in your index?
> > 
> > > > On Tuesday, April 24, 2012 11:56:46 PM UTC-4, George Viju wrote:
> > 
> > > > > Thank You Igor Motov! Here I am using single date range per  
> > > > > request.
> > 
> > > > > Cheers!
> > 
> > > > > George
> > 
> > > > > On Apr 24, 9:00 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > 
> > > > > > Are you going to have multiple ranges per request or a single  
> > > > > > range  
> > > > > > per  
> > > > > > request?
> > 
> > > > > > On Tuesday, April 24, 2012 11:18:42 AM UTC-4, George Viju wrote:
> > 
> > > > > > > Thank You Igor Motov! . I have the parameters should be be  
> > > > > > > found  
> > > > > > > like -- createddaterange vs sales and items (in the  
> > > > > > > createddaterange)  
> > > > > > > vs sales ,
> > 
> > > > > > > Here I need to find,
> > 
> > > > > > > 1. For each date range the number(amount) of sales.
> > 
> > > > > > > 1. For each items in the date range the number(amount) of  
> > > > > > > sales.
> > 
> > > > > > > Example:  
> > > > > > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > > > > > > the  
> > > > > > > number of sales is 25  
> > > > > > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > > > > > > the  
> > > > > > > number of sales of item AAA is 30
> > 
> > > > > > > My Output is Like  
> > > > > > > From April 20, 2012 11:51:26 to April 23, 2012  
> > > > > > > 11:51:26  
> > > > > > > the number of sales is 25 and the sales of item AAA is 30.
> > 
> > > > > > > How can I get this using Facets Elasticsearch?
> > 
> > > > > > > Thanks in Advance!
> > 
> > > > > > > Cheers!
> > 
> > > > > > > George
> > 
> > > > > > > That is,
> > 
> > > > > > > On Apr 24, 7:23 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > > > 
> > > > > > > > Your first example looks like statistical facet response,  
> > > > > > > > not  
> > > > > > > > date histogram facet response. So, I am not quite sure what  
> > > > > > > > information  
> > > > > > > > you  
> > > > > > > > are trying to retrieve. What's the type of the field that  
> > > > > > > > you  
> > > > > > > > are  
> > > > > > > > running  
> > > > > > > > these facet queries on? Can you provide a more detailed  
> > > > > > > > example  
> > > > > > > > of  
> > > > > > > > what  
> > > > > > > > you  
> > > > > > > > are trying to achieve?
> > 
> > > > > > > > On Monday, April 23, 2012 11:51:26 PM UTC-4, George Viju  
> > > > > > > > wrote:
> > 
> > > > > > > > > Thank you Igor Motov! In my case, I need to combine  
> > > > > > > > > the  
> > > > > > > > > Date  
> > > > > > > > > Histogram and Term Facet
> > 
> > > > > > > > > It is like.
> > 
> > > > > > > > > 1. Daterange and the count of matches similar to  
> > > > > > > > > createddate" : {  
> > > > > > > > > "\_type" : "statistical",  
> > > > > > > > > "count" : 158,  
> > > > > > > > > "total" : 2.10720682311E14,  
> > > > > > > > > "min" : 1.3332708E12,  
> > > > > > > > > "max" : 1.3340484E12,  
> > > > > > > > > "mean" : 1.3336752045E12,  
> > > > > > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > > > > > "variance" : 6.30332803714792E16,  
> > > > > > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > > > > > }
> > > > > > > > > 2. The number number of items and the matches count  
> > > > > > > > > similar  
> > > > > > > > > to  
> > > > > > > > > "facets" : {  
> > > > > > > > > "itemscount" : {  
> > > > > > > > > "\_type" : "terms",  
> > > > > > > > > "missing" : 0,  
> > > > > > > > > "total" : 3492,  
> > > > > > > > > "other" : 0,  
> > > > > > > > > "terms" : [ {  
> > > > > > > > > "term" : 1,  
> > > > > > > > > "count" : 3022  
> > > > > > > > > }, {  
> > > > > > > > > "term" : 2,  
> > > > > > > > > "count" : 247  
> > > > > > > > > }, {  
> > > > > > > > > "term" : 6,  
> > > > > > > > > "count" : 154  
> > > > > > > > > }, {  
> > > > > > > > > "term" : 3,  
> > > > > > > > > "count" : 28  
> > > > > > > > > }, {  
> > > > > > > > > "term" : 5,  
> > > > > > > > > "count" : 27  
> > > > > > > > > }, {  
> > > > > > > > > "term" : 4,  
> > > > > > > > > "count" : 14  
> > > > > > > > > } ]  
> > > > > > > > > },
> > 
> > > > > > > > > How can I combine these two as a single Facet?
> > 
> > > > > > > > > Cheers!
> > 
> > > > > > > > > George
> > 
> > > > > > > > > On Apr 23, 8:30 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > > > > > 
> > > > > > > > > > Not sure I understood your question. If you are trying  
> > > > > > > > > > to  
> > > > > > > > > > combine  
> > > > > > > > > > statistical and histogram facets in the same facet, it's  
> > > > > > > > > > not  
> > > > > > > > > > possible.  
> > > > > > > > > > However, you can send multiple facet requests in the  
> > > > > > > > > > same  
> > > > > > > > > > search  
> > > > > > > > > > request:
> > 
> > > > > > > > > > {  
> > > > > > > > > > "query" : {  
> > > > > > > > > > "match\_all" : {}  
> > > > > > > > > > },  
> > > > > > > > > > "facets" : {  
> > > > > > > > > > "stat1" : {  
> > > > > > > > > > "statistical" : {  
> > > > > > > > > > . . .  
> > > > > > > > > > }  
> > > > > > > > > > },  
> > > > > > > > > > "histo1" : {  
> > > > > > > > > > "date\_histogram" : {  
> > > > > > > > > > . . .  
> > > > > > > > > > }  
> > > > > > > > > > }  
> > > > > > > > > > }
> > 
> > > > > > > > > > }  
> > > > > > > > > > On Saturday, April 21, 2012 7:41:22 AM UTC-4, George  
> > > > > > > > > > Viju  
> > > > > > > > > > wrote:
> > 
> > > > > > > > > > > Hi,  
> > > > > > > > > > > How to combine two type of facets together as a  
> > > > > > > > > > > single  
> > > > > > > > > > > facet  
> > > > > > > > > > > in  
> > > > > > > > > > > elasticsearch?
> > 
> > > > > > > > > > > Cheers!
> > 
> > > > > > > > > > > George
> > 
> > > > > > > > > > > On Apr 20, 7:46 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com)  
> > > > > > > > > > > wrote:
> > > > > > > > > > > 
> > > > > > > > > > > > Hi,  
> > > > > > > > > > > > I am using DateHistogram Facet for getting the  
> > > > > > > > > > > > Daterange  
> > > > > > > > > > > > and  
> > > > > > > > > > > > items. For Example
> > 
> > > > > > > > > > > > In DateHistogram Facet we can get the number of  
> > > > > > > > > > > > data  
> > > > > > > > > > > > or  
> > > > > > > > > > > > count  
> > > > > > > > > > > > within the selected date range. In my application I  
> > > > > > > > > > > > need  
> > > > > > > > > > > > to  
> > > > > > > > > > > > get  
> > > > > > > > > > > > both  
> > > > > > > > > > > > the
> > 
> > > > > > > > > > > > 1. Daterange and the count of matches similar to
> > 
> > > > > > > > > > > > createddate" : {  
> > > > > > > > > > > > "\_type" : "statistical",  
> > > > > > > > > > > > "count" : 158,  
> > > > > > > > > > > > "total" : 2.10720682311E14,  
> > > > > > > > > > > > "min" : 1.3332708E12,  
> > > > > > > > > > > > "max" : 1.3340484E12,  
> > > > > > > > > > > > "mean" : 1.3336752045E12,  
> > > > > > > > > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > > > > > > > > "variance" : 6.30332803714792E16,  
> > > > > > > > > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > > > > > > > > }
> > 
> > > > > > > > > > > > 1. The number number of items and the matches count  
> > > > > > > > > > > > similar  
> > > > > > > > > > > > to
> > 
> > > > > > > > > > > > "facets" : {  
> > > > > > > > > > > > "itemscount" : {  
> > > > > > > > > > > > "\_type" : "terms",  
> > > > > > > > > > > > "missing" : 0,  
> > > > > > > > > > > > "total" : 3492,  
> > > > > > > > > > > > "other" : 0,  
> > > > > > > > > > > > "terms" : [ {  
> > > > > > > > > > > > "term" : 1,  
> > > > > > > > > > > > "count" : 3022  
> > > > > > > > > > > > }, {  
> > > > > > > > > > > > "term" : 2,  
> > > > > > > > > > > > "count" : 247  
> > > > > > > > > > > > }, {  
> > > > > > > > > > > > "term" : 6,  
> > > > > > > > > > > > "count" : 154  
> > > > > > > > > > > > }, {  
> > > > > > > > > > > > "term" : 3,  
> > > > > > > > > > > > "count" : 28  
> > > > > > > > > > > > }, {  
> > > > > > > > > > > > "term" : 5,  
> > > > > > > > > > > > "count" : 27  
> > > > > > > > > > > > }, {  
> > > > > > > > > > > > "term" : 4,  
> > > > > > > > > > > > "count" : 14  
> > > > > > > > > > > > } ]  
> > > > > > > > > > > > },
> > 
> > > > > > > > > > > > Can this two things will get by a single facet? How  
> > > > > > > > > > > > can  
> > > > > > > > > > > > I  
> > > > > > > > > > > > get  
> > > > > > > > > > > > this  
> > > > > > > > > > > > using facet?
> > 
> > > > > > > > > > > > Cheers!
> > 
> > > > > > > > > > > > George

---

<div class="post-metadata">

**Author:** ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)\
**Post date:** [April 25, 2012, 3:31pm UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422/14 "2012-04-25T15:31:35Z")

</div>

Thank You Igor Motov !

Cheers!

George

On Apr 25, 7:00 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:

> I cannot think of any practical way to do it besides combining multiple  
> search requests into a single request using Multi Search API.
> 
> On Wednesday, April 25, 2012 9:44:49 AM UTC-4, George Viju wrote:
> 
> > Thank you Igor Motov! Could it be possible for Multiple date ranges  
> > per request (in the same Example)?
> 
> > Thanks in Advance!
> 
> > Cheers!
> 
> > George  
> > On Apr 25, 6:28 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > 
> > > In this case, all you need to do is to run terms facet with query that  
> > > limits results to your date range. The facets will contain number of  
> > > sales  
> > > per term, and the total number of sales will be equal to total number of  
> > > hits.
> 
> > > {  
> > > .....  
> > > "hits" : {
> > > 
> > > - "total" : 7, \<--- This is total number of records\*  
> > > "max\_score" : 1.0,  
> > > "hits" :   
> > > },  
> > > "facets" : {  
> > > "term" : {  
> > > "\_type" : "terms",  
> > > "missing" : 0,  
> > > "total" : 7, \<-- This is total number of terms, it will be equal  
> > > to  
> > > the number above if you have one term per record  
> > > "other" : 0,  
> > > "terms" : [ {  
> > > "term" : "AAA",  
> > > "count" : 6  
> > > }, {  
> > > "term" : "BBB",  
> > > "count" : 1  
> > > } ]  
> > > }  
> > > }
> 
> > > }  
> > > On Wednesday, April 25, 2012 4:58:34 AM UTC-4, George Viju wrote:
> 
> > > > I am sorry Igor Motov. Thanks for notifying this. Please read the  
> > > > Example as:
> 
> > > > ```
> > > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the
> > > > 
> > > > ```
> > > > 
> > > > number of sales is 30  
> > > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the  
> > > > number of sales of item AAA is 25
> 
> > > > My Output is Like  
> > > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > > > the number of sales is 30 and the sales of item AAA is 25.
> 
> > > > Cheers!
> 
> > > > George
> 
> > > > On Apr 25, 11:58 am, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > 
> > > > > I think I have started to understand what you are trying to achieve,  
> > > > > but  
> > > > > I  
> > > > > am still a little bit confused about "sale". In your example, for  
> > > > > the  
> > > > > same  
> > > > > period of time the total number of sales (25) is smaller than the  
> > > > > number  
> > > > > of  
> > > > > sales for one item (30). How is this possible and how are sales  
> > > > > represented/stored in your index?
> 
> > > > > On Tuesday, April 24, 2012 11:56:46 PM UTC-4, George Viju wrote:
> 
> > > > > > Thank You Igor Motov! Here I am using single date range per  
> > > > > > request.
> 
> > > > > > Cheers!
> 
> > > > > > George
> 
> > > > > > On Apr 24, 9:00 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > > 
> > > > > > > Are you going to have multiple ranges per request or a single  
> > > > > > > range  
> > > > > > > per  
> > > > > > > request?
> 
> > > > > > > On Tuesday, April 24, 2012 11:18:42 AM UTC-4, George Viju wrote:
> 
> > > > > > > > Thank You Igor Motov! . I have the parameters should be be  
> > > > > > > > found  
> > > > > > > > like -- createddaterange vs sales and items (in the  
> > > > > > > > createddaterange)  
> > > > > > > > vs sales ,
> 
> > > > > > > > Here I need to find,
> 
> > > > > > > > 1. For each date range the number(amount) of sales.
> 
> > > > > > > > 1. For each items in the date range the number(amount) of  
> > > > > > > > sales.
> 
> > > > > > > > Example:  
> > > > > > > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > > > > > > > the  
> > > > > > > > number of sales is 25  
> > > > > > > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > > > > > > > the  
> > > > > > > > number of sales of item AAA is 30
> 
> > > > > > > > My Output is Like  
> > > > > > > > From April 20, 2012 11:51:26 to April 23, 2012  
> > > > > > > > 11:51:26  
> > > > > > > > the number of sales is 25 and the sales of item AAA is 30.
> 
> > > > > > > > How can I get this using Facets Elasticsearch?
> 
> > > > > > > > Thanks in Advance!
> 
> > > > > > > > Cheers!
> 
> > > > > > > > George
> 
> > > > > > > > That is,
> 
> > > > > > > > On Apr 24, 7:23 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > > > > 
> > > > > > > > > Your first example looks like statistical facet response,  
> > > > > > > > > not  
> > > > > > > > > date histogram facet response. So, I am not quite sure what  
> > > > > > > > > information  
> > > > > > > > > you  
> > > > > > > > > are trying to retrieve. What's the type of the field that  
> > > > > > > > > you  
> > > > > > > > > are  
> > > > > > > > > running  
> > > > > > > > > these facet queries on? Can you provide a more detailed  
> > > > > > > > > example  
> > > > > > > > > of  
> > > > > > > > > what  
> > > > > > > > > you  
> > > > > > > > > are trying to achieve?
> 
> > > > > > > > > On Monday, April 23, 2012 11:51:26 PM UTC-4, George Viju  
> > > > > > > > > wrote:
> 
> > > > > > > > > > Thank you Igor Motov! In my case, I need to combine  
> > > > > > > > > > the  
> > > > > > > > > > Date  
> > > > > > > > > > Histogram and Term Facet
> 
> > > > > > > > > > It is like.
> 
> > > > > > > > > > 1. Daterange and the count of matches similar to  
> > > > > > > > > > createddate" : {  
> > > > > > > > > > "\_type" : "statistical",  
> > > > > > > > > > "count" : 158,  
> > > > > > > > > > "total" : 2.10720682311E14,  
> > > > > > > > > > "min" : 1.3332708E12,  
> > > > > > > > > > "max" : 1.3340484E12,  
> > > > > > > > > > "mean" : 1.3336752045E12,  
> > > > > > > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > > > > > > "variance" : 6.30332803714792E16,  
> > > > > > > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > > > > > > }
> > > > > > > > > > 2. The number number of items and the matches count  
> > > > > > > > > > similar  
> > > > > > > > > > to  
> > > > > > > > > > "facets" : {  
> > > > > > > > > > "itemscount" : {  
> > > > > > > > > > "\_type" : "terms",  
> > > > > > > > > > "missing" : 0,  
> > > > > > > > > > "total" : 3492,  
> > > > > > > > > > "other" : 0,  
> > > > > > > > > > "terms" : [ {  
> > > > > > > > > > "term" : 1,  
> > > > > > > > > > "count" : 3022  
> > > > > > > > > > }, {  
> > > > > > > > > > "term" : 2,  
> > > > > > > > > > "count" : 247  
> > > > > > > > > > }, {  
> > > > > > > > > > "term" : 6,  
> > > > > > > > > > "count" : 154  
> > > > > > > > > > }, {  
> > > > > > > > > > "term" : 3,  
> > > > > > > > > > "count" : 28  
> > > > > > > > > > }, {  
> > > > > > > > > > "term" : 5,  
> > > > > > > > > > "count" : 27  
> > > > > > > > > > }, {  
> > > > > > > > > > "term" : 4,  
> > > > > > > > > > "count" : 14  
> > > > > > > > > > } ]  
> > > > > > > > > > },
> 
> > > > > > > > > > How can I combine these two as a single Facet?
> 
> > > > > > > > > > Cheers!
> 
> > > > > > > > > > George
> 
> > > > > > > > > > On Apr 23, 8:30 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > > > > > > 
> > > > > > > > > > > Not sure I understood your question. If you are trying  
> > > > > > > > > > > to  
> > > > > > > > > > > combine  
> > > > > > > > > > > statistical and histogram facets in the same facet, it's  
> > > > > > > > > > > not  
> > > > > > > > > > > possible.  
> > > > > > > > > > > However, you can send multiple facet requests in the  
> > > > > > > > > > > same  
> > > > > > > > > > > search  
> > > > > > > > > > > request:
> 
> > > > > > > > > > > {  
> > > > > > > > > > > "query" : {  
> > > > > > > > > > > "match\_all" : {}  
> > > > > > > > > > > },  
> > > > > > > > > > > "facets" : {  
> > > > > > > > > > > "stat1" : {  
> > > > > > > > > > > "statistical" : {  
> > > > > > > > > > > . . .  
> > > > > > > > > > > }  
> > > > > > > > > > > },  
> > > > > > > > > > > "histo1" : {  
> > > > > > > > > > > "date\_histogram" : {  
> > > > > > > > > > > . . .  
> > > > > > > > > > > }  
> > > > > > > > > > > }  
> > > > > > > > > > > }
> 
> > > > > > > > > > > }  
> > > > > > > > > > > On Saturday, April 21, 2012 7:41:22 AM UTC-4, George  
> > > > > > > > > > > Viju  
> > > > > > > > > > > wrote:
> 
> > > > > > > > > > > > Hi,  
> > > > > > > > > > > > How to combine two type of facets together as a  
> > > > > > > > > > > > single  
> > > > > > > > > > > > facet  
> > > > > > > > > > > > in  
> > > > > > > > > > > > elasticsearch?
> 
> > > > > > > > > > > > Cheers!
> 
> > > > > > > > > > > > George
> 
> > > > > > > > > > > > On Apr 20, 7:46 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com)  
> > > > > > > > > > > > wrote:
> > > > > > > > > > > > 
> > > > > > > > > > > > > Hi,  
> > > > > > > > > > > > > I am using DateHistogram Facet for getting the  
> > > > > > > > > > > > > Daterange  
> > > > > > > > > > > > > and  
> > > > > > > > > > > > > items. For Example
> 
> > > > > > > > > > > > > In DateHistogram Facet we can get the number of  
> > > > > > > > > > > > > data  
> > > > > > > > > > > > > or  
> > > > > > > > > > > > > count  
> > > > > > > > > > > > > within the selected date range. In my application I  
> > > > > > > > > > > > > need  
> > > > > > > > > > > > > to  
> > > > > > > > > > > > > get  
> > > > > > > > > > > > > both  
> > > > > > > > > > > > > the
> 
> > > > > > > > > > > > > 1. Daterange and the count of matches similar to
> 
> > > > > > > > > > > > > createddate" : {  
> > > > > > > > > > > > > "\_type" : "statistical",  
> > > > > > > > > > > > > "count" : 158,  
> > > > > > > > > > > > > "total" : 2.10720682311E14,  
> > > > > > > > > > > > > "min" : 1.3332708E12,  
> > > > > > > > > > > > > "max" : 1.3340484E12,  
> > > > > > > > > > > > > "mean" : 1.3336752045E12,  
> > > > > > > > > > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > > > > > > > > > "variance" : 6.30332803714792E16,  
> > > > > > > > > > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > > > > > > > > > }
> 
> > > > > > > > > > > > > 1. The number number of items and the matches count  
> > > > > > > > > > > > > similar  
> > > > > > > > > > > > > to
> 
> > > > > > > > > > > > > "facets" : {  
> > > > > > > > > > > > > "itemscount" : {  
> > > > > > > > > > > > > "\_type" : "terms",  
> > > > > > > > > > > > > "missing" : 0,  
> > > > > > > > > > > > > "total" : 3492,  
> > > > > > > > > > > > > "other" : 0,  
> > > > > > > > > > > > > "terms" : [ {  
> > > > > > > > > > > > > "term" : 1,  
> > > > > > > > > > > > > "count" : 3022  
> > > > > > > > > > > > > }, {  
> > > > > > > > > > > > > "term" : 2,  
> > > > > > > > > > > > > "count" : 247  
> > > > > > > > > > > > > }, {
> 
> ...
> 
> read more »

---

<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:** [April 27, 2012, 9:03am UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422/15 "2012-04-27T09:03:51Z")

</div>

You can have multiple term facets, under their own name, each with a  
facet\_filter that further filter down the relevant term facet on a specific  
date range.

On Wed, Apr 25, 2012 at 4:44 PM, George Viju [vijuitech@gmail.com](mailto:vijuitech@gmail.com) wrote:

> Thank you Igor Motov! Could it be possible for Multiple date ranges  
> per request (in the same Example)?
> 
> Thanks in Advance!
> 
> Cheers!
> 
> George  
> On Apr 25, 6:28 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> 
> > In this case, all you need to do is to run terms facet with query that  
> > limits results to your date range. The facets will contain number of  
> > sales  
> > per term, and the total number of sales will be equal to total number of  
> > hits.
> > 
> > {  
> > .....  
> > "hits" : {
> > 
> > - "total" : 7, \<--- This is total number of records\*  
> > "max\_score" : 1.0,  
> > "hits" :   
> > },  
> > "facets" : {  
> > "term" : {  
> > "\_type" : "terms",  
> > "missing" : 0,  
> > "total" : 7, \<-- This is total number of terms, it will be equal  
> > to  
> > the number above if you have one term per record  
> > "other" : 0,  
> > "terms" : [ {  
> > "term" : "AAA",  
> > "count" : 6  
> > }, {  
> > "term" : "BBB",  
> > "count" : 1  
> > } ]  
> > }  
> > }
> > 
> > }  
> > On Wednesday, April 25, 2012 4:58:34 AM UTC-4, George Viju wrote:
> > 
> > > I am sorry Igor Motov. Thanks for notifying this. Please read the  
> > > Example as:
> > 
> > > ```
> > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the
> > > 
> > > ```
> > > 
> > > number of sales is 30  
> > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26 the  
> > > number of sales of item AAA is 25
> > 
> > > My Output is Like  
> > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > > the number of sales is 30 and the sales of item AAA is 25.
> > 
> > > Cheers!
> > 
> > > George
> > 
> > > On Apr 25, 11:58 am, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > 
> > > > I think I have started to understand what you are trying to achieve,  
> > > > but  
> > > > I  
> > > > am still a little bit confused about "sale". In your example, for the  
> > > > same  
> > > > period of time the total number of sales (25) is smaller than the  
> > > > number  
> > > > of  
> > > > sales for one item (30). How is this possible and how are sales  
> > > > represented/stored in your index?
> > 
> > > > On Tuesday, April 24, 2012 11:56:46 PM UTC-4, George Viju wrote:
> > 
> > > > > Thank You Igor Motov! Here I am using single date range per  
> > > > > request.
> > 
> > > > > Cheers!
> > 
> > > > > George
> > 
> > > > > On Apr 24, 9:00 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > 
> > > > > > Are you going to have multiple ranges per request or a single  
> > > > > > range  
> > > > > > per  
> > > > > > request?
> > 
> > > > > > On Tuesday, April 24, 2012 11:18:42 AM UTC-4, George Viju wrote:
> > 
> > > > > > > Thank You Igor Motov! . I have the parameters should be be  
> > > > > > > found  
> > > > > > > like -- createddaterange vs sales and items (in the  
> > > > > > > createddaterange)  
> > > > > > > vs sales ,
> > 
> > > > > > > Here I need to find,
> > 
> > > > > > > 1. For each date range the number(amount) of sales.
> > 
> > > > > > > 1. For each items in the date range the number(amount) of  
> > > > > > > sales.
> > 
> > > > > > > Example:  
> > > > > > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > > > > > > the  
> > > > > > > number of sales is 25  
> > > > > > > From April 20, 2012 11:51:26 to April 23, 2012 11:51:26  
> > > > > > > the  
> > > > > > > number of sales of item AAA is 30
> > 
> > > > > > > My Output is Like  
> > > > > > > From April 20, 2012 11:51:26 to April 23, 2012  
> > > > > > > 11:51:26  
> > > > > > > the number of sales is 25 and the sales of item AAA is 30.
> > 
> > > > > > > How can I get this using Facets Elasticsearch?
> > 
> > > > > > > Thanks in Advance!
> > 
> > > > > > > Cheers!
> > 
> > > > > > > George
> > 
> > > > > > > That is,
> > 
> > > > > > > On Apr 24, 7:23 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > > > 
> > > > > > > > Your first example looks like statistical facet response, not  
> > > > > > > > date histogram facet response. So, I am not quite sure what  
> > > > > > > > information  
> > > > > > > > you  
> > > > > > > > are trying to retrieve. What's the type of the field that you  
> > > > > > > > are  
> > > > > > > > running  
> > > > > > > > these facet queries on? Can you provide a more detailed  
> > > > > > > > example  
> > > > > > > > of  
> > > > > > > > what  
> > > > > > > > you  
> > > > > > > > are trying to achieve?
> > 
> > > > > > > > On Monday, April 23, 2012 11:51:26 PM UTC-4, George Viju  
> > > > > > > > wrote:
> > 
> > > > > > > > > Thank you Igor Motov! In my case, I need to combine  
> > > > > > > > > the  
> > > > > > > > > Date  
> > > > > > > > > Histogram and Term Facet
> > 
> > > > > > > > > It is like.
> > 
> > > > > > > > > 1. Daterange and the count of matches similar to  
> > > > > > > > > createddate" : {  
> > > > > > > > > "\_type" : "statistical",  
> > > > > > > > > "count" : 158,  
> > > > > > > > > "total" : 2.10720682311E14,  
> > > > > > > > > "min" : 1.3332708E12,  
> > > > > > > > > "max" : 1.3340484E12,  
> > > > > > > > > "mean" : 1.3336752045E12,  
> > > > > > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > > > > > "variance" : 6.30332803714792E16,  
> > > > > > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > > > > > }
> > > > > > > > > 2. The number number of items and the matches count  
> > > > > > > > > similar  
> > > > > > > > > to  
> > > > > > > > > "facets" : {  
> > > > > > > > > "itemscount" : {  
> > > > > > > > > "\_type" : "terms",  
> > > > > > > > > "missing" : 0,  
> > > > > > > > > "total" : 3492,  
> > > > > > > > > "other" : 0,  
> > > > > > > > > "terms" : [ {  
> > > > > > > > > "term" : 1,  
> > > > > > > > > "count" : 3022  
> > > > > > > > > }, {  
> > > > > > > > > "term" : 2,  
> > > > > > > > > "count" : 247  
> > > > > > > > > }, {  
> > > > > > > > > "term" : 6,  
> > > > > > > > > "count" : 154  
> > > > > > > > > }, {  
> > > > > > > > > "term" : 3,  
> > > > > > > > > "count" : 28  
> > > > > > > > > }, {  
> > > > > > > > > "term" : 5,  
> > > > > > > > > "count" : 27  
> > > > > > > > > }, {  
> > > > > > > > > "term" : 4,  
> > > > > > > > > "count" : 14  
> > > > > > > > > } ]  
> > > > > > > > > },
> > 
> > > > > > > > > How can I combine these two as a single Facet?
> > 
> > > > > > > > > Cheers!
> > 
> > > > > > > > > George
> > 
> > > > > > > > > On Apr 23, 8:30 pm, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > > > > > 
> > > > > > > > > > Not sure I understood your question. If you are trying to  
> > > > > > > > > > combine  
> > > > > > > > > > statistical and histogram facets in the same facet, it's  
> > > > > > > > > > not  
> > > > > > > > > > possible.  
> > > > > > > > > > However, you can send multiple facet requests in the same  
> > > > > > > > > > search  
> > > > > > > > > > request:
> > 
> > > > > > > > > > {  
> > > > > > > > > > "query" : {  
> > > > > > > > > > "match\_all" : {}  
> > > > > > > > > > },  
> > > > > > > > > > "facets" : {  
> > > > > > > > > > "stat1" : {  
> > > > > > > > > > "statistical" : {  
> > > > > > > > > > . . .  
> > > > > > > > > > }  
> > > > > > > > > > },  
> > > > > > > > > > "histo1" : {  
> > > > > > > > > > "date\_histogram" : {  
> > > > > > > > > > . . .  
> > > > > > > > > > }  
> > > > > > > > > > }  
> > > > > > > > > > }
> > 
> > > > > > > > > > }  
> > > > > > > > > > On Saturday, April 21, 2012 7:41:22 AM UTC-4, George Viju  
> > > > > > > > > > wrote:
> > 
> > > > > > > > > > > Hi,  
> > > > > > > > > > > How to combine two type of facets together as a  
> > > > > > > > > > > single  
> > > > > > > > > > > facet  
> > > > > > > > > > > in  
> > > > > > > > > > > elasticsearch?
> > 
> > > > > > > > > > > Cheers!
> > 
> > > > > > > > > > > George
> > 
> > > > > > > > > > > On Apr 20, 7:46 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com)  
> > > > > > > > > > > wrote:
> > > > > > > > > > > 
> > > > > > > > > > > > Hi,  
> > > > > > > > > > > > I am using DateHistogram Facet for getting the  
> > > > > > > > > > > > Daterange  
> > > > > > > > > > > > and  
> > > > > > > > > > > > items. For Example
> > 
> > > > > > > > > > > > In DateHistogram Facet we can get the number of  
> > > > > > > > > > > > data  
> > > > > > > > > > > > or  
> > > > > > > > > > > > count  
> > > > > > > > > > > > within the selected date range. In my application I  
> > > > > > > > > > > > need  
> > > > > > > > > > > > to  
> > > > > > > > > > > > get  
> > > > > > > > > > > > both  
> > > > > > > > > > > > the
> > 
> > > > > > > > > > > > 1. Daterange and the count of matches similar to
> > 
> > > > > > > > > > > > createddate" : {  
> > > > > > > > > > > > "\_type" : "statistical",  
> > > > > > > > > > > > "count" : 158,  
> > > > > > > > > > > > "total" : 2.10720682311E14,  
> > > > > > > > > > > > "min" : 1.3332708E12,  
> > > > > > > > > > > > "max" : 1.3340484E12,  
> > > > > > > > > > > > "mean" : 1.3336752045E12,  
> > > > > > > > > > > > "sum\_of\_squares" : 2.8103295903276077E26,  
> > > > > > > > > > > > "variance" : 6.30332803714792E16,  
> > > > > > > > > > > > "std\_deviation" : 2.510642952940127E8  
> > > > > > > > > > > > }
> > 
> > > > > > > > > > > > 1. The number number of items and the matches count  
> > > > > > > > > > > > similar  
> > > > > > > > > > > > to
> > 
> > > > > > > > > > > > "facets" : {  
> > > > > > > > > > > > "itemscount" : {  
> > > > > > > > > > > > "\_type" : "terms",  
> > > > > > > > > > > > "missing" : 0,  
> > > > > > > > > > > > "total" : 3492,  
> > > > > > > > > > > > "other" : 0,  
> > > > > > > > > > > > "terms" : [ {  
> > > > > > > > > > > > "term" : 1,  
> > > > > > > > > > > > "count" : 3022  
> > > > > > > > > > > > }, {  
> > > > > > > > > > > > "term" : 2,  
> > > > > > > > > > > > "count" : 247  
> > > > > > > > > > > > }, {  
> > > > > > > > > > > > "term" : 6,  
> > > > > > > > > > > > "count" : 154  
> > > > > > > > > > > > }, {  
> > > > > > > > > > > > "term" : 3,  
> > > > > > > > > > > > "count" : 28  
> > > > > > > > > > > > }, {  
> > > > > > > > > > > > "term" : 5,  
> > > > > > > > > > > > "count" : 27  
> > > > > > > > > > > > }, {  
> > > > > > > > > > > > "term" : 4,  
> > > > > > > > > > > > "count" : 14  
> > > > > > > > > > > > } ]  
> > > > > > > > > > > > },
> > 
> > > > > > > > > > > > Can this two things will get by a single facet? How  
> > > > > > > > > > > > can  
> > > > > > > > > > > > I  
> > > > > > > > > > > > get  
> > > > > > > > > > > > this  
> > > > > > > > > > > > using facet?
> > 
> > > > > > > > > > > > Cheers!
> > 
> > > > > > > > > > > > George

---

<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:30am UTC](https://discuss.elastic.co/t/combination-of-date-histogram-facet-and-term-facet/7422/16 "2017-07-06T03:30:57Z")

</div>


