Search code examples
azure-cognitive-search

Azure Search - Hierarchical facets guidance


I'm developing a project where I want to have hierarchical facets. I have an index with a complex structure, like: Index -field1 -List And othercomplexfield contains another list with anothercomplexfield inside.

I'd like to be able to give to users the possibility to:

Have the facets of field1. When one is selected, I'd like to give the user the possibility to select one of the values of a certain field of "othercomplexfield" while filtering by the selected field1.

I can do that.

I'd then like to give the user the possibility to select one of the possible values of "anothercomplexfield" while filtering by field1 AND by the selected othercomplexfield.

The difficulty here is that I don't want every possible facet value, but only the ones CONTAINED by the othercomplexfield that I'm filtering for.

So far I had to do this inside of c# and i did not find a way to write a query that gives me back from azure search the distinct values that I want.

Someone has a similar problem? Did I explain the problem well enough? I saw no clear guidance online, everything is easy if you only have level 1 facets but when you get into nested objects it's not that clear anymore.


Solution

  • I'm not sure I fully understand the context of your question. What I can tell you is that filters only apply at the document level and not at the complex collection level. What I mean by that is that if a filter matches an item in a complex collection, the entire document will be returned, not just the item in the complex collection that matched. The same is true for facets--facets will count all documents in the result set that match the filter and can't be scoped down just to parts of documents. With that, it seems like having this logic in your application like you mentioned might be the best approach for your current index schema.

    We do have this old blog post that talks about one way to implement hierarchical facets with Azure Cognitive Search which may give you some other ideas on how you could implement the functionality you're looking for: https://learn.microsoft.com/en-us/archive/blogs/onsearch/multi-level-taxonomy-facets-in-azure-search