Upgrade the C# API clients to v7

The latest major version of the Algolia.Search package is v7. This page lists the breaking changes since the last release, v6.

Method changes overview

The following table has links for all methods and their replacements

Search API client

v6 (legacy) v7 (latest)
client.AddApiKey client.AddApiKey
client.AddApiKey.wait client.WaitForApiKey
client.AssignUserID client.AssignUserId
not available client.BatchAssignUserIds
DictionaryClient.ClearDictionaryEntries client.BatchDictionaryEntries
client.CopyIndex client.OperationIndex
client.CopyRules client.OperationIndex
client.CopySynonyms client.OperationIndex
client.DeleteApiKey client.DeleteApiKey
DictionaryClient.DeleteDictionaryEntries client.BatchDictionaryEntries
client.GenerateSecuredApiKey client.GenerateSecuredApiKey
client.GetApiKey client.GetApiKey
client.GetSecuredApiKeyRemainingValidity client.GetSecuredApiKeyRemainingValidity
client.GetTopUserID client.GetTopUserIds
client.GetUserID client.GetUserId
client.ListApiKeys client.ListApiKeys
client.ListIndices client.ListIndices
client.ListUserIDs client.ListUserIds
client.MoveIndex client.OperationIndex
client.MultipleBatch client.MultipleBatch
client.MultipleQueries client.Search
client.RemoveUserID client.RemoveUserId
DictionaryClient.ReplaceDictionaryEntries client.BatchDictionaryEntries
client.RestoreApiKey client.RestoreApiKey
DictionaryClient.SaveDictionaryEntries client.BatchDictionaryEntries
client.SearchUserIds client.SearchUserIds
client.UpdateApiKey client.UpdateApiKey
index.Batch client.Batch
index.Browse client.BrowseObjects
index.BrowseRules client.BrowseRules
index.BrowseSynonyms client.BrowseSynonyms
index.ClearObjects client.ClearObjects
index.ClearRules client.ClearRules
index.ClearSynonyms client.ClearSynonyms
index.CopySettings client.OperationIndex
index.Delete client.DeleteIndex
index.DeleteBy client.DeleteBy
index.DeleteObject client.DeleteObject
index.DeleteObjects client.DeleteObjects
index.DeleteRule client.DeleteRule
index.DeleteSynonym client.DeleteSynonym
index.FindObject client.SearchSingleIndex
index.GetObject client.GetObject
index.GetObjects client.GetObjects
index.GetRule client.GetRule
index.GetSettings client.GetSettings
index.GetSynonym client.GetSynonym
index.GetTask client.GetTask
index.PartialUpdateObject client.PartialUpdateObject
index.PartialUpdateObjects client.PartialUpdateObjects
index.ReplaceAllObjects client.ReplaceAllObjects
index.ReplaceAllRules client.SaveRules
index.ReplaceAllSynonyms client.SaveSynonyms
index.SaveObject client.SaveObject
index.SaveObjects client.SaveObjects
index.SaveRule client.SaveRule
index.SaveRules client.SaveRules
index.SaveSynonym client.SaveSynonym
index.SaveSynonyms client.SaveSynonyms
index.Search client.SearchSingleIndex
index.SearchForFacetValues client.SearchForFacetValues
index.SearchRules client.SearchRules
index.SearchSynonyms client.SearchSynonyms
index.SetSettings client.SetSettings
index.{operation}.wait client.WaitForTask

Recommend API client

v6 (legacy) v7 (latest)
client.GetFrequentlyBoughtTogether client.GetRecommendations
client.GetRecommendations client.GetRecommendations
client.GetRelatedProducts client.GetRecommendations

Removal of InitIndex

All methods are methods of a client instance. The InitIndex method of the SearchClient class has been removed. Instead, all methods require a indexName parameter.

1
2
3
4
5
6
7
8
9
10
// v6
var client = new SearchClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");
var index = client.InitIndex("ALGOLIA_INDEX_NAME");

// v7
var client = new SearchClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");
client.SearchSingleIndex<Hit>(
    "ALGOLIA_INDEX_NAME",
    new SearchParams(new SearchParamsObject { Query = "QUERY"})
);

Wait for tasks

The Wait method has been removed. Instead, use one of the following helpers:

Copy or moving indices, settings, synonyms, or rules

Use the OperationIndex method, which replaces the following methods:

  • CopyIndex
  • MoveIndex
  • CopyRules
  • CopySynonyms
  • CopySettings

Serialization library

The Algolia.Search package no longer depends on the Newtonsoft.Json package to serialize the request and deserialize the response. The API client uses .NET’s official System.Text.Json package.

If you were using the Newtonsoft.Json package for custom serialization, see Migrate from Newtonsoft.Json to System.Text.Json in Microsoft’s documentation.

Enumeration type serialization

To keep the serialization of enumeration types consistent with previous versions of the .NET API client, they’re serialized as int by default.

To serialize enumeration types as strings, use the JsonStringEnumConverter attribute from System.Text.Json.Serialization.

1
2
3
4
5
6
7
8
9
10
11
12
13
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum MyEnum
{
    MyValue1,
    MyValue2
}

public class MyModel
{
    public MyEnum MyProperty { get; set; }
}

client.SaveObjectAsync("MyIndex", new MyModel { MyProperty = MyEnum.MyValue2 })

With this, the MyProperty property will be serialized as string ("MyValue2) instead of an integer (1).

Did you find this page helpful?
C# API clients v7