# Facets For the Distinct Fields

**URL:** <https://discuss.elastic.co/t/facets-for-the-distinct-fields/7469>\
**Category:** Elasticsearch\
**Created:** [April 26, 2012, 6:09am UTC](https://discuss.elastic.co/t/facets-for-the-distinct-fields/7469 "2012-04-26T06:09:24Z")\
**Posts on this page:** 6\
**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 26, 2012, 6:09am UTC](https://discuss.elastic.co/t/facets-for-the-distinct-fields/7469/1 "2012-04-26T06:09:24Z")

</div>

Hi,  
In my application

# Product\_ID Total Sale\_ID

3 2 1

4 5 3

9 3 4

It means, For the Two Fields Product\_ID and Sale\_ID I need the  
Total Count.

Here I need to get the Total Which should satisfies both Product\_Id  
and Sale\_ID

The Expected output is like

"itemcount" : {  
{

```
    "term1" : "3",
    "term2" : "1",

    "count" : 2
  }, {
    "term1" : "4",
    "term2" : "3"

    "count" : 5

  }, {
    "term1" : "9",
    "term2" : "4",

    "count" : 3
  },
}

```

How can I get this using Elasticsearch?

Cheers!

George

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 26, 2012, 7:16am UTC](https://discuss.elastic.co/t/facets-for-the-distinct-fields/7469/2 "2012-04-26T07:16:40Z")

</div>

You could create a new field which add product and sale with a separator and with no analyzer.

Then compute the facet on that new field.

David 😉  
Twitter : @dadoonet / @elasticsearchfr

Le 26 avr. 2012 à 08:09, George Viju [vijuitech@gmail.com](mailto:vijuitech@gmail.com) a écrit :

> Hi,  
> In my application
> 
> # Product\_ID Total Sale\_ID
> 
> 3 2 1
> 
> 4 5 3
> 
> 9 3 4
> 
> It means, For the Two Fields Product\_ID and Sale\_ID I need the  
> Total Count.
> 
> Here I need to get the Total Which should satisfies both Product\_Id  
> and Sale\_ID
> 
> The Expected output is like
> 
> "itemcount" : {  
> {
> 
> ```
> "term1" : "3",
> "term2" : "1",
> 
> "count" : 2
> }, {
> "term1" : "4",
> "term2" : "3"
> 
> "count" : 5
> 
> }, {
> "term1" : "9",
> "term2" : "4",
> 
> "count" : 3
> },
> 
> ```
> 
> }
> 
> How can I get this using Elasticsearch?
> 
> 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 26, 2012, 7:21am UTC](https://discuss.elastic.co/t/facets-for-the-distinct-fields/7469/3 "2012-04-26T07:21:48Z")

</div>

Thank You David Pilato!

Cheers!

George

On Apr 26, 12:16 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> You could create a new field which add product and sale with a separator and with no analyzer.
> 
> Then compute the facet on that new field.
> 
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr
> 
> Le 26 avr. 2012 à 08:09, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) a écrit :
> 
> > Hi,  
> > In my application
> 
> > # Product\_ID Total Sale\_ID
> 
> > 3 2 1
> 
> > 4 5 3
> 
> > 9 3 4
> 
> > It means, For the Two Fields Product\_ID and Sale\_ID I need the  
> > Total Count.
> 
> > Here I need to get the Total Which should satisfies both Product\_Id  
> > and Sale\_ID
> 
> > The Expected output is like
> 
> > "itemcount" : {  
> > {
> 
> > ```
> > "term1" : "3",
> > "term2" : "1",
> > 
> > ```
> 
> > ```
> > "count" : 2
> > }, {
> > "term1" : "4",
> > "term2" : "3"
> > 
> > ```
> 
> > ```
> > "count" : 5
> > 
> > ```
> 
> > ```
> > }, {
> > "term1" : "9",
> > "term2" : "4",
> > 
> > ```
> 
> > ```
> > "count" : 3
> > },
> > 
> > ```
> > 
> > }
> 
> > How can I get this using Elasticsearch?
> 
> > 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 26, 2012, 9:29am UTC](https://discuss.elastic.co/t/facets-for-the-distinct-fields/7469/4 "2012-04-26T09:29:37Z")

</div>

Hi,  
In an application I need to get the date and the Product, For  
date alone I can get as

Eg

# HOUR TOTAL

9 70

11 2

14 4

I can get this by DateHistogram Facet by setting the interval as  
hour

"createddaterange" : {  
"\_type" : "date\_histogram",  
"entries" : [ {  
"time" : 1335430800000,  
"count" : 70,  
"min" : 1.3354308E12,  
"max" : 1.335434149E12,  
"total" : 9.34803365E13,  
"total\_count" : 70,  
"mean" : 1.3354333785714285E12  
}, {  
"time" : 1335438000000,  
"count" : 2,  
"min" : 1.335440393E12,  
"max" : 1.33544091E12,  
"total" : 2.670881303E12,  
"total\_count" : 2,  
"mean" : 1.3354406515E12  
}, {  
"time" : 1335448800000,  
"count" : 4,  
"min" : 1.3354503E12,  
"max" : 1.335450981E12,  
"total" : 5.341802376E12,  
"total\_count" : 4,  
"mean" : 1.335450594E12  
} ]

For Date as well as the Product\_D like

# HOUR TOTAL PRODUCT\_ID

9 70 11

11 2 34

14 4 22

How can I get this for hour, month, day, week with the Product\_ID in  
Elasticsearch?

Cheers!

George

On Apr 26, 12:21 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:

> Thank You David Pilato!
> 
> Cheers!
> 
> George
> 
> On Apr 26, 12:16 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> 
> > You could create a new field which add product and sale with a separator and with no analyzer.
> 
> > Then compute the facet on that new field.
> 
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr
> 
> > Le 26 avr. 2012 à 08:09, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) a écrit :
> 
> > > Hi,  
> > > In my application
> 
> > > # Product\_ID Total Sale\_ID
> 
> > > 3 2 1
> 
> > > 4 5 3
> 
> > > 9 3 4
> 
> > > It means, For the Two Fields Product\_ID and Sale\_ID I need the  
> > > Total Count.
> 
> > > Here I need to get the Total Which should satisfies both Product\_Id  
> > > and Sale\_ID
> 
> > > The Expected output is like
> 
> > > "itemcount" : {  
> > > {
> 
> > > ```
> > > "term1" : "3",
> > > "term2" : "1",
> > > 
> > > ```
> 
> > > ```
> > > "count" : 2
> > > }, {
> > > "term1" : "4",
> > > "term2" : "3"
> > > 
> > > ```
> 
> > > ```
> > > "count" : 5
> > > 
> > > ```
> 
> > > ```
> > > }, {
> > > "term1" : "9",
> > > "term2" : "4",
> > > 
> > > ```
> 
> > > ```
> > > "count" : 3
> > > },
> > > 
> > > ```
> > > 
> > > }
> 
> > > How can I get this using Elasticsearch?
> 
> > > 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 30, 2012, 3:40pm UTC](https://discuss.elastic.co/t/facets-for-the-distinct-fields/7469/5 "2012-04-30T15:40:41Z")

</div>

How can I get this for hour, month, day, week with the Product\_ID and  
the Date in the above example using  
Elasticsearch?

On Apr 26, 2:29 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:

> Hi,  
> In an application I need to get the date and the Product, For  
> date alone I can get as
> 
> Eg
> 
> # HOUR TOTAL
> 
> 9 70
> 
> 11 2
> 
> 14 4
> 
> I can get this by DateHistogram Facet by setting the interval as  
> hour
> 
> "createddaterange" : {  
> "\_type" : "date\_histogram",  
> "entries" : [ {  
> "time" : 1335430800000,  
> "count" : 70,  
> "min" : 1.3354308E12,  
> "max" : 1.335434149E12,  
> "total" : 9.34803365E13,  
> "total\_count" : 70,  
> "mean" : 1.3354333785714285E12  
> }, {  
> "time" : 1335438000000,  
> "count" : 2,  
> "min" : 1.335440393E12,  
> "max" : 1.33544091E12,  
> "total" : 2.670881303E12,  
> "total\_count" : 2,  
> "mean" : 1.3354406515E12  
> }, {  
> "time" : 1335448800000,  
> "count" : 4,  
> "min" : 1.3354503E12,  
> "max" : 1.335450981E12,  
> "total" : 5.341802376E12,  
> "total\_count" : 4,  
> "mean" : 1.335450594E12  
> } ]
> 
> For Date as well as the Product\_D like
> 
> # HOUR TOTAL PRODUCT\_ID
> 
> 9 70 11
> 
> 11 2 34
> 
> 14 4 22
> 
> How can I get this for hour, month, day, week with the Product\_ID in  
> Elasticsearch?
> 
> Cheers!
> 
> George
> 
> On Apr 26, 12:21 pm,GeorgeViju[vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> 
> > Thank You David Pilato!
> 
> > Cheers!
> 
> > George
> 
> > On Apr 26, 12:16 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> 
> > > You could create a new field which add product and sale with a separator and with no analyzer.
> 
> > > Then compute the facet on that new field.
> 
> > > David 😉  
> > > Twitter : @dadoonet / @elasticsearchfr
> 
> > > Le 26 avr. 2012 à 08:09,GeorgeViju[vijuit...@gmail.com](mailto:vijuit...@gmail.com) a écrit :
> 
> > > > Hi,  
> > > > In my application
> 
> > > > # Product\_ID Total Sale\_ID
> 
> > > > 3 2 1
> 
> > > > 4 5 3
> 
> > > > 9 3 4
> 
> > > > It means, For the Two Fields Product\_ID and Sale\_ID I need the  
> > > > Total Count.
> 
> > > > Here I need to get the Total Which should satisfies both Product\_Id  
> > > > and Sale\_ID
> 
> > > > The Expected output is like
> 
> > > > "itemcount" : {  
> > > > {
> 
> > > > ```
> > > > "term1" : "3",
> > > > "term2" : "1",
> > > > 
> > > > ```
> 
> > > > ```
> > > > "count" : 2
> > > > }, {
> > > > "term1" : "4",
> > > > "term2" : "3"
> > > > 
> > > > ```
> 
> > > > ```
> > > > "count" : 5
> > > > 
> > > > ```
> 
> > > > ```
> > > > }, {
> > > > "term1" : "9",
> > > > "term2" : "4",
> > > > 
> > > > ```
> 
> > > > ```
> > > > "count" : 3
> > > > },
> > > > 
> > > > ```
> > > > 
> > > > }
> 
> > > > How can I get this using Elasticsearch?
> 
> > > > 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/facets-for-the-distinct-fields/7469/6 "2017-07-06T03:30:33Z")

</div>


