【问题标题】:Azure Search Nested Class IndexingAzure 搜索嵌套类索引
【发布时间】:2015-06-04 11:10:18
【问题描述】:

我尝试将 Azure 搜索服务用于我的应用程序。我有一个像

这样的嵌套类
public class Products
{
    String ProductName {get;set;}
    List<Order> Order  {get;set;}
}
public class Order
{
    String Name {get;set;}
}

我找不到一种方法来索引产品,不仅搜索产品名称属性而且搜索订单名称。

在 Azure 搜索中处理此问题的方法是什么?

【问题讨论】:

标签: azure-cognitive-search


【解决方案1】:

您是否考虑过使用 Collection(Edm.String) 字段类型?看看以下索引定义是否适合您:

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

然后您可以像这样索引您的文档:

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

或者,您可以颠倒 Product - Order 关系并将 Order 作为主要实体,其所有属性包括 ProductName:

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

【讨论】:

  • 感谢您的回答。但是,我的订单类包括我还想进行一些搜索的地理位置属性。这就是为什么,这种方法不能满足我的需求。在进行了一些研究之后,有一个扁平化数据的解决方法,但这个解决方法仅适用于我假设的 DocumentDB。
  • 您能否颠倒 Product - Order 关系并以 Order 作为主要实体,包括 ProductName 在内的所有属性? { "name": "orders", "fields": [ {"name": "ordertId", "type": "Edm.String", "key": true, "searchable": false}, {"name" : "productName", "type": "Edm.String"}, {"name": "orderName", "type": "Edm.String"} ] }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-05
  • 2023-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多