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


(tuneladora) #1

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.


(Jan Fiedler) #2

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 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.


(Shay Banon) #3

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 (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.


(tuneladora) #4

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

On Jul 8, 10:49 pm, Shay Banon 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 (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.


(system) #5