azure.search.documents.indexes.aio package

class azure.search.documents.indexes.aio.SearchIndexClient(endpoint: str, credential: AzureKeyCredential | AsyncTokenCredential, **kwargs)[source]

A client to interact with Azure search service Indexes.

Parameters:
Keyword Arguments:
  • 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.

async 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:

AnalyzeRequest

Raises:

~azure.core.exceptions.HttpResponseError

Example:

Analyze text
from azure.core.credentials import AzureKeyCredential
from azure.search.documents.indexes.aio 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")

async with client:
    result = await client.analyze_text(index_name, analyze_request)
    print(result.as_dict())
async close() None[source]

Close the session. :return: None :rtype: None

async 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:

SearchIndex

Raises:

~azure.core.exceptions.HttpResponseError

Example:

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 = await client.create_index(index)
await client.close()
async create_or_update_index(index: SearchIndex, allow_index_downtime: bool | None = None, *, match_condition: MatchConditions = MatchConditions.Unconditionally, **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:

SearchIndex

Raises:

~azure.core.exceptions.ResourceNotFoundError or ~azure.core.exceptions.ResourceModifiedError or ~azure.core.exceptions.ResourceNotModifiedError or ~azure.core.exceptions.ResourceNotFoundError or ~azure.core.exceptions.ResourceExistsError

Example:

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 = await client.create_or_update_index(index=index)
await client.close()
async create_or_update_synonym_map(synonym_map: SynonymMap, *, match_condition: MatchConditions = MatchConditions.Unconditionally, **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:

SynonymMap

async 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:

SynonymMap

Example:

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 = await client.create_synonym_map(synonym_map)
print("Create new Synonym Map 'test-syn-map succeeded")
async delete_index(index: str | SearchIndex, *, match_condition: MatchConditions = MatchConditions.Unconditionally, **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:

Delete an index.
client = SearchIndexClient(service_endpoint, AzureKeyCredential(key))
name = "hotels"
await client.delete_index(name)
await client.close()
async delete_synonym_map(synonym_map: str | SynonymMap, *, match_condition: MatchConditions = MatchConditions.Unconditionally, **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:

synonym_map (str or SynonymMap) – The synonym map name or object to delete

Keyword Arguments:

match_condition (MatchConditions) – The match condition to use upon the etag

Example:

Delete a Synonym Map
await client.delete_synonym_map("test-syn-map")
print("Synonym Map 'test-syn-map' deleted")
async get_index(name: str, **kwargs: Any) SearchIndex[source]
Parameters:

name (str) – The name of the index to retrieve.

Returns:

SearchIndex object

Return type:

SearchIndex

Raises:

~azure.core.exceptions.HttpResponseError

Example:

Get an index.
client = SearchIndexClient(service_endpoint, AzureKeyCredential(key))
name = "hotels"
result = await client.get_index(name)
await client.close()
async get_index_statistics(index_name: str, **kwargs: Any) MutableMapping[str, Any][source]

Returns statistics for the given index, including a document count and storage usage.

Parameters:

index_name (str) – The name of the index to retrieve.

Returns:

Statistics for the given index, including a document count and storage usage.

Return type:

Dict

Raises:

~azure.core.exceptions.HttpResponseError

get_search_client(index_name: str, **kwargs: Any) SearchClient[source]

Return a client to perform operations on Search.

Parameters:

index_name (str) – The name of the Search Index

Returns:

SearchClient

Return type:

SearchClient

async get_service_statistics(**kwargs) MutableMapping[str, Any][source]

Get service level statistics for a search service.

Returns:

Service statistics result

Return type:

dict

async 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:

SynonymMap

Raises:

~azure.core.exceptions.ResourceNotFoundError

Example:

Get a Synonym Map
result = await 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))
async get_synonym_map_names(**kwargs: Any) List[str][source]

List the Synonym Map names in an Azure Search service.

Returns:

List of synonym map names

Return type:

List[str]

Raises:

~azure.core.exceptions.HttpResponseError

async get_synonym_maps(*, select: List[str] | None = None, **kwargs) 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:

List[SynonymMap]

Raises:

~azure.core.exceptions.HttpResponseError

Example:

List Synonym Maps
result = await 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(**kwargs: Any) AsyncItemPaged[str][source]

List the index names in an Azure Search service.

Returns:

List of index names

Return type:

AsyncItemPaged[str]

Raises:

~azure.core.exceptions.HttpResponseError

list_indexes(*, select: List[str] | None = None, **kwargs) AsyncItemPaged[SearchIndex][source]

List the indexes 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 indexes

Return type:

AsyncItemPaged[SearchIndex]

Raises:

~azure.core.exceptions.HttpResponseError

async send_request(request: HttpRequest, *, stream: bool = False, **kwargs) AsyncHttpResponse[source]

Runs a network request using the client’s existing pipeline.

Parameters:

request (HttpRequest) – The network request you want to make.

Keyword Arguments:

stream (bool) – Whether the response payload will be streamed. Defaults to False.

Returns:

The response of your network call. Does not do error handling on your response.

Return type:

AsyncHttpResponse

class azure.search.documents.indexes.aio.SearchIndexerClient(endpoint: str, credential: AzureKeyCredential | AsyncTokenCredential, **kwargs)[source]

A client to interact with Azure search service Indexers.

Parameters:
Keyword Arguments:
  • 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.

async close() None[source]

Close the session. :return: None :rtype: None

async create_data_source_connection(data_source_connection: SearchIndexerDataSourceConnection, **kwargs: Any) SearchIndexerDataSourceConnection[source]

Creates a new data source connection. :param data_source_connection: The definition of the data source connection to create. :type data_source_connection: ~azure.search.documents.indexes.models.SearchIndexerDataSourceConnection :return: The created SearchIndexerDataSourceConnection :rtype: ~azure.search.documents.indexes.models.SearchIndexerDataSourceConnection

Example:

Create a SearchIndexerDataSourceConnection
container = SearchIndexerDataContainer(name="searchcontainer")
data_source = SearchIndexerDataSourceConnection(
    name="async-sample-data-source-connection",
    type="azureblob",
    connection_string=connection_string,
    container=container,
)
result = await client.create_data_source_connection(data_source)
print("Create new Data Source Connection - async-sample-data-source-connection")
async 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:

SearchIndexer

Example:

Create a SearchIndexer
# create a datasource
container = SearchIndexerDataContainer(name="searchcontainer")
data_source_connection = SearchIndexerDataSourceConnection(
    name="async-indexer-datasource", type="azureblob", connection_string=connection_string, container=container
)
data_source = await indexers_client.create_data_source_connection(data_source_connection)

# create an indexer
indexer = SearchIndexer(
    name="async-sample-indexer",
    data_source_name="async-indexer-datasource",
    target_index_name="async-indexer-hotels",
)
result = await indexers_client.create_indexer(indexer)
print("Create new Indexer - async-sample-indexer")
async create_or_update_data_source_connection(data_source_connection: SearchIndexerDataSourceConnection, *, match_condition: MatchConditions = MatchConditions.Unconditionally, **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 :return: The created SearchIndexerDataSourceConnection :rtype: ~azure.search.documents.indexes.models.SearchIndexerDataSourceConnection

async create_or_update_indexer(indexer: SearchIndexer, *, match_condition: MatchConditions = MatchConditions.Unconditionally, **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:

match_condition (MatchConditions) – The match condition to use upon the etag

Returns:

The created SearchIndexer

Return type:

SearchIndexer

async create_or_update_skillset(skillset: SearchIndexerSkillset, *, match_condition: MatchConditions = MatchConditions.Unconditionally, **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

Returns:

The created or updated SearchIndexerSkillset

Return type:

SearchIndexerSkillset

async 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:

SearchIndexerSkillset

async delete_data_source_connection(data_source_connection: str | SearchIndexerDataSourceConnection, *, match_condition: MatchConditions = MatchConditions.Unconditionally, **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

Example:

Delete a SearchIndexerDataSourceConnection
await client.delete_data_source_connection("async-sample-data-source-connection")
print("Data Source Connection 'async-sample-data-source-connection' successfully deleted")
async delete_indexer(indexer: str | SearchIndexer, *, match_condition: MatchConditions = MatchConditions.Unconditionally, **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 name or the indexer object to delete.

Keyword Arguments:

match_condition (MatchConditions) – The match condition to use upon the etag

Example:

Delete a SearchIndexer
await indexers_client.delete_indexer("async-sample-indexer")
print("Indexer 'async-sample-indexer' successfully deleted")
async delete_skillset(skillset: str | SearchIndexerSkillset, *, match_condition: MatchConditions = MatchConditions.Unconditionally, **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

async get_data_source_connection(name: str, *, select: List[str] | None = None, **kwargs: Any) SearchIndexerDataSourceConnection[source]

Retrieves a data source connection definition.

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.

Parameters:

name (str) – The name of the data source connection to retrieve.

Returns:

The SearchIndexerDataSourceConnection that is fetched.

Return type:

~azure.search.documents.indexes.models.SearchIndexerDataSourceConnection

Retrieve a SearchIndexerDataSourceConnection
result = await client.get_data_source_connection("async-sample-data-source-connection")
print("Retrived Data Source Connection 'async-sample-data-source-connection'")
return result

async get_data_source_connection_names(**kwargs) 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]

async get_data_source_connections(**kwargs: Any) Sequence[SearchIndexerDataSourceConnection][source]

Lists all data source connections available for a search service.

Returns:

List of all the data source connections.

Return type:

list[SearchIndexerDataSourceConnection]

Example:

List all SearchIndexerDataSourceConnections
result = await client.get_data_source_connections()
names = [x.name for x in result]
print("Found {} Data Source Connections in the service: {}".format(len(result), ", ".join(names)))
async 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:

SearchIndexer

Example:

Retrieve a SearchIndexer
result = await indexers_client.get_indexer("async-sample-indexer")
print("Retrived Indexer 'async-sample-indexer'")
return result
async get_indexer_names(**kwargs) Sequence[str][source]

Lists all indexer names available for a search service.

Returns:

List of all the SearchIndexer names.

Return type:

list[str]

async 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:

SearchIndexerStatus

Example:

Get a SearchIndexer’s status
result = await indexers_client.get_indexer_status("async-sample-indexer")
print("Retrived Indexer status for 'async-sample-indexer'")
return result
async get_indexers(*, select: List[str] | None = None, **kwargs) 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:

List all the SearchIndexers
result = await indexers_client.get_indexers()
names = [x.name for x in result]
print("Found {} Indexers in the service: {}".format(len(result), ", ".join(names)))
async get_skillset(name: str, **kwargs) 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:

SearchIndexerSkillset

Raises:

~azure.core.exceptions.ResourceNotFoundError

async get_skillset_names(**kwargs) List[str][source]

List the SearchIndexerSkillset names in an Azure Search service.

Returns:

List of SearchIndexerSkillset names

Return type:

list[str]

Raises:

~azure.core.exceptions.HttpResponseError

async get_skillsets(*, select: List[str] | None = None, **kwargs) 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:

list[SearchIndexerSkillset]

Raises:

~azure.core.exceptions.HttpResponseError

async reset_indexer(name: str, **kwargs: Any) None[source]

Resets the change tracking state associated with an indexer.

Parameters:

name (str) – The name of the indexer to reset.

Example:

Reset a SearchIndexer’s change tracking state
await indexers_client.reset_indexer("async-sample-indexer")
print("Reset the Indexer 'async-sample-indexer'")
return
async run_indexer(name: str, **kwargs: Any) None[source]

Run an indexer.

Parameters:

name (str) – The name of the indexer to run.

Example:

Run a SearchIndexer
await indexers_client.run_indexer("async-sample-indexer")
print("Ran the Indexer 'async-sample-indexer'")
return