Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Facets and hits?


Hi, my Find skills are a bit limited, so I hope someone can push me in the right direction. 

Lets say I have a query that gets all "Categories":

var searchResults = client.Search()
    .TermsFacetFor(x => x.Category)

If I now want the 10 first hits in each Facet, can I extend my query to do that? Or do I need to write a subquery for each Facet?


Oct 09, 2015 13:22

Sorry, didn't read the thread completly, removed my wrong answer

Edited, Oct 09, 2015 14:31

If you need to get the 10 first (order by something?) for X amount of facets, I don't think there is a way to do it in a single query.
However, you could use multisearch to limit the number of queries. Here's an example:

                var words = new List<string>() { "burger", "banjo", "water"};
                var multiSearchQuery = SearchClient.Instance.MultiSearch<MyItem>();            
                foreach (var word in words)
                   multiSearchQuery = multiSearchQuery.Search(x => x.Filter(z => z.Category.Match(word)));

Edited, Oct 09, 2015 14:35

Thanks, I'll give it a try.

Oct 09, 2015 15:49

Keep in mind that multisearch has a maximum of 10 queries, so if you go above that you'll have to modify your code to create more multisearch queries.

If that is the case, I suppose Henrik's answer is helpful, as that means that you'll need to get more than 10 facets, which is the default value :-)

TermsFacetFor(x => x.Something, facet => facet.Size = 50)
Oct 09, 2015 15:55

So I gave it a try and it works. Feels a bit dirty though.. :) A question though. If I add 10 searches to a multisearch, I get 403 forbidden, saying that 10 is the maximum allowed queries. If I only add 9 queries it works. Is this by design? Or just a misstake?

Oct 12, 2015 11:10

Sounds like a bug to me

Oct 14, 2015 10:02
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.