2017-11-01 11 views
1

開発中にAzure Searchインデックスを手動で作成することに飽きてしまったので、私たちのために行うためのコンソールアプリケーションを作成しています。 Azureには、すでにデータベースビューであるデータソースがあります。そのビューはインデックスにフィードします。私の質問は、インデックスを作成するときにデータソースを指定する方法です。ここに私のコードは、(Employeeクラスの定義は含まない)、これまでです:Azureの検索データソースの作成Azure Search SDK:データソースの指定方法

using Microsoft.Azure.Search; 
using Microsoft.Azure.Search.Models; 

namespace AdvancedSearchIndexGenerator 
{ 
    class Program 
    { 
     static void Main() 
     { 
      SearchServiceClient client = new SearchServiceClient(Util.AzureSearchServiceName, new SearchCredentials(Util.AzureSearchApiKey)); 

      var definition = new Index() 
      { 
       Name = Util.AzureSearchIndexName, 
       Fields = FieldBuilder.BuildForType<Employee>() 
      }; 

      client.Indexes.Create(definition); 
     } 
    } 
} 

答えて

0

あなたは、インデックスを作成するときは、データ・ソースを指定しないでください。データソースからデータを抽出してインデックスにプッシュするインデクサーを作成するときに、データソースを指定できます。

Indexer creationに引数としてdataSourceNameを渡すことができます。

ありがとう、

Luis Cabrera | Azure Search

1

インデックス

作成した後に、別のステップである

あなたは2にAzureの検索データソースを作成することができます方法:中Microsoft.Azure.Search NuGetパッケージを使用してAzure Search Service REST API

  • を使用して

    1. C#コード
  • NuGetパッケージを使用(かなり古い、これらのパッケージの新しいバージョンが異なる実装を有することができる):

    • パッケージID = "Microsoft.Azure.Search" バージョン= "1.1.1 " targetFramework =" net461"
    • パッケージID = "Microsoft.Rest.ClientRuntime.Azure" バージョン= "2.5.2" targetFramework = "net45"

    サンプルC#コードはCosmosDBとAzureの検索データソースを作成するには、以下の書かれている:

    using Microsoft.Azure.Search.Models; 
    using Microsoft.Rest.Azure; 
    
    DataSource dataSource = CreateDataSource(sqlQuery, collectionName, indexName, dataSourceName, dataSourceConnectionString); 
    AzureOperationResponse<DataSource> operation = await client.DataSources.CreateOrUpdateWithHttpMessagesAsync(dataSource); 
    
    private DataSource GetDataSource(string sqlQuery, string collectionName, string indexName, string dataSourceName, string dataSourceConnectionString) 
    { 
        DataSource dataSource = new DataSource(); 
        dataSource.Name = dataSourceName; 
        dataSource.Container = GetDataSourceContainer(sqlQuery, collectionName); 
        dataSource.Credentials = new DataSourceCredentials(dataSourceConnectionString); 
        dataSource.Type = "documentdb"; 
        return dataSource; 
    }  
    
    private DataContainer GetDataSourceContainer(string sqlQuery, string collectionName) 
    { 
        DataContainer container = new DataContainer(); 
        container.Query = sqlQuery; 
        container.Name = collectionName; 
        return container; 
    } 
    
    +1

    実際、データソースはインデックスとは独立しています。私たちはすでに存在しており、私たちはそれを削除または再作成するつもりはありません。私は、新しいインデックス(プログラムで作成している)をそのデータソースにポイントする方法を知る必要があります。あなたの答えはそれを含んでいません。 – birdus

    +0

    私の悪いです、それはMicrosoft.Azure.Search.Models.Indexerですか?ここでは、TargetIndexName&DataSourceNameを指定できます – rajeshmag

    関連する問題