how to get one specific item in Azure Search.

James Peter 81 Reputation points
2020-08-04T18:35:27.403+00:00

I have an index for Books and each book have a collection of customers. If I filter books that contains a specific customer works great, but I get in the result all the customers for the book. I would need to get the book with only the customer I'm filtering in the collection.

My index is something like:

{
   BookId: 1,
   Title: "My book",
   Author: "Author",
   Customers: [
   {
      CustomerId: 1,
      ...more customer data
   }
   {
      CustomerId: 2,
      ...more customer data
   }
   ]
}

I need to get the book filtering by title and only get the customer's 1 data or no customer if the customer 1 is not in the collection for that book. Is this possible?

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.
834 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. SnehaAgrawal-MSFT 19,921 Reputation points
    2020-08-05T06:59:35.75+00:00

    Thanks for asking question! As its answered here from PG Bruce;

    " This is not possible today. You'd have to filter out the complex collection elements on the client-side.

    Also, you didn't mention this in your question, but it seems the cardinality of the relationship from songs/books to customers could be quite high. If that's the case, you should consider a different data model, because there is a hard limit on the number of elements you can have in complex collections per document. Even without that limit, there are practical limits to complex collections, for example around document size and the inability to incrementally update them during indexing.

    If your model will have at most a few hundred customers per song, you're probably fine, but if it's in the thousands or higher, you should reconsider your design."

    1 person found this answer helpful.
    0 comments No comments