Search code examples
azure-cognitive-searchazure-search-.net-sdk

Adding a scoring profile with the .NET client


I can't find how to use the .NET Client for Azure search to add a scoring profile. Yes, I know there's a doc to do it using the REST API Thanks.


Solution

  • The scoring profiles have to be created at the same time as the index:

    private async Task CreateIndexAsync<T>(string index) where T : class
    {
        var definition = new Index()
        {
           Name = index,
           Fields = FieldBuilder.BuildForType<T>(),
           ScoringProfiles = new List<ScoringProfile>
           {
               //your scoring profiles here
           }
       };
    
       if (!_adminServiceClient.Indexes.Exists(index))
       {
           await _adminServiceClient.Indexes.CreateAsync(definition);
       }
    
     }