Monday, 25 November 2019

Azure Search - Improving speed while getting facets only

If you want to get only facets from your search query - for some purposes as preparing filters list - remember to set limit to 0.

For example like this:

var facetResults = searchQuery.Take(0).GetFacets();

.Take(0) translates to $top=0 in Azure Search query. That will return something like this:

{
    "@odata.context": "https://{YOUR-SEARCH-SERVICE}.search.windows.net/indexes('my-index-web-index-99')/$metadata#docs(*)",
    "@odata.count": 857,
    "@search.facets": {
        "contenttype_facet_1": [
            {
                "count": 146,
                "value": "Content Type 1"
            },
            {
                "count": 134,
                "value": "Content Type 2"
            },
            {
                "count": 118,
                "value": "Content Type 3"
            },
        ],
        "topic_facet_1": [
            {
                "count": 176,
                "value": "Topic 1"
            },
            {
                "count": 70,
                "value": "Topic 2"
            },
            {
                "count": 62,
                "value": "Topic 3"
            },
            {
                "count": 52,
                "value": "Topic 4"
            }
        ],
        "subtopic_facet_1": [
            {
                "count": 49,
                "value": "Subtopic 1"
            },
            {
                "count": 32,
                "value": "Subtopic 2"
            }
        ]
    },
    "value": []
}

So only essential statistics data without actual results

Share it:

Radosław Kozłowski - Senior Sitecore Developer Radoslaw Kozlowski

Author & Editor

Sitecore MVP, passionate Sitecore & .NET developer and architect. Sitecore Community evangelist.

1 comments:

  1. Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.
    artificial intelligence training in hyderabad
    business analytics course
    data analytics course

    ReplyDelete