Package version:
Creates an instance of SearchClient.
Example usage:
const { SearchClient, AzureKeyCredential } = require("@azure/search-documents");
const client = new SearchClient(
"<endpoint>",
"<indexName>",
new AzureKeyCredential("<Admin Key>")
);
Optionally, the type of the model can be used to enable strong typing and type hints:
type TModel = {
keyName: string;
field1?: string | null;
field2?: { anotherField?: string | null } | null;
};
const client = new SearchClient<TModel>(
...
);
The endpoint of the search service
The name of the index
Used to authenticate requests to the service.
Used to configure the Search client.
Readonly
apiThe API version to use when communicating with the service.
Readonly
endpointThe endpoint of the search service
Readonly
indexThe name of the index
Readonly
pipelineA reference to the internal HTTP pipeline for use with raw requests
Readonly
serviceThe service version to use when communicating with the service.
Based on a partial searchText from the user, return a list of potential completion strings based on a specified suggester.
The search text on which to base autocomplete results.
The name of the suggester as specified in the suggesters collection that's part of the index definition.
Options to the autocomplete operation.
import {
AzureKeyCredential,
SearchClient,
SearchFieldArray,
} from "@azure/search-documents";
type TModel = {
key: string;
azure?: { sdk: string | null } | null;
};
const client = new SearchClient<TModel>(
"endpoint.azure",
"indexName",
new AzureKeyCredential("key")
);
const searchFields: SearchFieldArray<TModel> = ["azure/sdk"];
const autocompleteResult = await client.autocomplete(
"searchText",
"suggesterName",
{ searchFields }
);
Delete a set of documents.
Documents to be deleted.
Optional
options: IndexDocumentsOptionsAdditional options.
Delete a set of documents.
The name of their primary key in the index.
The primary key values of documents to delete.
Optional
options: IndexDocumentsOptionsAdditional options.
Retrieve a particular document from the index by key.
The primary key value of the document
Additional options
Perform a set of index modifications (upload, merge, mergeOrUpload, delete)
for the given set of documents.
This operation may partially succeed and not all document operations will
be reflected in the index. If you would like to treat this as an exception,
set the throwOnAnyFailure
option to true.
For more details about how merging works, see: https://docs.microsoft.com/en-us/rest/api/searchservice/AddUpdate-or-Delete-Documents
An array of actions to perform on the index.
Additional options.
Update a set of documents in the index. For more details about how merging works, see https://docs.microsoft.com/en-us/rest/api/searchservice/AddUpdate-or-Delete-Documents
The updated documents.
Additional options.
Update a set of documents in the index or upload them if they don't exist. For more details about how merging works, see https://docs.microsoft.com/en-us/rest/api/searchservice/AddUpdate-or-Delete-Documents
The updated documents.
Additional options.
Performs a search on the current index given the specified arguments.
Optional
searchText: stringText to search
Optional
options: anyOptions for the search operation.
import {
AzureKeyCredential,
SearchClient,
SearchFieldArray,
} from "@azure/search-documents";
type TModel = {
key: string;
azure?: { sdk: string | null } | null;
};
const client = new SearchClient<TModel>(
"endpoint.azure",
"indexName",
new AzureKeyCredential("key")
);
const select = ["azure/sdk"] as const;
const searchFields: SearchFieldArray<TModel> = ["azure/sdk"];
const searchResult = await client.search("searchText", {
select,
searchFields,
});
Returns a short list of suggestions based on the searchText and specified suggester.
The search text to use to suggest documents. Must be at least 1 character, and no more than 100 characters.
The name of the suggester as specified in the suggesters collection that's part of the index definition.
Options for the suggest operation
import {
AzureKeyCredential,
SearchClient,
SearchFieldArray,
} from "@azure/search-documents";
type TModel = {
key: string;
azure?: { sdk: string | null } | null;
};
const client = new SearchClient<TModel>(
"endpoint.azure",
"indexName",
new AzureKeyCredential("key")
);
const select = ["azure/sdk"] as const;
const searchFields: SearchFieldArray<TModel> = ["azure/sdk"];
const suggestResult = await client.suggest("searchText", "suggesterName", {
select,
searchFields,
});
Upload an array of documents to the index.
The documents to upload.
Additional options.
Class used to perform operations against a search index, including querying documents in the index as well as adding, updating, and removing them.