Multi value multi level hierarchical facets using App Search

Abhishek -- thank you!

I appreciate the detail.

The Hierarchical Facets guide mentions this at the end:


If we want the facet menu to include the correct counts for all dimensions, like so:

California (8)
  World Heritage Site (6)
    Open (4)
    Closed (2)
Alaska (5)

We would use multiple queries:

  1. Request dimension1 facets.
  2. Request dimension2 facets, filter on dimension1 .
  3. Request dimension3 facets, filter on dimension1 and dimension2 .

Your flow looks like so:

  1. Request dimension1 facets.
  2. Request dimension2 facets, filter on dimension1.
  3. ...

It is returning the correct facet counts for dimension2.

The filter will not impact the facet -- it will impact the result set.

So, anytime you are faceting on dimension2, it will return all of dimension2.


Remember that you have full control over the schema.

For example, you could break up dimension2 and establish separate hierarchies.

  • Vegetables are a 2 dimensional hierarchy.
  • Fruits are a 2 dimensional hierarchy.
  • Meats and Poultry is a 3 dimensional hierarchy.

If your schema were more "broken apart", such as this:

"id": text,
"email": text,
"dimension1": text,
"dimension2_veg": text
"dimension2_fruit": text,
"dimension2_meats": text,
"dimension3":  ...

You would be able to...

  1. more precisely apply single queries
  2. apply multiple queries when you need to represent multiple dimensions

Request 1:

{
  "query": "",
  "facets": {
    "dimension1": [{ "type": "value"}]
  }
}

Will return the count of Vegetables/Fruits/Meats&Poultry:

Vegetables (8)
Fruits (5)
Meats & Poultry (5)

Request 2:

{
  "query": "",
  "facets": {
    "dimension2_veg": [{ "type": "value"}]
  }
}

Will return:

Vegetables (8)
   Etc (1)
   Etc (2)
Fruits (5)
Meats & Poultry (5)

Request 3:

{
  "query": "",
  "facets": {
    "dimension2_fruits": [{ "type": "value"}]
  }
}

Will return:

Vegetables (x)
   Etc (x)
   Etc (x)
Fruits (x)
   Etc (x)
   Etc (x)
Meats & Poultry (x)

"Dimension" is just an example placeholder that can be replaced with your own symbols. :smile:

This isn't a "correct answer" for your case, but a demonstration that there is great flexibility.

Another thing that might help is our open source library, Search UI.

Search UI can help build search from a great set of foundational components, like faceting.

I hope this is helpful,

Kellen