Search code examples
azure-cognitive-search

What is the difference between $filter and facet in Azure Search


Quite new to Azure Search, and just wondering what is the difference between facet and filter?

Say I have a product table, and it has category and subcategories. If I want to return things under one category, should I use $filter or use facet? What is the difference between these two?

Many Thanks


Solution

  • Filter is used to restrict which documents are returned by a query. Faceting is used to produce summaries of field values across those documents. Details are here and you can find more general info about how to use faceting and filter together here.

    For your specific example, to retrieve documents for one category, use a filter. If you then want to see how many of those documents there are for each sub-category of that category (for example), use facets.