0

Our data structure is similar to HotelId 1 example in the link https://learn.microsoft.com/en-us/azure/search/search-howto-complex-data-types

Our requirement is as follows:

Input: City = New York, StateProvince = NY, BaseRate = $100

Select fields: HotelId, HotelName, Description, Tags, Address, Rooms

Filter: Only rooms where BaseRate is less than or equal to Input rate and Address City and State matches input values. In this example, it should only select the first room from Rooms, not all Rooms.

Desired output:

{
"HotelId": "1",
"HotelName": "Secret Point Motel",
"Description": "Ideally located on the main commercial artery of the city in the heart of New York.",
"Tags": ["Free wifi", "on-site parking", "indoor pool", "continental breakfast"]
"Address": {
    "StreetAddress": "677 5th Ave",
    "City": "New York",
    "StateProvince": "NY"
  },
"Rooms": [
    {
      "Description": "Budget Room, 1 Queen Bed (Cityside)",
      "RoomNumber": 1105,
      "BaseRate": 96.99,
    }
  ]
}

Any help or direction on how to write a query for this or any pointers would be welcome.

1 Answer 1

1

The records in the hotels sample index consist of hotels, not rooms. Think of it as an index with Documents and Paragraphs. You may search for a Document (hotel) which has something within a Paragraph (room). The result you get would always be a list of Documents. From what I know there is no way to remove certain complex types from a record in a response.

The query to do what you ask (except filtering out rooms) is this by the way:

search=Address/City:"New York" AND Address/StateProvince:"NY"&$select=HotelId,HotelName,Description,Tags,Address,Rooms&$count=true&searchMode=all&queryType=full&$filter=Rooms/any(room: room/BaseRate lt 100.0)

Possible workarounds:

  1. Design your index with rooms as records

  2. Filter out rooms above the selected base rate in your frontend application.

1
  • Thank you for responding. Yes, we are writing that same query to filter everything and we have to filter Rooms in client-side only. I was just wondering if there was a way we could filter Rooms in Azure Search query itself. We could flatten the index where each document will get one Room but it will increase documents in index approx 5 times. It would be great if Azure Search team could put this - filtering complex collections in their ToDo items.
    – Shaurin G
    Commented Mar 12, 2021 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.