SearchIndexClient Class
A client to interact with Azure search service index.
- Inheritance
-
azure.search.documents._headers_mixin.HeadersMixinSearchIndexClient
Constructor
SearchIndexClient(endpoint: str, credential: AzureKeyCredential | TokenCredential, **kwargs: Any)
Parameters
Name | Description |
---|---|
endpoint
Required
|
The URL endpoint of an Azure search service |
credential
Required
|
A credential to authorize search client requests |
Keyword-Only Parameters
Name | Description |
---|---|
api_version
|
The Search API version to use for requests. |
audience
|
sets the Audience to use for authentication with Azure Active Directory (AAD). The audience is not considered when using a shared key. If audience is not provided, the public cloud audience will be assumed. |
Methods
analyze_text |
Shows how an analyzer breaks text into tokens. |
close |
Close the session. :return: None :rtype: None |
create_index |
Creates a new search index. |
create_or_update_index |
Creates a new search index or updates an index if it already exists. |
create_or_update_synonym_map |
Create a new Synonym Map in an Azure Search service, or update an existing one. |
create_synonym_map |
Create a new Synonym Map in an Azure Search service |
delete_index |
Deletes a search index and all the documents it contains. The model must be provided instead of the name to use the access conditions. |
delete_synonym_map |
Delete a named Synonym Map in an Azure Search service. To use access conditions, the SynonymMap model must be provided instead of the name. It is enough to provide the name of the synonym map to delete unconditionally. |
get_index | |
get_index_statistics |
Returns statistics for the given index, including a document count and storage usage. |
get_search_client |
Return a client to perform operations on Search |
get_service_statistics |
Get service level statistics for a search service. |
get_synonym_map |
Retrieve a named Synonym Map in an Azure Search service |
get_synonym_map_names |
List the Synonym Map names in an Azure Search service. |
get_synonym_maps |
List the Synonym Maps in an Azure Search service. |
list_index_names |
List the index names in an Azure Search service. |
list_indexes |
List the indexes in an Azure Search service. |
send_request |
Runs a network request using the client's existing pipeline. |
analyze_text
Shows how an analyzer breaks text into tokens.
analyze_text(index_name: str, analyze_request: AnalyzeTextOptions, **kwargs: Any) -> AnalyzeResult
Parameters
Name | Description |
---|---|
index_name
Required
|
The name of the index for which to test an analyzer. |
analyze_request
Required
|
The text and analyzer or analysis components to test. |
Returns
Type | Description |
---|---|
AnalyzeResult |
Exceptions
Type | Description |
---|---|
Examples
Analyze text
from azure.core.credentials import AzureKeyCredential
from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents.indexes.models import AnalyzeTextOptions
client = SearchIndexClient(service_endpoint, AzureKeyCredential(key))
analyze_request = AnalyzeTextOptions(text="One's <two/>", analyzer_name="standard.lucene")
result = client.analyze_text(index_name, analyze_request)
print(result.as_dict())
close
Close the session. :return: None :rtype: None
close() -> None
Exceptions
Type | Description |
---|---|
create_index
Creates a new search index.
create_index(index: SearchIndex, **kwargs: Any) -> SearchIndex
Parameters
Name | Description |
---|---|
index
Required
|
The index object. |
Returns
Type | Description |
---|---|
The index created |
Exceptions
Type | Description |
---|---|
Examples
Creating a new index.
client = SearchIndexClient(service_endpoint, AzureKeyCredential(key))
name = "hotels"
fields = [
SimpleField(name="hotelId", type=SearchFieldDataType.String, key=True),
SimpleField(name="baseRate", type=SearchFieldDataType.Double),
SearchableField(name="description", type=SearchFieldDataType.String, collection=True),
ComplexField(
name="address",
fields=[
SimpleField(name="streetAddress", type=SearchFieldDataType.String),
SimpleField(name="city", type=SearchFieldDataType.String),
],
collection=True,
),
]
cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)
scoring_profiles: List[ScoringProfile] = []
index = SearchIndex(name=name, fields=fields, scoring_profiles=scoring_profiles, cors_options=cors_options)
result = client.create_index(index)
create_or_update_index
Creates a new search index or updates an index if it already exists.
create_or_update_index(index: SearchIndex, allow_index_downtime: bool | None = None, *, match_condition: MatchConditions = MatchConditions.Unconditionally, **kwargs: Any) -> SearchIndex
Parameters
Name | Description |
---|---|
index
Required
|
The index object. |
allow_index_downtime
Required
|
Allows new analyzers, tokenizers, token filters, or char filters to be added to an index by taking the index offline for at least a few seconds. This temporarily causes indexing and query requests to fail. Performance and write availability of the index can be impaired for several minutes after the index is updated, or longer for very large indexes. |
Keyword-Only Parameters
Name | Description |
---|---|
match_condition
|
The match condition to use upon the etag |
Returns
Type | Description |
---|---|
The index created or updated |
Exceptions
Type | Description |
---|---|
azure.core.exceptions.ResourceNotFoundError orazure.core.exceptions.ResourceModifiedError orazure.core.exceptions.ResourceNotModifiedError orazure.core.exceptions.ResourceNotFoundError orazure.core.exceptions.ResourceExistsError
|
Examples
Update an index.
client = SearchIndexClient(service_endpoint, AzureKeyCredential(key))
name = "hotels"
fields = [
SimpleField(name="hotelId", type=SearchFieldDataType.String, key=True),
SimpleField(name="baseRate", type=SearchFieldDataType.Double),
SearchableField(name="description", type=SearchFieldDataType.String, collection=True),
SearchableField(name="hotelName", type=SearchFieldDataType.String),
ComplexField(
name="address",
fields=[
SimpleField(name="streetAddress", type=SearchFieldDataType.String),
SimpleField(name="city", type=SearchFieldDataType.String),
SimpleField(name="state", type=SearchFieldDataType.String),
],
collection=True,
),
]
cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)
scoring_profile = ScoringProfile(name="MyProfile")
scoring_profiles = []
scoring_profiles.append(scoring_profile)
index = SearchIndex(name=name, fields=fields, scoring_profiles=scoring_profiles, cors_options=cors_options)
result = client.create_or_update_index(index=index)
create_or_update_synonym_map
Create a new Synonym Map in an Azure Search service, or update an existing one.
create_or_update_synonym_map(synonym_map: SynonymMap, *, match_condition: MatchConditions = MatchConditions.Unconditionally, **kwargs: Any) -> SynonymMap
Parameters
Name | Description |
---|---|
synonym_map
Required
|
The Synonym Map object |
Keyword-Only Parameters
Name | Description |
---|---|
match_condition
|
The match condition to use upon the etag |
Returns
Type | Description |
---|---|
The created or updated Synonym Map |
Exceptions
Type | Description |
---|---|
create_synonym_map
Create a new Synonym Map in an Azure Search service
create_synonym_map(synonym_map: SynonymMap, **kwargs: Any) -> SynonymMap
Parameters
Name | Description |
---|---|
synonym_map
Required
|
The Synonym Map object |
Returns
Type | Description |
---|---|
The created Synonym Map |
Exceptions
Type | Description |
---|---|
Examples
Create a Synonym Map
synonyms = [
"USA, United States, United States of America",
"Washington, Wash. => WA",
]
synonym_map = SynonymMap(name="test-syn-map", synonyms=synonyms)
result = client.create_synonym_map(synonym_map)
print("Create new Synonym Map 'test-syn-map succeeded")
delete_index
Deletes a search index and all the documents it contains. The model must be provided instead of the name to use the access conditions.
delete_index(index: str | SearchIndex, *, match_condition: MatchConditions = MatchConditions.Unconditionally, **kwargs: Any) -> None
Parameters
Name | Description |
---|---|
index
Required
|
str or
SearchIndex
The index name or object to delete. |
Keyword-Only Parameters
Name | Description |
---|---|
match_condition
|
The match condition to use upon the etag |
Exceptions
Type | Description |
---|---|
Examples
Delete an index.
client = SearchIndexClient(service_endpoint, AzureKeyCredential(key))
name = "hotels"
client.delete_index(name)
delete_synonym_map
Delete a named Synonym Map in an Azure Search service. To use access conditions, the SynonymMap model must be provided instead of the name. It is enough to provide the name of the synonym map to delete unconditionally.
delete_synonym_map(synonym_map: str | SynonymMap, *, match_condition: MatchConditions = MatchConditions.Unconditionally, **kwargs: Any) -> None
Parameters
Name | Description |
---|---|
synonym_map
Required
|
str or
SynonymMap
The synonym map name or object to delete |
Keyword-Only Parameters
Name | Description |
---|---|
match_condition
|
The match condition to use upon the etag |
Exceptions
Type | Description |
---|---|
Examples
Delete a Synonym Map
client.delete_synonym_map("test-syn-map")
print("Synonym Map 'test-syn-map' deleted")
get_index
get_index(name: str, **kwargs: Any) -> SearchIndex
Parameters
Name | Description |
---|---|
name
Required
|
The name of the index to retrieve. |
Returns
Type | Description |
---|---|
SearchIndex object |
Exceptions
Type | Description |
---|---|
Examples
Get an index.
client = SearchIndexClient(service_endpoint, AzureKeyCredential(key))
name = "hotels"
result = client.get_index(name)
get_index_statistics
Returns statistics for the given index, including a document count and storage usage.
get_index_statistics(index_name: str, **kwargs: Any) -> MutableMapping[str, Any]
Parameters
Name | Description |
---|---|
index_name
Required
|
The name of the index to retrieve. |
Returns
Type | Description |
---|---|
Statistics for the given index, including a document count and storage usage. |
Exceptions
Type | Description |
---|---|
get_search_client
Return a client to perform operations on Search
get_search_client(index_name: str, **kwargs: Any) -> SearchClient
Parameters
Name | Description |
---|---|
index_name
Required
|
The name of the Search Index |
Returns
Type | Description |
---|---|
SearchClient object |
Exceptions
Type | Description |
---|---|
get_service_statistics
Get service level statistics for a search service.
get_service_statistics(**kwargs: Any) -> MutableMapping[str, Any]
Returns
Type | Description |
---|---|
Service statistics result. |
Exceptions
Type | Description |
---|---|
get_synonym_map
Retrieve a named Synonym Map in an Azure Search service
get_synonym_map(name: str, **kwargs: Any) -> SynonymMap
Parameters
Name | Description |
---|---|
name
Required
|
The name of the Synonym Map to get |
Returns
Type | Description |
---|---|
The retrieved Synonym Map |
Exceptions
Type | Description |
---|---|
Examples
Get a Synonym Map
result = client.get_synonym_map("test-syn-map")
print("Retrived Synonym Map 'test-syn-map' with synonyms")
if result:
for syn in result.synonyms:
print(" {}".format(syn))
get_synonym_map_names
List the Synonym Map names in an Azure Search service.
get_synonym_map_names(**kwargs: Any) -> List[str]
Returns
Type | Description |
---|---|
List of synonym maps |
Exceptions
Type | Description |
---|---|
get_synonym_maps
List the Synonym Maps in an Azure Search service.
get_synonym_maps(*, select: List[str] | None = None, **kwargs) -> List[SynonymMap]
Keyword-Only Parameters
Name | Description |
---|---|
select
|
Selects which top-level properties of the skillsets to retrieve. Specified as a list of JSON property names, or '*' for all properties. The default is all properties. |
Returns
Type | Description |
---|---|
List of synonym maps |
Exceptions
Type | Description |
---|---|
Examples
List Synonym Maps
result = client.get_synonym_maps()
names = [x.name for x in result]
print("Found {} Synonym Maps in the service: {}".format(len(result), ", ".join(names)))
list_index_names
List the index names in an Azure Search service.
list_index_names(**kwargs: Any) -> ItemPaged[str]
Returns
Type | Description |
---|---|
List of index names |
Exceptions
Type | Description |
---|---|
list_indexes
List the indexes in an Azure Search service.
list_indexes(*, select: List[str] | None = None, **kwargs: Any) -> ItemPaged[SearchIndex]
Keyword-Only Parameters
Name | Description |
---|---|
select
|
Selects which top-level properties of the skillsets to retrieve. Specified as a list of JSON property names, or '*' for all properties. The default is all properties. |
Returns
Type | Description |
---|---|
List of indexes |
Exceptions
Type | Description |
---|---|
send_request
Runs a network request using the client's existing pipeline.
send_request(request: HttpRequest, *, stream: bool = False, **kwargs) -> HttpResponse
Parameters
Name | Description |
---|---|
request
Required
|
The network request you want to make. |
Keyword-Only Parameters
Name | Description |
---|---|
stream
|
Whether the response payload will be streamed. Defaults to False. |
Returns
Type | Description |
---|---|
The response of your network call. Does not do error handling on your response. |
Exceptions
Type | Description |
---|---|
Azure SDK for Python