Azure Search Nested Class Indexing

I try to use Azure Search service for my application. I have a nested class like

public class Products
{
    String ProductName {get;set;}
    List<Order> Order  {get;set;}
}
public class Order
{
    String Name {get;set;}
}

and i couldn't find a way indexing products not only searching productname property but also searching ordername.

What is the way to handle this problem in Azure Search?

Upvotes: 1

Views: 858

Answers (1)

Yahnoosh
Yahnoosh

Reputation: 1972

Have you considered using Collection(Edm.String) field type? Take a look if the following index definition would work for you:

{
    "name": "products",  
    "fields": [
      {"name": "productId", "type": "Edm.String", "key": true, "searchable": false},
      {"name": "productName", "type": "Edm.String"},
      {"name": "orderNames", "type": "Collection(Edm.String)"}
    ]
}

You could then index your documents like this:

{
   "value":[
      {
         "productId":"1",
         "productName":"product1",
         "orderNames":[
            "order1",
            "order2"
         ]
      },
      {
         "productId":"2",
         "productName":"product2",
         "orderNames":[
            "order1",
            "order2"
         ]
      }
   ]
}

Alternatively you can you reverse Product - Order relationship and have Order as the main entity with all its properties including ProductName:

{
   "name":"orders",
   "fields":[
      {
         "name":"ordertId",
         "type":"Edm.String",
         "key":true,
         "searchable":false
      },
      {
         "name":"productName",
         "type":"Edm.String"
      },
      {
         "name":"orderName",
         "type":"Edm.String"
      }
   ]
}

Upvotes: 1

Related Questions