How to search and retrieve single item present in a list inside one document in Azure Cognitive Search

Debashis Jena 1 Reputation point
2021-12-20T12:22:11.867+00:00

I have only one document inside an index. I want to retrieve only single item from an list based on search. But based on the search it is providing whole document data. But I need only one item from a list.

This is the content inside my index.

{
"HotelId": "45",
"HotelName": "Arcadia Resort & Restaurant",
"Rooms": [
{
"RoomId": "101",
"Type": "Budget Room",
"BaseRate": 70.99,
},
{
"RoomId": "102",
"Type": "Deluxe Room",
"BaseRate": 85.99,
},
{
"RoomId": "103",
"Type": "Standard Room",
"BaseRate": 75.99,
},
{
"RoomId": "104",
"Type": "Deluxe Room",
"BaseRate": 70.99,
}

}

From the above document I only require details of a single room based on the search of RoomId.
For e.g I need only data for Room id 103. I tried making the field Room id as filterable and added query to filter that so that I get only one data with room id matching 103 but i still got the whole data.

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,062 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ajkuma 26,636 Reputation points Microsoft Employee
    2021-12-21T12:44:58.907+00:00

    @Debashis Jena , Thanks for the feedback.

    Because the granularity of your index is at the parent level rather than the child level, current it is not possible pull only the child item from the list.
    Alternatively, you could change the granularity of your index. Another option could be to keep your existing schema and then do a second layer of filtering of the */child at the application layer, to have only required criteria to list in your application.

    Quoting the response from Derek Legenzoff (from our Azure Search PG).

    “We don't have any immediate plans to change the way this works that I'm aware of but we're always looking to improve the product based on feedback from customers like yourself so we appreciate you sharing the feedback with us.”

    Kindly check this thread for similar feedback request, response from our PG and workaround that you could leverage:

    [FEATURE REQ] Azure Search Working with Complex Collections]
    https://github.com/Azure/azure-sdk-for-net/issues/23569

    -Kindly be assured that I have also relayed your feedback internally to our product engineering team.
    -Also checkout this doc - Model complex data types in Azure Cognitive Search] for more info.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.