Question

I'm looking for a way to display my facets in a grouped list. For example i have some users and a facet to filter by country, this gives me:

  • Country
    • Holland (5)
    • England (2)
    • Egypt (5)
    • Rwanda (2)

And what i would like to have is:

  • Europe
    • Holland (5)
    • England (2)
  • Africa
    • Egypt (5)
    • Rwanda (2)

I'm using the Tire gem in a Rails application, my models and relations are like this: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-option_groups_from_collection_for_select

I've googled for an example on this for hours, just can't find anything for nested /grouped facets what makes sense to me in Elasticsearch. Hope someone can help me in the right direction! Many thanks in advance!

Daniel

Was it helpful?

Solution

You can probably handle this by indexing the data in two ways and then just parse the outout. Use the "object" version to apply filters, and get your parsing version as a facet to display filters.

For example:

    "mydocument":{
    "attributes":[     
       "location":{
        {"continent":"europe",
        "country":"england"
       },
     "fur_style":"long"
   ],
"facets":[
       {"location":"Europe##england"},
       {"fur_style":"long"
    ]
    }

when you get your data back, you'll have:

"facets":[
{"location":"Europe##england",
"total":5},
{"location":"africa##egypt",
"total":7}
{"fur_style":"long",
 "total":3}
etc etc
]

In your application, you just have to loop through and break apart the terms using the ## delimiter (or whatever you want it to be).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top