0
votes

In the given hotel example given azure cognitive search, I need to get only one hotel from each category. What are the filter parameters I need to use and how?

I want a result like below where all categories are Budget, Resort and Spa, Luxury, Boutique, Suite, Extended-Stay

[
{
  "@search.score": 1,
  "HotelId": "24",
  "HotelName": "Gacc Capital",
  **"Category": "Budget",**
  "Rating": 3.5
},
{
  "@search.score": 1,
  "HotelId": "22",
  "HotelName": "Stone Lion Inn",
  **"Category": "Luxury",**
  "Rating": 3.9
},
{
  "@search.score": 1,
  "HotelId": "11",
  "HotelName": "Regal Orb Resort & Spa",
  **"Category": "Extended-Stay",**
  "Rating": 2.5
},
{
  "@search.score": 1,
  "HotelId": "13",
  "HotelName": "Historic Lion Resort",
  **"Category": "Boutique",**
  "Rating": 4.1
},
{
  "@search.score": 1,
  "HotelId": "29",
  "HotelName": "Thompson House",
  **"Category": "Resort and Spa",**
  "Rating": 2.6
},
{
  "@search.score": 1,
  "HotelId": "36",
  "HotelName": "Pelham Hotel",
  **"Category": "Suite",**
  "Rating": 3.5
}

]

1

1 Answers

0
votes

What you are asking for is known as aggregation or collapsing. At this point, there is no support in Azure Cognitive Search to support this. You can vote for this functionality to be added to the product here:

https://feedback.azure.com/forums/263029-azure-search/suggestions/8382225-add-aggregations-functionality

https://feedback.azure.com/forums/263029-azure-search/suggestions/9484995-add-support-for-field-collapsing

The only possible workaround is to submit multiple queries. First a query where you request the facet/refiner for Category. Then you need to submit a query for each of the Category entries to retrieve the top 1 result.