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 |
擷取服務中現有 KnowledgeSource 的清單。 |
| 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)
擷取服務中現有 KnowledgeSource 的清單。
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>
上傳檔案的元資料。