Subsearch within a facet


(Enrique Medina Montenegro) #1

Hi,

I want my users to search products and then I'm executing a faceted search,
so they can also get the categories all those products belong to. I have
three levels of categorias, named "categorias1", "categorias2", and
"categorias3", where highest level is 1, then 2, then 3, as expected. If I
execute this:

{

"from" : 0, "size" : 10,

"query" : {

"fuzzy" : { "nombre" : "pc" }

},

facets : {

"myfacet" : {

        "terms" : {

            "field" : "categorias1",

            "size" : 10

        }

    }

}

}

This query works like a charm, but let's say now the user clicks on a
specific "categorias1", and now I want to display the search results within
that "categorias1", and faceted as well by the next level, i.e.
"categorias2". I'm trying this query without success:

{

"from" : 0, "size" : 2,

"query" : {

"fuzzy" : { "nombre" : "pc" }

},

"filter" : {

"term" : { "categorias1" : "Informática" }

},

facets : {

     "myfacet" : {

       "terms" : {

            "field" : "categorias2",

            "size" : 10

        }

    }

}

}

This is based on issue 650 and I'm running ES 0.15.0-SNAPSHOT (built with
Gradle):

Is this expected to provide the products within the specific "categorias1"
that the user has clicked on, faceted with next level "categorias2"? Or do I
have to build the query in a different way?

Thanks.


(Shay Banon) #2

You need to adda a facet_filter to the terms facet, otherwise, it will be compute the facets only for the query (without the filter from 650).
On Wednesday, February 2, 2011 at 6:45 PM, Enrique Medina Montenegro wrote:

Hi,

I want my users to search products and then I'm executing a faceted search, so they can also get the categories all those products belong to. I have three levels of categorias, named "categorias1", "categorias2", and "categorias3", where highest level is 1, then 2, then 3, as expected. If I execute this:

{
"from" : 0, "size" : 10,
"query" : {
"fuzzy" : { "nombre" : "pc" }
},
facets : {
"myfacet" : {
"terms" : {
"field" : "categorias1",
"size" : 10
}
}
}
}

This query works like a charm, but let's say now the user clicks on a specific "categorias1", and now I want to display the search results within that "categorias1", and faceted as well by the next level, i.e. "categorias2". I'm trying this query without success:

{
"from" : 0, "size" : 2,
"query" : {
"fuzzy" : { "nombre" : "pc" }
},
"filter" : {
"term" : { "categorias1" : "Informática" }
},
facets : {
"myfacet" : {
"terms" : {
"field" : "categorias2",
"size" : 10
}
}
}
}

This is based on issue 650 and I'm running ES 0.15.0-SNAPSHOT (built with Gradle):

https://github.com/elasticsearch/elasticsearch/issues/issue/650

Is this expected to provide the products within the specific "categorias1" that the user has clicked on, faceted with next level "categorias2"? Or do I have to build the query in a different way?

Thanks.


(system) #3