# 2-dimension facet or bulk search query for a trends chart

**URL:** <https://discuss.elastic.co/t/2-dimension-facet-or-bulk-search-query-for-a-trends-chart/4811>\
**Category:** Elasticsearch\
**Created:** [July 7, 2011, 3:47pm UTC](https://discuss.elastic.co/t/2-dimension-facet-or-bulk-search-query-for-a-trends-chart/4811 "2011-07-07T15:47:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tuneladora](https://avatars.discourse-cdn.com/v4/letter/t/b2d939/32.png) [@tuneladora](https://discuss.elastic.co/u/tuneladora)\
**Post date:** [July 7, 2011, 3:47pm UTC](https://discuss.elastic.co/t/2-dimension-facet-or-bulk-search-query-for-a-trends-chart/4811/1 "2011-07-07T15:47:48Z")

</div>

Hi all,

I'm trying to print a 2 dimensional trend chart from ES data, mostly  
always with date in one of the axis, so I've been trying to combine  
terms and histogram facets.

I'm expecting something somehow similar to this:

2011-07-01:  
value1 (20)  
value2 (51)  
value2 (17)

2011-07-02:  
value1 (75)  
value2 (46)  
value2 (45)

....

After failing at this I've been reading a little bit and this seems  
impossible at the moment. is this correct?

Then I though that since I know before hand all the potential values  
(value1, value2, etc..) I could request a histogram for each one of  
the values and build the results matrix on "my" side. The problem with  
this is that, since there are many possible values, I have to make a  
lot of http requests, which makes the latency too high.

Then I thought that the same way there is bulk indexing and bulk  
deleting, there might be bulk search to get everything in one HTTP  
request. I tried sending an array of requests to ES but it only seem  
to answer the last one.

Is there any way to send an array of requests and get an array of  
results?

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![Jan\_Fiedler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jan_fiedler/32/2518_2.png) [@Jan\_Fiedler](https://discuss.elastic.co/u/Jan_Fiedler)\
**Post date:** [July 8, 2011, 11:25am UTC](https://discuss.elastic.co/t/2-dimension-facet-or-bulk-search-query-for-a-trends-chart/4811/2 "2011-07-08T11:25:59Z")

</div>

Not sure this is the optimal solution but I think there is one that  
would allow you to do it with 2 HTTP requests (independent of number  
of terms).

The first request would have your query (whatever it is) and calculate  
a histogram on your date values. This way you basically learn about  
the values that you need for your second faceting dimension. Then  
create a second request with the same query as the first one (you are  
not interested in the hits of that second query). Add one term facet  
per date value you learned from the first request. For each facet you  
add, you would use the facet filter capability to restrict the  
documents used for calculating this facet to those that match your  
date value (the first dimension). Depending want your date values  
actually are you either need a (date) term filter or a (date) range  
filter for that.

Maybe this helps.  
Jan

On Jul 7, 5:47 pm, tuneladora [bictor...@gmail.com](mailto:bictor...@gmail.com) wrote:

> Hi all,
> 
> I'm trying to print a 2 dimensional trend chart from ES data, mostly  
> always with date in one of the axis, so I've been trying to combine  
> terms and histogram facets.
> 
> I'm expecting something somehow similar to this:
> 
> 2011-07-01:  
> value1 (20)  
> value2 (51)  
> value2 (17)
> 
> 2011-07-02:  
> value1 (75)  
> value2 (46)  
> value2 (45)
> 
> ....
> 
> After failing at this I've been reading a little bit and this seems  
> impossible at the moment. is this correct?
> 
> Then I though that since I know before hand all the potential values  
> (value1, value2, etc..) I could request a histogram for each one of  
> the values and build the results matrix on "my" side. The problem with  
> this is that, since there are many possible values, I have to make a  
> lot of http requests, which makes the latency too high.
> 
> Then I thought that the same way there is bulk indexing and bulk  
> deleting, there might be bulk search to get everything in one HTTP  
> request. I tried sending an array of requests to ES but it only seem  
> to answer the last one.
> 
> Is there any way to send an array of requests and get an array of  
> results?
> 
> Thanks a lot.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 8, 2011, 8:49pm UTC](https://discuss.elastic.co/t/2-dimension-facet-or-bulk-search-query-for-a-trends-chart/4811/3 "2011-07-08T20:49:16Z")

</div>

Yes, the way to do that is to simply have several facets (you can have more than one) matching the relevant terms. If you only need counts, and no hits back, make sure to you use search\_type set to count which will optimize the execution.

On Friday, July 8, 2011 at 2:25 PM, Jan Fiedler wrote:

> Not sure this is the optimal solution but I think there is one that  
> would allow you to do it with 2 HTTP requests (independent of number  
> of terms).
> 
> The first request would have your query (whatever it is) and calculate  
> a histogram on your date values. This way you basically learn about  
> the values that you need for your second faceting dimension. Then  
> create a second request with the same query as the first one (you are  
> not interested in the hits of that second query). Add one term facet  
> per date value you learned from the first request. For each facet you  
> add, you would use the facet filter capability to restrict the  
> documents used for calculating this facet to those that match your  
> date value (the first dimension). Depending want your date values  
> actually are you either need a (date) term filter or a (date) range  
> filter for that.
> 
> Maybe this helps.  
> Jan
> 
> On Jul 7, 5:47 pm, tuneladora \<[bictor...@gmail.com](mailto:bictor...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> 
> > Hi all,
> > 
> > I'm trying to print a 2 dimensional trend chart from ES data, mostly  
> > always with date in one of the axis, so I've been trying to combine  
> > terms and histogram facets.
> > 
> > I'm expecting something somehow similar to this:
> > 
> > 2011-07-01:  
> > value1 (20)  
> > value2 (51)  
> > value2 (17)
> > 
> > 2011-07-02:  
> > value1 (75)  
> > value2 (46)  
> > value2 (45)
> > 
> > ....
> > 
> > After failing at this I've been reading a little bit and this seems  
> > impossible at the moment. is this correct?
> > 
> > Then I though that since I know before hand all the potential values  
> > (value1, value2, etc..) I could request a histogram for each one of  
> > the values and build the results matrix on "my" side. The problem with  
> > this is that, since there are many possible values, I have to make a  
> > lot of http requests, which makes the latency too high.
> > 
> > Then I thought that the same way there is bulk indexing and bulk  
> > deleting, there might be bulk search to get everything in one HTTP  
> > request. I tried sending an array of requests to ES but it only seem  
> > to answer the last one.
> > 
> > Is there any way to send an array of requests and get an array of  
> > results?
> > 
> > Thanks a lot.

---

<div class="post-metadata">

**Author:** ![tuneladora](https://avatars.discourse-cdn.com/v4/letter/t/b2d939/32.png) [@tuneladora](https://discuss.elastic.co/u/tuneladora)\
**Post date:** [July 10, 2011, 3:11am UTC](https://discuss.elastic.co/t/2-dimension-facet-or-bulk-search-query-for-a-trends-chart/4811/4 "2011-07-10T03:11:14Z")

</div>

Thanks guys!  
Having multiple facets with filters per value worked perfectly.

On Jul 8, 10:49 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Yes, the way to do that is to simply have several facets (you can have more than one) matching the relevant terms. If you only need counts, and no hits back, make sure to you use search\_type set to count which will optimize the execution.
> 
> On Friday, July 8, 2011 at 2:25 PM, Jan Fiedler wrote:
> 
> > Not sure this is the optimal solution but I think there is one that  
> > would allow you to do it with 2 HTTP requests (independent of number  
> > of terms).
> 
> > The first request would have your query (whatever it is) and calculate  
> > a histogram on your date values. This way you basically learn about  
> > the values that you need for your second faceting dimension. Then  
> > create a second request with the same query as the first one (you are  
> > not interested in the hits of that second query). Add one term facet  
> > per date value you learned from the first request. For each facet you  
> > add, you would use the facet filter capability to restrict the  
> > documents used for calculating this facet to those that match your  
> > date value (the first dimension). Depending want your date values  
> > actually are you either need a (date) term filter or a (date) range  
> > filter for that.
> 
> > Maybe this helps.  
> > Jan
> 
> > On Jul 7, 5:47 pm, tuneladora \<[bictor...@gmail.com](mailto:bictor...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> > 
> > > Hi all,
> 
> > > I'm trying to print a 2 dimensional trend chart from ES data, mostly  
> > > always with date in one of the axis, so I've been trying to combine  
> > > terms and histogram facets.
> 
> > > I'm expecting something somehow similar to this:
> 
> > > 2011-07-01:  
> > > value1 (20)  
> > > value2 (51)  
> > > value2 (17)
> 
> > > 2011-07-02:  
> > > value1 (75)  
> > > value2 (46)  
> > > value2 (45)
> 
> > > ....
> 
> > > After failing at this I've been reading a little bit and this seems  
> > > impossible at the moment. is this correct?
> 
> > > Then I though that since I know before hand all the potential values  
> > > (value1, value2, etc..) I could request a histogram for each one of  
> > > the values and build the results matrix on "my" side. The problem with  
> > > this is that, since there are many possible values, I have to make a  
> > > lot of http requests, which makes the latency too high.
> 
> > > Then I thought that the same way there is bulk indexing and bulk  
> > > deleting, there might be bulk search to get everything in one HTTP  
> > > request. I tried sending an array of requests to ES but it only seem  
> > > to answer the last one.
> 
> > > Is there any way to send an array of requests and get an array of  
> > > results?
> 
> > > Thanks a lot.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:01am UTC](https://discuss.elastic.co/t/2-dimension-facet-or-bulk-search-query-for-a-trends-chart/4811/5 "2017-07-06T04:01:07Z")

</div>

Closed on July 6, 2017, 4:01am UTC


