Hierarchical Facets using out-of-the-box Search UI

I'm trying to implement hierarchical facets (Province -> District) using out-of-the-box Search UI. With searchDriver can I do facets like this

Province 1
    - District 1-1
    - District 1-2
Province 2
    - District 2-1
    - District 2-2

The easiest way to implement this is to make District a separate facet, rather than trying to do a hierarchy: First class support for Hierarchical facets · Issue #285 · elastic/search-ui · GitHub

But how would I know that District 2-1 actually related to Province 2?

In that case, there is no direct relationship between the two. You'd have your data structured like so:

  "id": 1,
  "province":  "Province 1",
  "district": "District 1-1"
  "id": 2,
  "province":  "Province 1",
  "district": "District 1-2"
  "id": 3,
  "province":  "Province 2",
  "district": "District 2-1"

You would facet on "province", first, which would allow you to show the entire list of Provinces:

[ ] Province 1
[ ] Province 2

After a user has selected a province (or in other words, has applied a filter on "province"), you can then facet on "district".

At this point, since you're data is filtered on a particular "province", like "Province 1", for instance, you'd only see results "district" facets for districts that are actually in "Province 1".

[x] Province 1

[ ] District 1-1
[ ] District 1-2

Similarly, if a user would have selected "Province 2", you would then only see district values that are
in Province 2.

[x] Province 2

[ ] 2-1

Does that make sense?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.