Skip to content

Commit 1b40b93

Browse files
authored
[Search] Add indexer client timeout sample code (Azure#24506)
* add timeout sample code * Split SearchClientOptions into new subsection * fix failed build * Add SearchClientOptions snippet to sample * check SNIPPET
1 parent 487614e commit 1b40b93

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

sdk/search/Azure.Search.Documents/samples/Sample02_Service.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,28 @@ SearchIndexerDataSourceConnection dataSourceConnection = new SearchIndexerDataSo
131131
await indexerClient.CreateDataSourceConnectionAsync(dataSourceConnection);
132132
```
133133

134+
#### Create SearchClientOptions
135+
136+
To control specific request behaviors such as timeouts and retries, you can create a client with options.
137+
138+
```C# Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_SearchClientOptions
139+
// Create SearchIndexerClient options
140+
SearchClientOptions options = new SearchClientOptions()
141+
{
142+
Transport = new HttpClientTransport(new HttpClient()
143+
{
144+
// Increase timeout for each request to 5 minutes
145+
Timeout = TimeSpan.FromMinutes(5)
146+
});
147+
};
148+
149+
// Increase retry attempts to 6
150+
options.Retry.MaxRetries = 6;
151+
152+
// Create a new SearchIndexerClient with options
153+
indexerClient = new SearchIndexerClient(endpoint, credential, options);
154+
```
155+
134156
### Create a Skillset
135157

136158
To provide French translations of descriptions, we'll define a [translation skill](https://docs.microsoft.com/azure/search/cognitive-search-skill-text-translation) to translate from English.

sdk/search/Azure.Search.Documents/tests/Samples/Sample01_HelloWorld.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,26 @@ public async Task CreateIndexerAsync()
276276
// index is deleted when our SearchResources goes out of scope.
277277
cleanUpTasks.Push(() => indexerClient.DeleteDataSourceConnectionAsync(dataSourceConnectionName));
278278

279+
#if SNIPPET
280+
#region Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_SearchClientOptions
281+
// Create SearchIndexerClient options
282+
SearchClientOptions options = new SearchClientOptions()
283+
{
284+
Transport = new HttpClientTransport(new HttpClient()
285+
{
286+
// Increase timeout for each request to 5 minutes
287+
Timeout = TimeSpan.FromMinutes(5)
288+
});
289+
};
290+
291+
// Increase retry attempts to 6
292+
options.Retry.MaxRetries = 6;
293+
294+
// Create a new SearchIndexerClient with options
295+
indexerClient = new SearchIndexerClient(endpoint, credential, options);
296+
#endregion Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_SearchClientOptions
297+
#endif
298+
279299
#region Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_Skillset
280300
// Translate English descriptions to French.
281301
// See https://docs.microsoft.com/azure/search/cognitive-search-skill-text-translation for details of the Text Translation skill.

0 commit comments

Comments
 (0)