azure.search.documents.indexes package¶
-
class
azure.search.documents.indexes.
SearchIndexClient
(endpoint: str, credential: Union[AzureKeyCredential, TokenCredential], **kwargs: Any)[source]¶ A client to interact with Azure search service index.
- Parameters
endpoint (str) – The URL endpoint of an Azure search service
credential (AzureKeyCredential or TokenCredential) – A credential to authorize search client requests
- Keyword Arguments
-
analyze_text
(index_name: str, analyze_request: AnalyzeTextOptions, **kwargs: Any) → AnalyzeResult[source]¶ Shows how an analyzer breaks text into tokens.
- Parameters
index_name (str) – The name of the index for which to test an analyzer.
analyze_request (AnalyzeTextOptions) – The text and analyzer or analysis components to test.
- Returns
AnalyzeResult
- Return type
- Raises
~azure.core.exceptions.HttpResponseError
Example:
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
() → None[source]¶ Close the
SearchIndexClient
session.
-
create_alias
(alias: SearchAlias, **kwargs: Any) → SearchAlias[source]¶ Creates a new search alias.
- Parameters
alias (SearchAlias) – The alias object.
- Returns
The alias created
- Return type
- Raises
~azure.core.exceptions.HttpResponseError
Example:
-
create_index
(index: SearchIndex, **kwargs: Any) → SearchIndex[source]¶ Creates a new search index.
- Parameters
index (SearchIndex) – The index object.
- Returns
The index created
- Return type
- Raises
~azure.core.exceptions.HttpResponseError
Example:
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 = [] index = SearchIndex( name=name, fields=fields, scoring_profiles=scoring_profiles, cors_options=cors_options) result = client.create_index(index)
-
create_or_update_alias
(alias: str, **kwargs: azure.search.documents.indexes._generated.models._models_py3.SearchAlias) → azure.search.documents.indexes._generated.models._models_py3.SearchAlias[source]¶ Creates a new search alias or updates an alias if it already exists.
- Parameters
alias (SearchAlias) – The definition of the alias to create or update.
- Keyword Arguments
match_condition (MatchConditions) – The match condition to use upon the etag
- Returns
The index created or updated
- Return type
- Raises
ResourceNotFoundError
,ResourceModifiedError
,ResourceNotModifiedError
,ResourceNotFoundError
,ResourceExistsError
Example:
new_index_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=new_index_name, fields=fields, scoring_profiles=scoring_profiles, cors_options=cors_options) result_index = client.create_or_update_index(index=index) alias = SearchAlias(name = alias_name, indexes = [new_index_name]) result = client.create_or_update_alias(alias)
-
create_or_update_index
(index: SearchIndex, allow_index_downtime: bool = None, **kwargs: Any) → SearchIndex[source]¶ Creates a new search index or updates an index if it already exists.
- Parameters
index (SearchIndex) – The index object.
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.
- Keyword Arguments
match_condition (MatchConditions) – The match condition to use upon the etag
- Returns
The index created or updated
- Return type
- Raises
ResourceNotFoundError
,ResourceModifiedError
,ResourceNotModifiedError
,ResourceNotFoundError
,ResourceExistsError
Example:
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
(synonym_map: SynonymMap, **kwargs: Any) → SynonymMap[source]¶ Create a new Synonym Map in an Azure Search service, or update an existing one.
- Parameters
synonym_map (SynonymMap) – The Synonym Map object
- Keyword Arguments
match_condition (MatchConditions) – The match condition to use upon the etag
- Returns
The created or updated Synonym Map
- Return type
-
create_synonym_map
(synonym_map: SynonymMap, **kwargs: Any) → SynonymMap[source]¶ Create a new Synonym Map in an Azure Search service
- Parameters
synonym_map (SynonymMap) – The Synonym Map object
- Returns
The created Synonym Map
- Return type
Example:
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_alias
(alias: Union[str, SearchAlias], **kwargs: Any) → None[source]¶ Deletes a search alias and its associated mapping to an index. This operation is permanent, with no recovery option. The mapped index is untouched by this operation
- Parameters
alias (str or SearchAlias) – The alias name or object to delete.
- Keyword Arguments
match_condition (MatchConditions) – The match condition to use upon the etag
- Raises
~azure.core.exceptions.HttpResponseError
Example:
client.delete_alias(alias_name)
-
delete_index
(index: Union[str, SearchIndex], **kwargs: Any) → None[source]¶ Deletes a search index and all the documents it contains. The model must be provided instead of the name to use the access conditions.
- Parameters
index (str or SearchIndex) – The index name or object to delete.
- Keyword Arguments
match_condition (MatchConditions) – The match condition to use upon the etag
- Raises
~azure.core.exceptions.HttpResponseError
Example:
name = "hotels" client.delete_index(name)
-
delete_synonym_map
(synonym_map: Union[str, SynonymMap], **kwargs: Any) → None[source]¶ 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.
- Parameters
name (str or SynonymMap) – The synonym map name or object to delete
- Keyword Arguments
match_condition (MatchConditions) – The match condition to use upon the etag
- Returns
None
- Return type
Example:
client.delete_synonym_map("test-syn-map") print("Synonym Map 'test-syn-map' deleted")
-
get_alias
(name: str, **kwargs: Any) → SearchAlias[source]¶ - Parameters
name (str) – The name of the alias to retrieve.
- Returns
SearchAlias object
- Return type
- Raises
~azure.core.exceptions.HttpResponseError
-
get_index
(name: str, **kwargs: Any) → SearchIndex[source]¶ - Parameters
name (str) – The name of the index to retrieve.
- Returns
SearchIndex object
- Return type
- Raises
~azure.core.exceptions.HttpResponseError
Example:
name = "hotels" result = client.get_index(name)
-
get_index_statistics
(index_name: str, **kwargs: Any) → dict[source]¶ Returns statistics for the given index, including a document count and storage usage.
-
get_search_client
(index_name: str, **kwargs: dict) → azure.search.documents._search_client.SearchClient[source]¶ Return a client to perform operations on Search
- Parameters
index_name (str) – The name of the Search Index
- Return type
-
get_service_statistics
(**kwargs: Any) → dict[source]¶ Get service level statistics for a search service.
-
get_synonym_map
(name: str, **kwargs: Any) → SynonymMap[source]¶ Retrieve a named Synonym Map in an Azure Search service
- Parameters
name (str) – The name of the Synonym Map to get
- Returns
The retrieved Synonym Map
- Return type
- Raises
Example:
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
(**kwargs: Any) → List[str][source]¶ List the Synonym Map names in an Azure Search service.
-
get_synonym_maps
(**kwargs: Any) → List[SynonymMap][source]¶ List the Synonym Maps in an Azure Search service.
- Keyword Arguments
select (list[str]) – 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
- Raises
~azure.core.exceptions.HttpResponseError
Example:
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_alias_names
(**kwargs: Any) → ItemPaged[str][source]¶ List the alias names in an Azure Search service.
-
list_aliases
(**kwargs: Any) → ItemPaged[SearchAlias][source]¶ List the aliases in an Azure Search service.
-
list_index_names
(**kwargs: Any) → ItemPaged[str][source]¶ List the index names in an Azure Search service.
-
list_indexes
(**kwargs: Any) → ItemPaged[SearchIndex][source]¶ List the indexes in an Azure Search service.
-
class
azure.search.documents.indexes.
SearchIndexerClient
(endpoint: str, credential: Union[AzureKeyCredential, TokenCredential], **kwargs: Any)[source]¶ A client to interact with Azure search service Indexers.
- Parameters
endpoint (str) – The URL endpoint of an Azure search service
credential (AzureKeyCredential or TokenCredential) – A credential to authorize search client requests
- Keyword Arguments
-
close
() → None[source]¶ Close the
SearchIndexerClient
session.
-
create_data_source_connection
(data_source_connection: SearchIndexerDataSourceConnection, **kwargs: Any) → SearchIndexerDataSourceConnection[source]¶ Creates a new data source connection.
- Parameters
data_source_connection (SearchIndexerDataSourceConnection) – The definition of the data source connection to create.
- Returns
The created SearchIndexerDataSourceConnection
- Return type
Example:
container = SearchIndexerDataContainer(name='searchcontainer') data_source_connection = SearchIndexerDataSourceConnection( name="sample-data-source-connection", type="azureblob", connection_string=connection_string, container=container ) result = client.create_data_source_connection(data_source_connection) print(result) print("Create new Data Source Connection - sample-data-source-connection")
-
create_indexer
(indexer: SearchIndexer, **kwargs: Any) → SearchIndexer[source]¶ Creates a new SearchIndexer.
- Parameters
indexer (SearchIndexer) – The definition of the indexer to create.
- Returns
The created SearchIndexer
- Return type
Example:
-
create_or_update_data_source_connection
(data_source_connection: SearchIndexerDataSourceConnection, **kwargs: Any) → SearchIndexerDataSourceConnection[source]¶ Creates a new data source connection or updates a data source connection if it already exists. :param data_source_connection: The definition of the data source connection to create or update. :type data_source_connection: ~azure.search.documents.indexes.models.SearchIndexerDataSourceConnection :keyword match_condition: The match condition to use upon the etag :paramtype match_condition: ~azure.core.MatchConditions :keyword skip_indexer_reset_requirement_for_cache: Ignores cache reset requirements. :paramtype skip_indexer_reset_requirement_for_cache: bool :return: The created SearchIndexerDataSourceConnection :rtype: ~azure.search.documents.indexes.models.SearchIndexerDataSourceConnection
-
create_or_update_indexer
(indexer: SearchIndexer, **kwargs: Any) → SearchIndexer[source]¶ Creates a new indexer or updates a indexer if it already exists.
- Parameters
indexer (SearchIndexer) – The definition of the indexer to create or update.
- Keyword Arguments
- Returns
The created SearchIndexer
- Return type
-
create_or_update_skillset
(skillset: SearchIndexerSkillset, **kwargs: Any) → SearchIndexerSkillset[source]¶ Create a new SearchIndexerSkillset in an Azure Search service, or update an existing one.
- Parameters
skillset (SearchIndexerSkillset) – The SearchIndexerSkillset object to create or update
- Keyword Arguments
match_condition (MatchConditions) – The match condition to use upon the etag
skip_indexer_reset_requirement_for_cache (bool) – Ignores cache reset requirements.
disable_cache_reprocessing_change_detection (bool) – Disables cache reprocessing change detection.
- Returns
The created or updated SearchIndexerSkillset
- Return type
-
create_skillset
(skillset: SearchIndexerSkillset, **kwargs: Any) → SearchIndexerSkillset[source]¶ Create a new SearchIndexerSkillset in an Azure Search service
- Parameters
skillset (SearchIndexerSkillset) – The SearchIndexerSkillset object to create
- Returns
The created SearchIndexerSkillset
- Return type
Example:
-
delete_data_source_connection
(data_source_connection: Union[str, SearchIndexerDataSourceConnection], **kwargs: Any) → None[source]¶ Deletes a data source connection. To use access conditions, the SearchIndexerDataSourceConnection model must be provided instead of the name. It is enough to provide the name of the data source connection to delete unconditionally
- Parameters
data_source_connection (str or SearchIndexerDataSourceConnection) – The data source connection to delete.
- Keyword Arguments
match_condition (MatchConditions) – The match condition to use upon the etag
- Returns
None
- Return type
Example:
client.delete_data_source_connection("sample-data-source-connection") print("Data Source Connection 'sample-data-source-connection' successfully deleted")
-
delete_indexer
(indexer: Union[str, SearchIndexer], **kwargs: Any) → None[source]¶ Deletes an indexer. To use access conditions, the SearchIndexer model must be provided instead of the name. It is enough to provide the name of the indexer to delete unconditionally.
- Parameters
indexer (str or SearchIndexer) – The indexer to delete.
- Keyword Arguments
match_condition (MatchConditions) – The match condition to use upon the etag
- Returns
None
- Return type
Example:
-
delete_skillset
(skillset: Union[str, SearchIndexerSkillset], **kwargs: Any) → None[source]¶ Delete a named SearchIndexerSkillset in an Azure Search service. To use access conditions, the SearchIndexerSkillset model must be provided instead of the name. It is enough to provide the name of the skillset to delete unconditionally
- Parameters
skillset (str or SearchIndexerSkillset) – The SearchIndexerSkillset to delete
- Keyword Arguments
match_condition (MatchConditions) – The match condition to use upon the etag
Example:
-
get_data_source_connection
(name: str, **kwargs: Any) → SearchIndexerDataSourceConnection[source]¶ Retrieves a data source connection definition.
- Parameters
name (str) – The name of the data source connection to retrieve.
- Returns
The SearchIndexerDataSourceConnection that is fetched.
- Return type
Example:
result = client.get_data_source_connection("sample-data-source-connection") print("Retrived Data Source Connection 'sample-data-source-connection'")
-
get_data_source_connection_names
(**kwargs: Any) → Sequence[str][source]¶ Lists all data source connection names available for a search service.
- Returns
List of all the data source connection names.
- Return type
list[str]
-
get_data_source_connections
(**kwargs: Any) → Sequence[SearchIndexerDataSourceConnection][source]¶ Lists all data source connections available for a search service.
- Keyword Arguments
select (list[str]) – 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 all the data source connections.
- Return type
list[~azure.search.documents.indexes.models.SearchIndexerDataSourceConnection]
Example:
result = client.get_data_source_connections() names = [ds.name for ds in result] print("Found {} Data Source Connections in the service: {}".format(len(result), ", ".join(names)))
-
get_indexer
(name: str, **kwargs: Any) → SearchIndexer[source]¶ Retrieves a indexer definition.
- Parameters
name (str) – The name of the indexer to retrieve.
- Returns
The SearchIndexer that is fetched.
- Return type
Example:
-
get_indexer_names
(**kwargs: Any) → Sequence[str][source]¶ Lists all indexer names available for a search service.
- Returns
List of all the SearchIndexers.
- Return type
list[str]
Example:
-
get_indexer_status
(name: str, **kwargs: Any) → SearchIndexerStatus[source]¶ Get the status of the indexer.
- Parameters
name (str) – The name of the indexer to fetch the status.
- Returns
SearchIndexerStatus
- Return type
Example:
-
get_indexers
(**kwargs: Any) → Sequence[SearchIndexer][source]¶ Lists all indexers available for a search service.
- Keyword Arguments
select (list[str]) – 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 all the SearchIndexers.
- Return type
list[~azure.search.documents.indexes.models.SearchIndexer]
Example:
-
get_skillset
(name: str, **kwargs: Any) → SearchIndexerSkillset[source]¶ Retrieve a named SearchIndexerSkillset in an Azure Search service
- Parameters
name (str) – The name of the SearchIndexerSkillset to get
- Returns
The retrieved SearchIndexerSkillset
- Return type
- Raises
Example:
-
get_skillset_names
(**kwargs: Any) → List[str][source]¶ List the SearchIndexerSkillset names in an Azure Search service.
-
get_skillsets
(**kwargs: Any) → List[SearchIndexerSkillset][source]¶ List the SearchIndexerSkillsets in an Azure Search service.
- Keyword Arguments
select (list[str]) – 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 SearchIndexerSkillsets
- Return type
- Raises
~azure.core.exceptions.HttpResponseError
Example:
-
reset_documents
(indexer: Union[str, SearchIndexer], keys_or_ids: DocumentKeysOrIds, **kwargs: Any) → None[source]¶ Resets specific documents in the datasource to be selectively re-ingested by the indexer.
- Parameters
indexer (str or SearchIndexer) – The indexer to reset documents for.
keys_or_ids (DocumentKeysOrIds) –
- Returns
None, or the result of cls(response)
- Keyword Arguments
overwrite (bool) – If false, keys or ids will be appended to existing ones. If true, only the keys or ids in this payload will be queued to be re-ingested. The default is false.
- Return type
- Raises
~azure.core.exceptions.HttpResponseError
-
reset_indexer
(name: str, **kwargs: Any) → None[source]¶ Resets the change tracking state associated with an indexer.
Example:
-
reset_skills
(skillset: Union[str, SearchIndexerSkillset], skill_names: List[str], **kwargs: Any) → None[source]¶ Reset an existing skillset in a search service.
- Parameters
skillset (str or SearchIndexerSkillset) – The SearchIndexerSkillset to reset
- Returns
None, or the result of cls(response)
- Return type
- Raises
~azure.core.exceptions.HttpResponseError