Facets have got me down

We do something similar to your workaround for our ecommerce app. All our
dynamic product attributes are faceted against one field. Our app then
flattens things on the client side before returning the data to the user.
For efficiency, we do not use strings, but bit-shifted numerical values. A
client side mapping converts numeric ids into text values since our
taxonomy is known.

--
Ivan

On Wed, Feb 13, 2013 at 5:19 AM, jtreher@gmail.com wrote:

@Matt,

I might have a grip on it now. I think the major disjunction that I and
others in my situation are having is the fundamental concept of faceted
navigation.

There are some sites, such as a real estate site or a travel site which
use the same standard list of facets for every search result. location,
price, to, from, # of bedrooms, "other options" etc, etc. The facet toolkit
out-of-the-box provided by ES works for this type of navigation. That's
what the documentation uses for an example.

However, for organizations that do ecommerce, your typical faceted
navigation is dependent on the category or products that you are browsing.
And, for an "ad hoc" query, you might pull in products from multiple
domains, therefore the facets are dynamic based on the results. For
instance, if you sell speakers, shirts, and ovens, you have facets for
those domains. There is no out of the box way to tell SOLR or ES as far as
I can tell, to use complex facets consisting of key/value pairs (except for
the mathematical ones). For instance, if I could give ES the ideal
structure below and have it consume a key/value field for facet name/type
it would work out. The workaround to give ES a concatenation of key+value
works, it's just that it feels wrong. So, I store both the ideal version,
when I know the facet and the workaround version for ad hoc queries to get
counts. The application can break apart the workaround easily enough.

Ideal:
{facets:[
{facet_name:name1,
facet_value:value1},
{facet_name:name2,
facet_value:value2}
]

Workaround to "flatten facets". In this case ### is just a place holder
for the app to break apart the strings.
facets:[name1###value1,name2###value2]

Finally, I know that sites like Amazon force you to pick a category
before presenting domain facets. This would give one the ability to find
facets for a category and setup a proper facet query for ES. However, our
current specs don't allow for this, but it's certainly something to
consider.

On Tuesday, February 12, 2013 2:50:14 PM UTC-5, Matt Weber wrote:

I still am not 100% clear on what you are trying to accomplish. It
sounded like you have a field called "facets" that is an object.
Within that there can be any number of fields (genre, format,
has_remote, etc), but you don't necessarily know these field names
because each product you index can have it's own set. Since ES
requires that you know what field you want to facet on at query time,
ie. you need to specify a field name, you are out of luck because you
don't know the field names. I was suggesting you pull the mapping of
the index you are searching across, then inspect the names of the
fields within the "facets" object. You can then use these names at
query time to setup your facets. Now I wouldn't pull the mapping for
every query, but you could do it on some pre-defined interval and
cache the results within your application.

On Tue, Feb 12, 2013 at 10:02 AM, jtr...@gmail.com wrote:

@Matt Weber

Were you suggesting that I run a query to get ids and then run a
subsequent
query using facets found in those results to get the appropriate count,
restricting the scope of the count to the id set?

Thanks!

On Thursday, February 7, 2013 9:39:17 AM UTC-5, jtr...@gmail.comwrote:

When I'm actually doing a facet filter, I will know which facet(s) to
filter on, but upon the initial ad hoc query, I will need to present
the
facets to the user, grouped by count. Regardless, even when using a
facet
filter or two, I'd still like to present the remaining, unused facets
to the
user grouped by count.

On Wednesday, February 6, 2013 5:31:33 PM UTC-5, Matt Weber wrote:

So you don't know what fields you want to facet on? It sounds like
you want to facet on any field that is in the "facets" object, but
you
don't really know what is there? If this is fact what you are trying
to do, then you could always pull the mapping for your index and
parse
out any dynamic fields under the facets object then use those to
create the facets in your query.

On Wed, Feb 6, 2013 at 1:34 PM, jtr...@gmail.com wrote:

In the end, I'm trying to get the faceting count to work
"automatically"
when I'm not filtering by facet, but just using an ad hoc query.

Every one of my documents has a child object called "facets" that
has
all
the key:value attributes that belong to it to describe it. One
document
might have the colors key and another might have the genre key.
With an
ad
hoc query, I'd like ES to dive into the facets child object and
group
together any matches just like it does with the standard syntax.
However,
the facet "group" name will be one of the thousands of "keys."

input:
title: Mayhem
facets:
genre:horror
format: vhs
title: VHS player
facets:
remote control: yes
format: vhs

Search: Mayhem OR Player

output:
....
facets
genre
horror(1)
format
vhs(2)
remote control
yes(1)

On Wednesday, February 6, 2013 4:12:51 PM UTC-5, David Pilato
wrote:

I'm afraid I did not understand your question.
Here is some comment.

"facets": {
    "colors": {  <- this is a name you give to the facet
        "terms": {
            "field": "colors", <- the field you compute on
            "all_terms": true
        }
    }

What is your concern here?

You just add this facet request with the search request and you
get
back
hits and computed facet (with the same name you give).

Did you read this page?
Elasticsearch Platform — Find real-time answers at scale | Elastic**
facets/ http://www.elasticsearch.org/guide/reference/api/search/facets/

HTH

David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 févr. 2013 à 22:00, jtr...@gmail.com a écrit :

It might be because I'm low on energy, but I'm having a real tough
time
reconciling facet structure in my head right now. Does anyone know
of
a good
gist/blog example reference with some real world examples? I've
been
good
with the documentation except for facets, even though the samples
work
well.

I'll give you an example below. Every example has the facet
grouping
explicitly set:

"facets": {
    "colors": {  <- How is this grouping field dynamic to just

match
the field name?
"terms": {
"field": "colors",
"all_terms": true
}
}

I'm also struggling with documents that can contain any variety of
facets.
Some have none, some have many.

Thanks!

--
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 elasticsearc...@googlegroups.**com.

For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out.

--
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 elasticsearc...@googlegroups.**com.
For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out.

--
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 elasticsearc...@**googlegroups.com.
For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.