Azure Search - Smaller Facet Counts Not Returning From Index
Asked Answered
D

1

5

I am using Azure Search indexing for creating a faceted search of products. I have around 5 facets to aid in filtering the list of displayed products.

One thing I have noticed is that if there are quite a lot of products listed for filtering down using facets, smaller search items that belong within a facet do not get returned from the index.

For example (in its simplicity), if my index had the following cars manufacturers listed within a facet:

  • Audi (312)
  • BMW (203)
  • Volvo (198)
  • Skoda (4)

I would find that Skoda would not get returned, since there is such a small amount of search results linked to that manufacturer.

I can see this is the case when I search the index directly within the Azure Portal by using this query: facet=<facet-field-name>

After some research I came across the following explanation:

Facet counts can be inaccurate due to the sharding architecture. Every search index has multiple shards, and each shard reports the top N facets by document count, which is then combined into a single result. If some shards have many matching values, while others have fewer, you may find that some facet values are missing or under-counted in the results.

Although this behavior could change at any time, if you encounter this behavior today, you can work around it by artificially inflating the count: to a large number to enforce full reporting from each shard. If the value of count: is greater than or equal to the number of unique values in the field, you are guaranteed accurate results. However, when document counts are high, there is a performance penalty, so use this option judiciously.

Based on the above quote, how do I artificially inflate the count to get around this issue? Or does anyone know a better approach?

Debunk answered 26/11, 2017 at 20:29 Comment(0)
H
12

The default facet count is 10. You can specify a larger count using the count parameter as part of the facet expression. For example, assuming you're using the REST API with an HTTP GET request:

facet=myfield,count:100

If you're using the .NET SDK:

var parameters =
    new SearchParameters()
    {
        Facets = new[] { "myfield,count:100" }
    };

var results = indexClient.Documents.Search("*", parameters);

You can find more details about the facet expression syntax in the Azure Search REST API Reference.

Helen answered 2/12, 2017 at 22:54 Comment(5)
Great! But how do I stipulate the count via the API - IndexClient.Documents.Search<T>()? I've checked the SearchParameters properties and can't see where I can update that facet count.Debunk
It's part of the facet expression itself. Just add it to the SearchParameters.Facets property. I'll edit my answer to include an example.Helen
@BruceJohnston can we get all the facets available, what value should i pass for count in that case?Crane
@GaneshKarewad Please ask this as a separate question so that others will be able to find the answer easily.Helen
SearchParameters sp = new SearchParameters() { SearchMode = SearchMode.Any, Facets = new List<String>() { "state,count:60,sort:count"} }; We can add sorting logic as well into this.Groome

© 2022 - 2024 — McMap. All rights reserved.