Parametric Search with aggregations


(Cheyne Rood) #1

I've been working on advanced parametric search with elasticsearch v1.1 and
am having trouble getting aggregations to work in the way I'd like. I've
scoured the documentation and tried a couple different approaches without
luck, so I'm hoping someone on this list can help.

I have an index, "parts", and each indexed item has properties that I'd
like to use for parametric search, along with some text fields that I'll
allow the user to query.

On the frontend, I'd like to present the user with a search query input,
but also a number of parametric filtering options...here's how that looks
with only category filtering applied:
CloudApp

The challenges arise once I want to select a parametric filter, e.g.:
CloudApp

Here, I've checked "0.14" under "Weights". Notice that the other options
for weights have disappeared. This is of course because ES is only
aggregating the weights in the result set, and the only value in the result
set is "0.14". For the user, this is no good because they should be able
to select other weight values. On the backend, I'm including the weight
condition in my query:

So I took another approach, and put the weight condition in the filters,
rather than the query, so it wouldn't affect aggregations. Here's how the
backend settings look now:

And here's the frontend result:
CloudApp

The good news is that now I can see the sibling choices for my weight
filters, along with accurate counts of how selecting a sibling option would
affect the query results. The problem is that, because the weight
condition is not considered in aggregations, the aggregation numbers are
off for all of the non-weight parametric options. For example, the
"Material" option has an aggregate count of 5 results...but selecting it
would actually decrease the results to 0.

Does anyone know of a good solution for this? It seems fundamental to a
lot of parametric search solutions, so I'm hoping there's an answer. The
only route I can see now seems really expensive and messy: for each
aggregation, I need to apply all of the query conditions in the aggregation
filters...for example:

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/19d42213-000a-4033-ac71-90d25ee1bd0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Cheyne Rood) #2

Hey gang,

Just a quick update to say I've got this working, but I had to do it the
hard way. I keep track of all the filters my users apply in the parametric
options and factor them in to each aggregation. It's definitely going to
result in more expensive queries, but I'm hoping it'll be performant enough
to pass muster. So far it's still snappy with my test data.

On Friday, April 11, 2014 10:13:40 AM UTC-4, Cheyne Rood wrote:

I've been working on advanced parametric search with elasticsearch v1.1
and am having trouble getting aggregations to work in the way I'd like.
I've scoured the documentation and tried a couple different approaches
without luck, so I'm hoping someone on this list can help.

I have an index, "parts", and each indexed item has properties that I'd
like to use for parametric search, along with some text fields that I'll
allow the user to query.

On the frontend, I'd like to present the user with a search query input,
but also a number of parametric filtering options...here's how that looks
with only category filtering applied:
http://cl.ly/image/0N1K0m141w1s

The challenges arise once I want to select a parametric filter, e.g.:
http://cl.ly/image/1F382C050J32

Here, I've checked "0.14" under "Weights". Notice that the other options
for weights have disappeared. This is of course because ES is only
aggregating the weights in the result set, and the only value in the result
set is "0.14". For the user, this is no good because they should be able
to select other weight values. On the backend, I'm including the weight
condition in my query:

https://gist.github.com/cheyner/10471361#file-elastic-parts-condition-in-query

So I took another approach, and put the weight condition in the filters,
rather than the query, so it wouldn't affect aggregations. Here's how the
backend settings look now:

https://gist.github.com/cheyner/10471361#file-elastic-parts-condition-in-filters

And here's the frontend result:
http://cl.ly/image/2c262N0j2M0M

The good news is that now I can see the sibling choices for my weight
filters, along with accurate counts of how selecting a sibling option would
affect the query results. The problem is that, because the weight
condition is not considered in aggregations, the aggregation numbers are
off for all of the non-weight parametric options. For example, the
"Material" option has an aggregate count of 5 results...but selecting it
would actually decrease the results to 0.

Does anyone know of a good solution for this? It seems fundamental to a
lot of parametric search solutions, so I'm hoping there's an answer. The
only route I can see now seems really expensive and messy: for each
aggregation, I need to apply all of the query conditions in the aggregation
filters...for example:
https://gist.github.com/cheyner/10471361#file-elastic-parts-conditions-in-aggregations

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/a3572a91-b532-4666-bc9b-ba03d56c5f06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Binh Ly-2) #3

Or you can make 2 separate aggregations, one for your number crunching, and
another for your global parametrics. Something like this conceptually:

{
"aggs": {
"metrics": {
#all your standard metrics aggs here, all filtered by your query
},
"parametrics": {
"global": {} #global means don't filter by query criteria
# all your parametrics aggs here
}
}
}

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/43450dd0-7f3d-4746-b578-8a281d59995f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #4