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.
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:
WaitForTask
to wait until indexing operations are doneWaitForAppTask
to wait for application-level tasksWaitForApiKey
to wait for API key operations
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
).