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
- credential
- AzureKeyCredential or TokenCredential
A credential to authorize search client requests
- api_version
- str
The Search API version to use for requests.
- audience
- str
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 SearchIndexClient session. |
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. |
analyze_text
Shows how an analyzer breaks text into tokens.
analyze_text(index_name: str, analyze_request: AnalyzeTextOptions, **kwargs: Any) -> AnalyzeResult
Parameters
Returns
AnalyzeResult
Return type
Exceptions
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
create_index
Creates a new search index.
create_index(index: SearchIndex, **kwargs: Any) -> SearchIndex
Parameters
Returns
The index created
Return type
Exceptions
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
- allow_index_downtime
- bool
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.
- match_condition
- MatchConditions
The match condition to use upon the etag
Returns
The index created or updated
Return type
Exceptions
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
- match_condition
- MatchConditions
The match condition to use upon the etag
Returns
The created or updated Synonym Map
Return type
Exceptions
create_synonym_map
Create a new Synonym Map in an Azure Search service
create_synonym_map(synonym_map: SynonymMap, **kwargs: Any) -> SynonymMap
Parameters
Returns
The created Synonym Map
Return type
Exceptions
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
- match_condition
- MatchConditions
The match condition to use upon the etag
Exceptions
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
- match_condition
- MatchConditions
The match condition to use upon the etag
Returns
None
Return type
Exceptions
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
Returns
SearchIndex object
Return type
Exceptions
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
Returns
Statistics for the given index, including a document count and storage usage.
Return type
Exceptions
get_search_client
Return a client to perform operations on Search
get_search_client(index_name: str, **kwargs: Any) -> SearchClient
Parameters
Returns
SearchClient object
Return type
Exceptions
get_service_statistics
Get service level statistics for a search service.
get_service_statistics(**kwargs: Any) -> MutableMapping[str, Any]
Returns
Service statistics result.
Return type
Exceptions
get_synonym_map
Retrieve a named Synonym Map in an Azure Search service
get_synonym_map(name: str, **kwargs: Any) -> SynonymMap
Parameters
Returns
The retrieved Synonym Map
Return type
Exceptions
Examples
Get a Synonym Map
result = client.get_synonym_map("test-syn-map")
print("Retrived Synonym Map 'test-syn-map' with synonyms")
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
List of synonym maps
Return type
Exceptions
get_synonym_maps
List the Synonym Maps in an Azure Search service.
get_synonym_maps(*, select: List[str] | None = None, **kwargs) -> List[SynonymMap]
Parameters
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
List of synonym maps
Return type
Exceptions
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
List of index names
Return type
Exceptions
list_indexes
List the indexes in an Azure Search service.
list_indexes(*, select: List[str] | None = None, **kwargs: Any) -> ItemPaged[SearchIndex]
Parameters
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
List of indexes
Return type
Exceptions
Feedback
Submit and view feedback for