SearchIndexClient Class

A client to interact with Azure search service index.

Inheritance
azure.search.documents._headers_mixin.HeadersMixin
SearchIndexClient

Constructor

SearchIndexClient(endpoint, credential, **kwargs)

Parameters

endpoint
str
Required

The URL endpoint of an Azure search service

credential
AzureKeyCredential
Required

A credential to authorize search client requests

api_version
str
Required

The Search API version to use for requests.

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, analyze_request, **kwargs)

Parameters

index_name
str
Required

The name of the index for which to test an analyzer.

analyze_request
AnalyzeTextOptions
Required

The text and analyzer or analysis components to test.

Returns

AnalyzeResult

Return type

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 SearchIndexClient session.

close()

create_index

Creates a new search index.

create_index(index, **kwargs)

Parameters

index
SearchIndex
Required

The index object.

Returns

The index created

Return type

Examples

Creating a 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),
       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_index

Creates a new search index or updates an index if it already exists.

create_or_update_index(index, allow_index_downtime=None, **kwargs)

Parameters

index
SearchIndex
Required

The index object.

allow_index_downtime
bool
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.

match_condition

The match condition to use upon the etag

Returns

The index created or updated

Return type

Exceptions

Examples

Update an 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=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, **kwargs)

Parameters

synonym_map
SynonymMap
Required

The Synonym Map object

match_condition

The match condition to use upon the etag

Returns

The created or updated Synonym Map

Return type

create_synonym_map

Create a new Synonym Map in an Azure Search service

create_synonym_map(synonym_map, **kwargs)

Parameters

synonym_map
SynonymMap
Required

The Synonym Map object

Returns

The created Synonym Map

Return type

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, **kwargs)

Parameters

index
str or SearchIndex
Required

The index to retrieve.

match_condition

The match condition to use upon the etag

Examples

Delete an index.


   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, **kwargs)

Parameters

name
str or SynonymMap
Required

The Synonym Map to delete

match_condition

The match condition to use upon the etag

Returns

None

Return type

Examples

Delete a Synonym Map


   client.delete_synonym_map("test-syn-map")
   print("Synonym Map 'test-syn-map' deleted")

get_index

get_index(name, **kwargs)

Parameters

name
str
Required

The name of the index to retrieve.

Returns

SearchIndex object

Return type

Examples

Get an index.


   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, **kwargs)

Parameters

index_name
str
Required

The name of the index to retrieve.

Returns

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

Return type

get_search_client

Return a client to perform operations on Search

get_search_client(index_name, **kwargs)

Parameters

index_name
str
Required

The name of the Search Index

Return type

get_service_statistics

Get service level statistics for a search service.

get_service_statistics(**kwargs)

get_synonym_map

Retrieve a named Synonym Map in an Azure Search service

get_synonym_map(name, **kwargs)

Parameters

name
str
Required

The name of the Synonym Map to get

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)

Returns

List of synonym maps

Return type

get_synonym_maps

List the Synonym Maps in an Azure Search service.

get_synonym_maps(**kwargs)

Returns

List of synonym maps

Return type

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)

Returns

List of index names

Return type

list_indexes

List the indexes in an Azure Search service.

list_indexes(**kwargs)

Returns

List of indexes

Return type