azure - Azure 搜索:缓存 ServiceClient 而不依赖于 v11 中的索引名称
问题描述
我目前使用 Azure 搜索 API 的 v10 并创建一个静态变量,如下所示:
private static SearchServiceClient SearchServiceClient = new SearchServiceClient(searchServiceName, credentials);
在服务器端,这个变量在请求之间重复使用,所以我不必一遍又一遍地初始化它。我从https://docs.microsoft.com/en-us/azure/azure-functions/manage-connections得到了提高性能的想法。
现在,v11 拥有完全不同的数据类型。新SearchClient
类型的构造函数需要一个索引名称作为参数。我有很多索引,我想避免为每个索引创建一个静态变量,
在 v11 中,是否可以像以前那样重用搜索客户端?
解决方案
在 v11 中,SearchServiceClient
实际上分为 3 个不同的客户端:SearchClient
、SearchIndexClient
、SearchIndexerClient
,每个客户端都有不同的用法。您可以在此处查看详细信息。
因此,当您使用 时SearchClient
,它被定义为具有索引名称参数。您不能像SearchServiceClient
v10 中那样重复使用它。
但你可以这样做:
SearchIndexClient adminClient = new SearchIndexClient(serviceEndpoint, credential);
SearchClient ingesterClient = adminClient.GetSearchClient(indexName);
推荐阅读
- android - 如何根据 Ionic 3 中的用户输入在 JSON 数组中选择一个对象?
- java - 在 JSPX ADF 中播放媒体?
- asp.net-identity - IdentityUser 连接到 CreatedBy 和 ChangedBy
- mongodb - 如何查找不包含提及的单词的文档?
- facebook - Facebook 目标搜索空城市列表
- java - 如何为某些整数添加错误消息?
- virtualbox - 从主机访问 ADFS 端点
- angular - 将字体系列功能添加到 Angular 中的 CKEditor 工具栏
- javascript - React:将焦点放在componentDidMount上,如何用钩子做?
- documentation - 基于swagger2.0的文档中MIT有什么用