0

So I'm using the C# nuget wrapper around Azure Search. My problem is I have a index of products:

public class ProductDocument
{
    [System.ComponentModel.DataAnnotations.Key]
    public string Key { get; set; }
    [IsSearchable]
    public string Sku { get; set; }
    [IsSearchable]
    public string Name { get; set; }
    [IsSearchable]
    public string FullDescription { get; set; }

    [IsSearchable]
    public List<CustomerSkuDocument> CustomerSkus { get; set; }
}
public class CustomerSkuDocument
{
    [IsSearchable]
    public int AccountId { get; set; }
    [IsSearchable]
    public string Sku { get; set; }
}

Example data would be:

            new Product() { Key= 100,Name="Nail 101",Sku = "CCCCCCCC", CustomerSkus = new List<ProductCustomerSku>()
            {
                new ProductCustomerSku() {AccountId = 222, CustomerSku = "BBBB"},
                new ProductCustomerSku() {AccountId = 333, CustomerSku = "EEEEEEE"}
            } 

So the problem is around CustomerSkuDocument. When I Search I need to pass the AccountId in as well as the search term, however the AccountId is only used for when searching the ProductCustomerSkus.

Basically an Account can have different customer skus but it's only associated to that account - I don't want a separate index per account.

So my call would be something like /AccountId=222&term=BBBB which would find the match.

However /AccountId=333&term=BBBB would not find a match.

So I'm calling it like:

        SearchParameters sp = new SearchParameters();
            sp.SearchMode = SearchMode.Any;
            sp.QueryType = QueryType.Full;

            DocumentSearchResult<ProductDocument> results =
            productIndexClient.Documents.Search<ProductDocument>(term, sp);

Where term is the normal search term, tried it with adding the AccountId but it doesn't work.

user1829226
  • 125
  • 1
  • 8

1 Answers1

0

Azure Search does not support repeating data structures nested under a property of the outer document. We're working on this (see https://feedback.azure.com/forums/263029-azure-search/suggestions/6670910-modelling-complex-types-in-indexes), but we still have some work to do before we can release that.

Given that, the example you're showing is not probably indexing the nested parts. Can you post the search index definition you're using? While we work in direct support for complex types, you can see your options for approach here: https://learn.microsoft.com/en-us/azure/search/search-howto-complex-data-types

From the above you'll arribe at a index structure that will also guide your query options. If all you need is equality, perhaps you can simply include the accountId and the SKU in the same field and use a collection field so you can have multiple instances. For your query you would issue a search query that requires the accountId and has the rest as optional keywords.

Pablo Castro
  • 1,644
  • 11
  • 11