SearchIndexClient class
用于执行管理(创建、更新、列出/删除)索引 & 同义词映射的作的类。
构造函数
| Search |
创建 SearchIndexClient 的实例。 示例用法:
|
属性
| api |
与服务通信时要使用的 API 版本。 |
| endpoint | 搜索服务的终结点 |
| pipeline | 对用于原始请求的内部 HTTP 管道的引用 |
| service |
与服务通信时要使用的 API 版本。 |
方法
| analyze |
在提供的文本上手动调用分析器或 tokenizer。 |
| create |
创建新的搜索别名。 |
| create |
创建新的索引。 |
| create |
创造新的知识库。 |
| create |
创建新的知识源。 |
| create |
创建新的搜索别名或更新别名(如果已存在)。 |
| create |
创建新的索引或修改现有索引。 |
| create |
创建新的知识库,或者如果已有知识库就更新。 |
| create |
创建或更新使用明确名称的知识库。 |
| create |
|
| create |
创建新的 SynonymMap 或修改现有同义词映射。 |
| create |
在搜索服务中创建新的 SynonymMap。 |
| delete |
删除搜索别名及其关联到索引的映射。 此作是永久性的,没有恢复选项。 此操作未触及映射索引。 |
| delete |
删除搜索别名及其关联到索引的映射。 此作是永久性的,没有恢复选项。 此操作未触及映射索引。 |
| delete |
删除现有索引。 |
| delete |
删除现有索引。 |
| delete |
删除现有知识库。 |
| delete |
删除现有知识库。 |
| delete |
删除现有源。 |
| delete |
删除现有源。 |
| delete |
从文件知识源删除文件,并移除所有由该文件衍生的索引内容。 |
| delete |
删除现有的 SynonymMap。 |
| get |
检索别名定义。 |
| get |
检索有关索引的信息。 |
| get |
检索有关索引的统计信息,例如文档计数和索引存储的大小。 |
| get |
检索知识库定义。 |
| get |
检索与此 SearchIndexClient 对应的 KnowledgeRetrievalClient |
| get |
检索知识源定义。 |
| get |
返回知识源的当前状态和同步历史记录。 |
| get |
检索与此 SearchIndexClient 对应的 SearchClient |
| get |
检索有关服务的统计信息,例如文档计数、索引等。 |
| get |
检索有关 SynonymMap 的信息。 |
| list |
列出可用于搜索服务的所有别名。 |
| list |
检索服务中现有索引的列表。 |
| list |
检索服务中现有索引的名称列表。 |
| list |
检索搜索服务中所有索引的统计信息摘要。 |
| list |
检索服务中现有的知识库列表。 |
| list |
列出文件知识源中的所有文件。 |
| list |
检索服务中现有知识源的列表。 |
| list |
检索服务中现有 SynonymMap 的列表。 |
| list |
检索服务中现有 SynonymMap 的名称列表。 |
| update |
替换文件知识源中的现有文件及其元数据。 示例 上传并更新一个文件知识源文件。
|
| upload |
通过多部分表单数据将文件及其元数据上传到文件知识源。 示例 上传带有结构化元数据的文件。
|
构造函数详细信息
SearchIndexClient(string, KeyCredential | TokenCredential, SearchIndexClientOptions)
创建 SearchIndexClient 的实例。
示例用法:
import { SearchIndexClient, AzureKeyCredential } from "@azure/search-documents";
const indexClient = new SearchIndexClient("<endpoint>", new AzureKeyCredential("<apiKey>"));
new SearchIndexClient(endpoint: string, credential: KeyCredential | TokenCredential, options?: SearchIndexClientOptions)
参数
- endpoint
-
string
搜索服务的终结点
- credential
用于对服务的请求进行身份验证。
- options
- SearchIndexClientOptions
用于配置搜索索引客户端。
属性详细信息
apiVersion
警告
现已弃用此 API。
use {@Link serviceVersion} instead
与服务通信时要使用的 API 版本。
apiVersion: string
属性值
string
endpoint
搜索服务的终结点
endpoint: string
属性值
string
pipeline
serviceVersion
与服务通信时要使用的 API 版本。
serviceVersion: string
属性值
string
方法详细信息
analyzeText(string, AnalyzeTextOptions)
在提供的文本上手动调用分析器或 tokenizer。
function analyzeText(indexName: string, options: AnalyzeTextOptions): Promise<AnalyzeResult>
参数
- indexName
-
string
包含要分析的字段的索引的名称
- options
- AnalyzeTextOptions
其他参数
返回
Promise<AnalyzeResult>
createAlias(SearchAlias, OperationOptions)
创建新的搜索别名。
function createAlias(alias: SearchAlias, options?: OperationOptions): Promise<SearchAlias>
参数
- alias
- SearchAlias
要创建的别名的定义。
- options
- OperationOptions
选项参数。
返回
Promise<SearchAlias>
createIndex(SearchIndex, OperationOptions)
创建新的索引。
function createIndex(index: SearchIndex, options?: OperationOptions): Promise<SearchIndex>
参数
- index
- SearchIndex
描述要创建的索引的信息。
- options
- OperationOptions
其他可选参数。
返回
Promise<SearchIndex>
createKnowledgeBase(KnowledgeBase, CreateKnowledgeBaseOptions)
创造新的知识库。
function createKnowledgeBase(knowledgeBase: KnowledgeBase, options?: CreateKnowledgeBaseOptions): Promise<KnowledgeBase>
参数
- knowledgeBase
- KnowledgeBase
定义要创建的知识库。
- options
- CreateKnowledgeBaseOptions
options 参数。
返回
Promise<KnowledgeBase>
createKnowledgeSource(KnowledgeSource, CreateKnowledgeSourceOptions)
创建新的知识源。
function createKnowledgeSource(knowledgeSource: KnowledgeSource, options?: CreateKnowledgeSourceOptions): Promise<KnowledgeSource>
参数
- knowledgeSource
- KnowledgeSource
要创建的知识源的定义。
- options
- CreateKnowledgeSourceOptions
选项参数。
返回
Promise<KnowledgeSource>
createOrUpdateAlias(SearchAlias, CreateOrUpdateAliasOptions)
创建新的搜索别名或更新别名(如果已存在)。
function createOrUpdateAlias(alias: SearchAlias, options?: CreateOrUpdateAliasOptions): Promise<SearchAlias>
参数
- alias
- SearchAlias
要创建或更新的别名的定义。
- options
- CreateOrUpdateAliasOptions
选项参数。
返回
Promise<SearchAlias>
createOrUpdateIndex(SearchIndex, CreateOrUpdateIndexOptions)
创建新的索引或修改现有索引。
function createOrUpdateIndex(index: SearchIndex, options?: CreateOrUpdateIndexOptions): Promise<SearchIndex>
参数
- index
- SearchIndex
描述要创建的索引的信息。
- options
- CreateOrUpdateIndexOptions
其他可选参数。
返回
Promise<SearchIndex>
createOrUpdateKnowledgeBase(KnowledgeBase, CreateOrUpdateKnowledgeBaseOptions)
创建新的知识库,或者如果已有知识库就更新。
function createOrUpdateKnowledgeBase(knowledgeBase: KnowledgeBase, options?: CreateOrUpdateKnowledgeBaseOptions): Promise<KnowledgeBase>
参数
- knowledgeBase
- KnowledgeBase
定义用于创建或更新的知识库。
options 参数。
返回
Promise<KnowledgeBase>
创建或更新的知识库。
createOrUpdateKnowledgeBase(string, KnowledgeBase, CreateOrUpdateKnowledgeBaseOptions)
警告
现已弃用此 API。
Pass the knowledge base model first; its name property identifies the resource.
创建或更新使用明确名称的知识库。
function createOrUpdateKnowledgeBase(knowledgeBaseName: string, knowledgeBase: KnowledgeBase, options?: CreateOrUpdateKnowledgeBaseOptions): Promise<KnowledgeBase>
参数
- knowledgeBaseName
-
string
- knowledgeBase
- KnowledgeBase
返回
Promise<KnowledgeBase>
createOrUpdateKnowledgeSource(KnowledgeSource, CreateOrUpdateKnowledgeSourceOptions)
function createOrUpdateKnowledgeSource(knowledgeSource: KnowledgeSource, options?: CreateOrUpdateKnowledgeSourceOptions): Promise<KnowledgeSource>
参数
- knowledgeSource
- KnowledgeSource
返回
Promise<KnowledgeSource>
createOrUpdateSynonymMap(SynonymMap, CreateOrUpdateSynonymMapOptions)
创建新的 SynonymMap 或修改现有同义词映射。
function createOrUpdateSynonymMap(synonymMap: SynonymMap, options?: CreateOrUpdateSynonymMapOptions): Promise<SynonymMap>
参数
- synonymMap
- SynonymMap
描述要创建的 SynonymMap 的信息。
- options
- CreateOrUpdateSynonymMapOptions
其他可选参数。
返回
Promise<SynonymMap>
createSynonymMap(SynonymMap, OperationOptions)
在搜索服务中创建新的 SynonymMap。
function createSynonymMap(synonymMap: SynonymMap, options?: OperationOptions): Promise<SynonymMap>
参数
- synonymMap
- SynonymMap
在搜索服务中创建的 synonymMap 定义。
- options
- OperationOptions
其他可选参数。
返回
Promise<SynonymMap>
deleteAlias(SearchAlias, DeleteAliasOptions)
删除搜索别名及其关联到索引的映射。 此作是永久性的,没有恢复选项。 此操作未触及映射索引。
function deleteAlias(alias: SearchAlias, options?: DeleteAliasOptions): Promise<void>
参数
- alias
- SearchAlias
要删除的别名。
- options
- DeleteAliasOptions
其他可选参数。
返回
Promise<void>
deleteAlias(string, DeleteAliasOptions)
删除搜索别名及其关联到索引的映射。 此作是永久性的,没有恢复选项。 此操作未触及映射索引。
function deleteAlias(aliasName: string, options?: DeleteAliasOptions): Promise<void>
参数
- aliasName
-
string
要删除的别名的名称。
- options
- DeleteAliasOptions
其他可选参数。
返回
Promise<void>
deleteIndex(SearchIndex, DeleteIndexOptions)
删除现有索引。
function deleteIndex(index: SearchIndex, options?: DeleteIndexOptions): Promise<void>
参数
- index
- SearchIndex
要删除的索引。
- options
- DeleteIndexOptions
其他可选参数。
返回
Promise<void>
deleteIndex(string, DeleteIndexOptions)
删除现有索引。
function deleteIndex(indexName: string, options?: DeleteIndexOptions): Promise<void>
参数
- indexName
-
string
要删除的索引的名称。
- options
- DeleteIndexOptions
其他可选参数。
返回
Promise<void>
deleteKnowledgeBase(KnowledgeBase, DeleteKnowledgeBaseOptions)
删除现有知识库。
function deleteKnowledgeBase(knowledgeBase: KnowledgeBase, options?: DeleteKnowledgeBaseOptions): Promise<void>
参数
- knowledgeBase
- KnowledgeBase
需要删除知识库。
- options
- DeleteKnowledgeBaseOptions
options 参数。
返回
Promise<void>
deleteKnowledgeBase(string, DeleteKnowledgeBaseOptions)
删除现有知识库。
function deleteKnowledgeBase(knowledgeBaseName: string, options?: DeleteKnowledgeBaseOptions): Promise<void>
参数
- knowledgeBaseName
-
string
要删除的知识库名称。
- options
- DeleteKnowledgeBaseOptions
options 参数。
返回
Promise<void>
deleteKnowledgeSource(KnowledgeSource, DeleteKnowledgeSourceOptions)
删除现有源。
function deleteKnowledgeSource(source: KnowledgeSource, options?: DeleteKnowledgeSourceOptions): Promise<void>
参数
- source
- KnowledgeSource
要删除的知识源。
- options
- DeleteKnowledgeSourceOptions
options 参数。
返回
Promise<void>
deleteKnowledgeSource(string, DeleteKnowledgeSourceOptions)
删除现有源。
function deleteKnowledgeSource(sourceName: string, options?: DeleteKnowledgeSourceOptions): Promise<void>
参数
- sourceName
-
string
要删除的知识源的名称。
- options
- DeleteKnowledgeSourceOptions
options 参数。
返回
Promise<void>
deleteKnowledgeSourceFile(string, string, DeleteKnowledgeSourceFileOptions)
从文件知识源删除文件,并移除所有由该文件衍生的索引内容。
function deleteKnowledgeSourceFile(name: string, fileId: string, options?: DeleteKnowledgeSourceFileOptions): Promise<void>
参数
- name
-
string
知识源的名称。
- fileId
-
string
文件标识符。
- options
- DeleteKnowledgeSourceFileOptions
选项参数。
返回
Promise<void>
deleteSynonymMap(string | SynonymMap, DeleteSynonymMapOptions)
删除现有的 SynonymMap。
function deleteSynonymMap(synonymMap: string | SynonymMap, options?: DeleteSynonymMapOptions): Promise<void>
参数
- synonymMap
-
string | SynonymMap
- options
- DeleteSynonymMapOptions
其他可选参数。
返回
Promise<void>
getAlias(string, OperationOptions)
检索别名定义。
function getAlias(aliasName: string, options?: OperationOptions): Promise<SearchAlias>
参数
- aliasName
-
string
要检索的别名的名称。
- options
- OperationOptions
选项参数。
返回
Promise<SearchAlias>
getIndex(string, OperationOptions)
检索有关索引的信息。
function getIndex(indexName: string, options?: OperationOptions): Promise<SearchIndex>
参数
- indexName
-
string
索引的名称。
- options
- OperationOptions
其他可选参数。
返回
Promise<SearchIndex>
getIndexStatistics(string, OperationOptions)
检索有关索引的统计信息,例如文档计数和索引存储的大小。
function getIndexStatistics(indexName: string, options?: OperationOptions): Promise<SearchIndexStatistics>
参数
- indexName
-
string
索引的名称。
- options
- OperationOptions
其他可选参数。
返回
Promise<SearchIndexStatistics>
getKnowledgeBase(string, GetKnowledgeBaseOptions)
检索知识库定义。
function getKnowledgeBase(knowledgeBaseName: string, options?: GetKnowledgeBaseOptions): Promise<KnowledgeBase>
参数
- knowledgeBaseName
-
string
要检索的知识库名称。
- options
- GetKnowledgeBaseOptions
options 参数。
返回
Promise<KnowledgeBase>
getKnowledgeRetrievalClient(string, KnowledgeRetrievalClientOptions)
检索与此 SearchIndexClient 对应的 KnowledgeRetrievalClient
function getKnowledgeRetrievalClient(knowledgeBaseName: string, options?: KnowledgeRetrievalClientOptions): KnowledgeRetrievalClient
参数
- knowledgeBaseName
-
string
知识库名称
- options
- KnowledgeRetrievalClientOptions
KnowledgeRetrievalClient 选项
返回
getKnowledgeSource(string, GetKnowledgeSourceOptions)
检索知识源定义。
function getKnowledgeSource(sourceName: string, options?: GetKnowledgeSourceOptions): Promise<KnowledgeSource>
参数
- sourceName
-
string
要检索的知识源的名称。
- options
- GetKnowledgeSourceOptions
选项参数。
返回
Promise<KnowledgeSource>
getKnowledgeSourceStatus(string, GetKnowledgeSourceStatusOptions)
返回知识源的当前状态和同步历史记录。
function getKnowledgeSourceStatus(sourceName: string, options?: GetKnowledgeSourceStatusOptions): Promise<KnowledgeSourceStatus>
参数
- sourceName
-
string
要检索其状态的知识源的名称。
- options
- GetKnowledgeSourceStatusOptions
选项参数。
返回
Promise<KnowledgeSourceStatus>
getSearchClient<TModel>(string, SearchClientOptions)
检索与此 SearchIndexClient 对应的 SearchClient
function getSearchClient<TModel>(indexName: string, options?: SearchClientOptions): SearchClient<TModel>
参数
- indexName
-
string
索引的名称
- options
- SearchClientOptions
SearchClient 选项
返回
SearchClient<TModel>
getServiceStatistics(OperationOptions)
检索有关服务的统计信息,例如文档计数、索引等。
function getServiceStatistics(options?: OperationOptions): Promise<SearchServiceStatistics>
参数
- options
- OperationOptions
其他可选参数。
返回
Promise<SearchServiceStatistics>
getSynonymMap(string, OperationOptions)
检索有关 SynonymMap 的信息。
function getSynonymMap(synonymMapName: string, options?: OperationOptions): Promise<SynonymMap>
参数
- synonymMapName
-
string
SynonymMap 的名称。
- options
- OperationOptions
其他可选参数。
返回
Promise<SynonymMap>
listAliases(ListAliasesOptions)
列出可用于搜索服务的所有别名。
function listAliases(options?: ListAliasesOptions): AliasIterator
参数
- options
- ListAliasesOptions
选项参数。
返回
listIndexes(ResourceListingOptions)
检索服务中现有索引的列表。
function listIndexes(options?: ResourceListingOptions): IndexIterator
参数
- options
- ResourceListingOptions
列表索引作的选项。
返回
listIndexesNames(ResourceListingOptions)
检索服务中现有索引的名称列表。
function listIndexesNames(options?: ResourceListingOptions): IndexNameIterator
参数
- options
- ResourceListingOptions
列表索引作的选项。
返回
listIndexStatsSummary(ListIndexStatsSummaryOptions)
检索搜索服务中所有索引的统计信息摘要。
function listIndexStatsSummary(options?: ListIndexStatsSummaryOptions): PagedAsyncIterableIterator<IndexStatisticsSummary, IndexStatisticsSummary[], PageSettings>
参数
- options
- ListIndexStatsSummaryOptions
列表索引统计摘要操作的选项。
返回
PagedAsyncIterableIterator<IndexStatisticsSummary, IndexStatisticsSummary[], PageSettings>
listKnowledgeBases(ListKnowledgeBasesOptions)
检索服务中现有的知识库列表。
function listKnowledgeBases(options?: ListKnowledgeBasesOptions): KnowledgeBaseIterator
参数
- options
- ListKnowledgeBasesOptions
列表知识库作的选项。
返回
listKnowledgeSourceFiles(string, ListKnowledgeSourceFilesOptions)
列出文件知识源中的所有文件。
function listKnowledgeSourceFiles(name: string, options?: ListKnowledgeSourceFilesOptions): PagedAsyncIterableIterator<KnowledgeSourceFile, KnowledgeSourceFile[], PageSettings>
参数
- name
-
string
知识源的名称。
- options
- ListKnowledgeSourceFilesOptions
选项参数。
返回
PagedAsyncIterableIterator<KnowledgeSourceFile, KnowledgeSourceFile[], PageSettings>
listKnowledgeSources(ListKnowledgeSourcesOptions)
检索服务中现有知识源的列表。
function listKnowledgeSources(options?: ListKnowledgeSourcesOptions): KnowledgeSourceIterator
参数
- options
- ListKnowledgeSourcesOptions
列出知识源作的选项。
返回
listSynonymMaps(ResourceListingOptions)
检索服务中现有 SynonymMap 的列表。
function listSynonymMaps(options?: ResourceListingOptions): Promise<SynonymMap[]>
参数
- options
- ResourceListingOptions
列表 SynonymMaps作的选项。
返回
Promise<SynonymMap[]>
listSynonymMapsNames(ResourceListingOptions)
检索服务中现有 SynonymMap 的名称列表。
function listSynonymMapsNames(options?: ResourceListingOptions): Promise<string[]>
参数
- options
- ResourceListingOptions
列表 SynonymMaps作的选项。
返回
Promise<string[]>
updateKnowledgeSourceFile(string, string, UpdateKnowledgeSourceFileRequest, UpdateKnowledgeSourceFileOptions)
替换文件知识源中的现有文件及其元数据。
示例
上传并更新一个文件知识源文件。
import { SearchIndexClient, AzureKeyCredential } from "@azure/search-documents";
const client = new SearchIndexClient("<endpoint>", new AzureKeyCredential("<apiKey>"));
const body = {
metadata: { fileName: "manuals/example.txt", metadata: { category: "manual" } },
content: {
contents: new TextEncoder().encode("Azure AI Search retrieves relevant information."),
contentType: "text/plain",
filename: "example.txt",
},
};
const uploaded = await client.uploadKnowledgeSourceFileMultipart("<knowledgeSourceName>", body);
if (!uploaded.fileId) {
throw new Error("The service did not return an uploaded file ID.");
}
await client.updateKnowledgeSourceFile("<knowledgeSourceName>", uploaded.fileId, {
...body,
metadata: { ...body.metadata, metadata: { category: "updated-manual" } },
});
for await (const file of client.listKnowledgeSourceFiles("<knowledgeSourceName>", {
prefix: "manuals/",
pageSize: 10,
})) {
console.log(file.fileName, file.parsingMode, file.extractionMode);
}
function updateKnowledgeSourceFile(name: string, fileId: string, body: UpdateKnowledgeSourceFileRequest, options?: UpdateKnowledgeSourceFileOptions): Promise<KnowledgeSourceFile>
参数
- name
-
string
知识源的名称。
- fileId
-
string
文件标识符。
替换文件内容和元数据。
- options
- UpdateKnowledgeSourceFileOptions
选项参数。
返回
Promise<KnowledgeSourceFile>
文件的元数据已更新。
uploadKnowledgeSourceFileMultipart(string, UploadKnowledgeSourceFileMultipartRequest, UploadKnowledgeSourceFileMultipartOptions)
通过多部分表单数据将文件及其元数据上传到文件知识源。
示例
上传带有结构化元数据的文件。
import { SearchIndexClient, AzureKeyCredential } from "@azure/search-documents";
const client = new SearchIndexClient("<endpoint>", new AzureKeyCredential("<apiKey>"));
const body = {
metadata: { fileName: "manuals/example.txt", metadata: { category: "manual" } },
content: {
contents: new TextEncoder().encode("Azure AI Search retrieves relevant information."),
contentType: "text/plain",
filename: "example.txt",
},
};
const uploaded = await client.uploadKnowledgeSourceFileMultipart("<knowledgeSourceName>", body);
if (!uploaded.fileId) {
throw new Error("The service did not return an uploaded file ID.");
}
await client.updateKnowledgeSourceFile("<knowledgeSourceName>", uploaded.fileId, {
...body,
metadata: { ...body.metadata, metadata: { category: "updated-manual" } },
});
for await (const file of client.listKnowledgeSourceFiles("<knowledgeSourceName>", {
prefix: "manuals/",
pageSize: 10,
})) {
console.log(file.fileName, file.parsingMode, file.extractionMode);
}
function uploadKnowledgeSourceFileMultipart(name: string, body: UploadKnowledgeSourceFileMultipartRequest, options?: UploadKnowledgeSourceFileMultipartOptions): Promise<KnowledgeSourceFile>
参数
- name
-
string
知识源的名称。
文件内容和元数据。
选项参数。
返回
Promise<KnowledgeSourceFile>
上传文件的元数据。