如何在 Azure 搜索中索引相关的 SQL 表?

How to index related SQL tables in Azure Search?

有 2 个相关的 table:categoriesproductsproducts table 有字段 categoryId,其中包含其类别的 id。如何索引 products table 以获得 name 或其类别的任何其他内容?

每个 table 我有 2 个索引器和一个索引。

// categories indexer
    {
        "name": "categories",
        "dataSourceName": "categories",
        "targetIndexName": "products",
            "fieldMappings": [
            {
                "sourceFieldName": "id",
                "targetFieldName": "id"
            },
            {
                "sourceFieldName": "name",
                "targetFieldName": "name"
            }
    }

// products indexer
    {
        "name": "products",
        "dataSourceName": "products",
        "targetIndexName": "products",
            "fieldMappings": [
            {
                "sourceFieldName": "id",
                "targetFieldName": "id"
            },
            {
                "sourceFieldName": "name",
                "targetFieldName": "name"
            },
                {
                "sourceFieldName": "categoryId",
                "targetFieldName": "categoryId"
            }
    }

// index
{  
    "name": "products",  
    "fields": [  
      {  
        "name": "id",  
        "type": "Edm.String",  
        ...  
      },
      {  
        "name": "categoryId",  
        "type": "Edm.String",  
        ...
      },
      {  
        "name": "category_name",  
        "type": "Edm.String",  
         ...
      },
      {  
        "name": "name",  
        "type": "Edm.String",  
        ...
      }
...

创建连接 categoriesproducts 表的视图,可能将所有 caregoryId 非规范化为产品文档的集合字段。 (您可以对其他类别数据使用相同的方法)。为该视图设置索引器。

另一种方法是为产品和类别创建两个单独的搜索索引,并在搜索客户端代码中执行连接。