SearchIndexAsyncClient Class

  • java.lang.Object
    • com.azure.search.documents.indexes.SearchIndexAsyncClient

public final class SearchIndexAsyncClient

This class provides a client that contains the operations for creating, getting, listing, updating, or deleting indexes or synonym map and analyzing text in an Azure AI Search service.

Overview

An index is stored on your search service and populated with JSON documents that are indexed and tokenized for information retrieval. The fields collection of an index defines the structure of the search document. Fields have a name, data types, and attributes that determine how it's used. For example, searchable fields are used in full text search, and thus tokenized during indexing. An index also defines other constructs, such as scoring profiles for relevance tuning, suggesters, semantic configurations, and custom analyzers.

A synonym map is service-level object that contains user-defined synonyms. This object is maintained independently of search indexes. Once uploaded, you can point any searchable field to the synonym map (one per field).

This client provides an asynchronous API for accessing indexes. This client allows you to create, delete, update, and configure search indexes. The client also allows you to declare custom synonym maps to expand or rewrite queries.

Getting Started

Authenticating and building instances of this client are handled by SearchIndexClientBuilder. This sample shows you how to create an instance of the client:

SearchIndexAsyncClient searchIndexAsyncClient = new SearchIndexClientBuilder()
     .credential(new AzureKeyCredential("{key}"))
     .endpoint("{endpoint}")
     .buildAsyncClient();

For more information on authentication and building, see the documentation for SearchIndexClientBuilder.


Examples

The following examples all use a simple Hotel data set that you can import into your own index from the Azure portal. These are just a few of the basics - please check out our Samples for much more.

Create an Index

The following sample creates an index.

SearchIndex searchIndex = new SearchIndex("indexName", Arrays.asList(
     new SearchField("hotelId", SearchFieldDataType.STRING)
         .setKey(true)
         .setFilterable(true)
         .setSortable(true),
     new SearchField("hotelName", SearchFieldDataType.STRING)
         .setSearchable(true)
         .setFilterable(true)
         .setSortable(true),
     new SearchField("description", SearchFieldDataType.STRING)
         .setSearchable(true)
         .setAnalyzerName(LexicalAnalyzerName.EN_LUCENE),
     new SearchField("descriptionFr", SearchFieldDataType.STRING)
         .setSearchable(true)
         .setAnalyzerName(LexicalAnalyzerName.FR_LUCENE),
     new SearchField("tags", SearchFieldDataType.collection(SearchFieldDataType.STRING))
         .setSearchable(true)
         .setFilterable(true)
         .setFacetable(true),
     new SearchField("address", SearchFieldDataType.COMPLEX)
         .setFields(
             new SearchField("streetAddress", SearchFieldDataType.STRING)
                 .setSearchable(true),
             new SearchField("city", SearchFieldDataType.STRING)
                 .setFilterable(true)
                 .setSortable(true)
                 .setFacetable(true),
             new SearchField("stateProvince", SearchFieldDataType.STRING)
                 .setSearchable(true)
                 .setFilterable(true)
                 .setSortable(true)
                 .setFacetable(true),
             new SearchField("country", SearchFieldDataType.STRING)
                 .setSearchable(true)
                 .setSynonymMapNames("synonymMapName")
                 .setFilterable(true)
                 .setSortable(true)
                 .setFacetable(true),
             new SearchField("postalCode", SearchFieldDataType.STRING)
                 .setSearchable(true)
                 .setFilterable(true)
                 .setSortable(true)
                 .setFacetable(true))
 ));

 searchIndexAsyncClient.createIndex(searchIndex).block();

For a synchronous sample see createIndex(SearchIndex index).

List indexes

The following sample lists all indexes.

searchIndexAsyncClient.listIndexes().subscribe(index -> System.out.println("The index name is " + index.getName()));

For a synchronous sample see listIndexes().

Retrieve an Index

The following sample retrieves an index.

SearchIndex searchIndex = searchIndexAsyncClient.getIndex("indexName").block();
 if (searchIndex != null) {
     System.out.println("The index name is " + searchIndex.getName());
 }

For a synchronous sample see getIndex(String name).

Update an Index

The following sample updates an index.

SearchIndex searchIndex = searchIndexAsyncClient.getIndex("indexName").block();
 if (searchIndex != null) {
     searchIndex.setFields(new SearchField("newField", SearchFieldDataType.STRING));
     searchIndexAsyncClient.createOrUpdateIndex(searchIndex);
 }

For a synchronous sample see createOrUpdateIndex(SearchIndex index).

Delete an Index

The following sample deletes an index.

String indexName = "indexName";
 searchIndexAsyncClient.deleteIndex(indexName).block();

For a synchronous sample see deleteIndex(String name).

Create a Synonym Map

The following sample creates a synonym map.

SynonymMap synonymMap = new SynonymMap("synonymMapName", "hotel, motel, \"motor inn\"");
 searchIndexAsyncClient.createSynonymMap(synonymMap).block();

For a synchronous sample see createSynonymMap(SynonymMap synonymMap).

List Synonym Maps

The following sample lists all synonym maps.

searchIndexAsyncClient.listSynonymMaps().subscribe(synonymMap ->
     System.out.println("The synonymMap name is " + synonymMap.getName())
 );

For a synchronous sample see listSynonymMaps().

Retrieve a Synonym Map

The following sample retrieves a synonym map.

SynonymMap synonymMap = searchIndexAsyncClient.getSynonymMap("synonymMapName").block();
 if (synonymMap != null) {
     System.out.println("The synonymMap name is " + synonymMap.getName());
 }

For a synchronous sample see getSynonymMap(String name).

Update a Synonym Map

The following sample updates a synonym map.

SynonymMap synonymMap = searchIndexAsyncClient.getSynonymMap("synonymMapName").block();
 if (synonymMap != null) {
     synonymMap.setSynonyms("hotel, motel, inn");
     searchIndexAsyncClient.createOrUpdateSynonymMap(synonymMap).block();
 }

For a synchronous sample see createOrUpdateSynonymMap(SynonymMap synonymMap).

Delete a Synonym Map

The following sample deletes a synonym map.

String synonymMapName = "synonymMapName";
 searchIndexAsyncClient.deleteSynonymMap(synonymMapName).block();

For a synchronous sample see deleteSynonymMap(String name).

Method Summary

Modifier and Type Method and Description
PagedFlux<AnalyzedTokenInfo> analyzeText(String indexName, AnalyzeTextOptions analyzeTextOptions)

Shows how an analyzer breaks text into tokens.

static List<SearchField> buildSearchFields(Class<?> model, FieldBuilderOptions options)

Convenience method to convert a Class's Fields and Methods into SearchField to help aid the creation of a SearchField which represents the Class.

Mono<SearchAlias> createAlias(SearchAlias alias)

Creates a new Azure AI Search alias.

Mono<Response<SearchAlias>> createAliasWithResponse(SearchAlias alias)

Creates a new Azure AI Search alias.

Mono<SearchIndex> createIndex(SearchIndex index)

Creates a new Azure AI Search index.

Mono<Response<SearchIndex>> createIndexWithResponse(SearchIndex index)

Creates a new Azure AI Search index.

Mono<KnowledgeBase> createKnowledgeBase(KnowledgeBase knowledgeBase)

Creates a new agent.

Mono<Response<KnowledgeBase>> createKnowledgeBaseWithResponse(KnowledgeBase knowledgeBase)

Creates a new agent.

Mono<KnowledgeSource> createKnowledgeSource(KnowledgeSource knowledgeSource)

Creates a new knowledge source.

Mono<Response<KnowledgeSource>> createKnowledgeSourceWithResponse(KnowledgeSource knowledgeSource)

Creates a new knowledge source.

Mono<SearchAlias> createOrUpdateAlias(SearchAlias alias)

Creates or updates an Azure AI Search alias.

Mono<Response<SearchAlias>> createOrUpdateAliasWithResponse(SearchAlias alias, boolean onlyIfUnchanged)

Creates or updates an Azure AI Search alias.

Mono<SearchIndex> createOrUpdateIndex(SearchIndex index)

Creates a new Azure AI Search index or updates an index if it already exists.

Mono<Response<SearchIndex>> createOrUpdateIndexWithResponse(SearchIndex index, boolean allowIndexDowntime, boolean onlyIfUnchanged)

Creates a new Azure AI Search index or updates an index if it already exists.

Mono<KnowledgeBase> createOrUpdateKnowledgeBase(KnowledgeBase knowledgeBase)

Creates a new agent or updates an agent if it already exists.

Mono<Response<KnowledgeBase>> createOrUpdateKnowledgeBaseWithResponse(KnowledgeBase knowledgeBase, MatchConditions matchConditions)

Creates a new agent or updates an agent if it already exists.

Mono<KnowledgeSource> createOrUpdateKnowledgeSource(KnowledgeSource knowledgeSource)

Creates or updates a knowledge source.

Mono<Response<KnowledgeSource>> createOrUpdateKnowledgeSourceWithResponse(KnowledgeSource knowledgeSource, MatchConditions matchConditions)

Creates or updates a knowledge source.

Mono<SynonymMap> createOrUpdateSynonymMap(SynonymMap synonymMap)

Creates a new Azure AI Search synonym map or updates a synonym map if it already exists.

Mono<Response<SynonymMap>> createOrUpdateSynonymMapWithResponse(SynonymMap synonymMap, boolean onlyIfUnchanged)

Creates a new Azure AI Search synonym map or updates a synonym map if it already exists.

Mono<SynonymMap> createSynonymMap(SynonymMap synonymMap)

Creates a new Azure AI Search synonym map.

Mono<Response<SynonymMap>> createSynonymMapWithResponse(SynonymMap synonymMap)

Creates a new Azure AI Search synonym map.

Mono<Void> deleteAlias(String aliasName)

Deletes the Azure AI Search alias.

Mono<Response<Void>> deleteAliasWithResponse(SearchAlias alias, boolean onlyIfUnchanged)

Deletes the Azure AI Search alias.

Mono<Void> deleteIndex(String indexName)

Deletes an Azure AI Search index and all the documents it contains.

Mono<Response<Void>> deleteIndexWithResponse(SearchIndex index, boolean onlyIfUnchanged)

Deletes an Azure AI Search index and all the documents it contains.

Mono<Void> deleteKnowledgeBase(String knowledgeBaseName)

Deletes an existing agent.

Mono<Response<Void>> deleteKnowledgeBaseWithResponse(String knowledgeBaseName, MatchConditions matchConditions)

Deletes an existing agent.

Mono<Void> deleteKnowledgeSource(String sourceName)

Deletes an existing knowledge source.

Mono<Response<Void>> deleteKnowledgeSourceWithResponse(String sourceName, MatchConditions matchConditions)

Deletes an existing knowledge source.

Mono<Void> deleteSynonymMap(String synonymMapName)

Deletes an Azure AI Search synonym map.

Mono<Response<Void>> deleteSynonymMapWithResponse(SynonymMap synonymMap, boolean onlyIfUnchanged)

Deletes an Azure AI Search synonym map.

Mono<SearchAlias> getAlias(String aliasName)

Gets the Azure AI Search alias.

Mono<Response<SearchAlias>> getAliasWithResponse(String aliasName)

Gets the Azure AI Search alias.

String getEndpoint()

Gets the endpoint for the Azure AI Search service.

Mono<SearchIndex> getIndex(String indexName)

Retrieves an index definition from the Azure AI Search.

Mono<SearchIndexStatistics> getIndexStatistics(String indexName)

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

Mono<Response<SearchIndexStatistics>> getIndexStatisticsWithResponse(String indexName)

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

PagedFlux<IndexStatisticsSummary> getIndexStatsSummary()

Retrieves a summary of statistics for all indexes in the search service.

Mono<Response<SearchIndex>> getIndexWithResponse(String indexName)

Retrieves an index definition from the Azure AI Search.

Mono<KnowledgeBase> getKnowledgeBase(String knowledgeBaseName)

Retrieves an agent definition.

Mono<Response<KnowledgeBase>> getKnowledgeBaseWithResponse(String knowledgeBaseName)

Retrieves an agent definition.

Mono<KnowledgeSource> getKnowledgeSource(String sourceName)

Retrieves a knowledge source.

Mono<Response<KnowledgeSource>> getKnowledgeSourceWithResponse(String sourceName)

Retrieves a knowledge source.

SearchAsyncClient getSearchAsyncClient(String indexName)

Initializes a new SearchAsyncClient using the given Index name and the same configuration as the SearchServiceAsyncClient.

Mono<SearchServiceStatistics> getServiceStatistics()

Returns service level statistics for a search service, including service counters and limits.

Mono<Response<SearchServiceStatistics>> getServiceStatisticsWithResponse()

Returns service level statistics for a search service, including service counters and limits.

Mono<SynonymMap> getSynonymMap(String synonymMapName)

Retrieves a synonym map definition.

Mono<Response<SynonymMap>> getSynonymMapWithResponse(String synonymMapName)

Retrieves a synonym map definition.

PagedFlux<SearchAlias> listAliases()

Lists all aliases in the Azure AI Search service.

PagedFlux<SearchIndex> listIndexes()

Lists all indexes available for an Azure AI Search service.

PagedFlux<String> listIndexNames()

Lists all indexes names for an Azure AI Search service.

PagedFlux<KnowledgeBase> listKnowledgeBases()

Lists all knowledgebases available for a search service.

PagedFlux<KnowledgeSource> listKnowledgeSources()

Lists all knowledge sources available for a search service.

PagedFlux<String> listSynonymMapNames()

Lists all synonym map names for an Azure AI Search service.

PagedFlux<SynonymMap> listSynonymMaps()

Lists all synonym maps available for an Azure AI Search service.

Methods inherited from java.lang.Object

Method Details

analyzeText

public PagedFlux<AnalyzedTokenInfo> analyzeText(String indexName, AnalyzeTextOptions analyzeTextOptions)

Shows how an analyzer breaks text into tokens.

Code Sample

Analyzer text with LexicalTokenizerName "Classic" in search index "searchIndex".

SEARCH_INDEX_ASYNC_CLIENT.analyzeText("searchIndex",
     new AnalyzeTextOptions("The quick brown fox", LexicalTokenizerName.CLASSIC))
     .subscribe(tokenInfo ->
         System.out.printf("The token emitted by the analyzer is %s.%n", tokenInfo.getToken()));

Parameters:

indexName - the name of the index for which to test an analyzer
analyzeTextOptions - the text and analyzer or analysis components to test

Returns:

a response containing analyze result.

buildSearchFields

public static List<SearchField> buildSearchFields(Class<?> model, FieldBuilderOptions options)

Convenience method to convert a Class's Fields and Methods into SearchField to help aid the creation of a SearchField which represents the Class.

Parameters:

model - The model Class that will have SearchField generated from its structure.
options - Configuration used to determine generation of the SearchField.

Returns:

A list SearchField which represent the model Class.

createAlias

public Mono<SearchAlias> createAlias(SearchAlias alias)

Creates a new Azure AI Search alias.

Code Sample

Create the search alias named "my-alias".

SEARCH_INDEX_ASYNC_CLIENT.createAlias(new SearchAlias("my-alias", Collections.singletonList("index-to-alias")))
     .subscribe(searchAlias -> System.out.printf("Created alias '%s' that aliases index '%s'.",
         searchAlias.getName(), searchAlias.getIndexes().get(0)));

Parameters:

alias - definition of the alias to create.

Returns:

the created alias.

createAliasWithResponse

public Mono<Response<SearchAlias>> createAliasWithResponse(SearchAlias alias)

Creates a new Azure AI Search alias.

Code Sample

Create the search alias named "my-alias".

SEARCH_INDEX_ASYNC_CLIENT.createAliasWithResponse(new SearchAlias("my-alias",
         Collections.singletonList("index-to-alias")))
     .subscribe(response ->
         System.out.printf("Response status code %d. Created alias '%s' that aliases index '%s'.",
             response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0)));

Parameters:

alias - definition of the alias to create.

Returns:

the created alias.

createIndex

public Mono<SearchIndex> createIndex(SearchIndex index)

Creates a new Azure AI Search index.

Code Sample

Create search index named "searchIndex".

List<SearchField> searchFields = Arrays.asList(
     new SearchField("hotelId", SearchFieldDataType.STRING).setKey(true),
     new SearchField("hotelName", SearchFieldDataType.STRING).setSearchable(true)
 );
 SearchIndex searchIndex = new SearchIndex("searchIndex", searchFields);
 SEARCH_INDEX_ASYNC_CLIENT.createIndex(searchIndex)
     .subscribe(indexFromService ->
         System.out.printf("The index name is %s. The ETag of index is %s.%n", indexFromService.getName(),
         indexFromService.getETag()));

Parameters:

index - definition of the index to create.

Returns:

the created Index.

createIndexWithResponse

public Mono<Response<SearchIndex>> createIndexWithResponse(SearchIndex index)

Creates a new Azure AI Search index.

Code Sample

Create search index named "searchIndex".

List<SearchField> searchFields = Arrays.asList(
     new SearchField("hotelId", SearchFieldDataType.STRING).setKey(true),
     new SearchField("hotelName", SearchFieldDataType.STRING).setSearchable(true)
 );
 SearchIndex searchIndex = new SearchIndex("searchIndex", searchFields);

 SEARCH_INDEX_ASYNC_CLIENT.createIndexWithResponse(searchIndex)
     .subscribe(indexFromServiceResponse ->
         System.out.printf("The status code of the response is %s. The index name is %s.%n",
         indexFromServiceResponse.getStatusCode(), indexFromServiceResponse.getValue().getName()));

Parameters:

index - definition of the index to create

Returns:

a response containing the created Index.

createKnowledgeBase

public Mono<KnowledgeBase> createKnowledgeBase(KnowledgeBase knowledgeBase)

Creates a new agent.

Parameters:

knowledgeBase - The definition of the agent to create.

Returns:

the response body on successful completion of Mono.

createKnowledgeBaseWithResponse

public Mono<Response<KnowledgeBase>> createKnowledgeBaseWithResponse(KnowledgeBase knowledgeBase)

Creates a new agent.

Parameters:

knowledgeBase - The definition of the agent to create.

Returns:

the response body along with Response<T> on successful completion of Mono.

createKnowledgeSource

public Mono<KnowledgeSource> createKnowledgeSource(KnowledgeSource knowledgeSource)

Creates a new knowledge source.

Parameters:

knowledgeSource - The definition of the knowledge source to create.

Returns:

A Mono that will produce the created knowledge source.

createKnowledgeSourceWithResponse

public Mono<Response<KnowledgeSource>> createKnowledgeSourceWithResponse(KnowledgeSource knowledgeSource)

Creates a new knowledge source.

Parameters:

knowledgeSource - The definition of the knowledge source to create.

Returns:

A Mono that will produce a Response<T> containing the created knowledge source.

createOrUpdateAlias

public Mono<SearchAlias> createOrUpdateAlias(SearchAlias alias)

Creates or updates an Azure AI Search alias.

Code Sample

Create then update the search alias named "my-alias".

SEARCH_INDEX_ASYNC_CLIENT.createOrUpdateAlias(
         new SearchAlias("my-alias", Collections.singletonList("index-to-alias")))
     .flatMap(searchAlias -> {
         System.out.printf("Created alias '%s' that aliases index '%s'.", searchAlias.getName(),
             searchAlias.getIndexes().get(0));

         return SEARCH_INDEX_ASYNC_CLIENT.createOrUpdateAlias(new SearchAlias(searchAlias.getName(),
             Collections.singletonList("new-index-to-alias")));
     }).subscribe(searchAlias -> System.out.printf("Updated alias '%s' to aliases index '%s'.",
         searchAlias.getName(), searchAlias.getIndexes().get(0)));

Parameters:

alias - definition of the alias to create or update.

Returns:

the created or updated alias.

createOrUpdateAliasWithResponse

public Mono<Response<SearchAlias>> createOrUpdateAliasWithResponse(SearchAlias alias, boolean onlyIfUnchanged)

Creates or updates an Azure AI Search alias.

Code Sample

Create then update the search alias named "my-alias".

SEARCH_INDEX_ASYNC_CLIENT.createOrUpdateAliasWithResponse(
         new SearchAlias("my-alias", Collections.singletonList("index-to-alias")), false)
     .flatMap(response -> {
         System.out.printf("Response status code %d. Created alias '%s' that aliases index '%s'.",
             response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0));

         return SEARCH_INDEX_ASYNC_CLIENT.createOrUpdateAliasWithResponse(
             new SearchAlias(response.getValue().getName(), Collections.singletonList("new-index-to-alias"))
                 .setETag(response.getValue().getETag()), true);
     }).subscribe(response ->
         System.out.printf("Response status code %d. Updated alias '%s' that aliases index '%s'.",
             response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0)));

Parameters:

alias - definition of the alias to create or update.
onlyIfUnchanged - only update the alias if the eTag matches the alias on the service

Returns:

the created or updated alias.

createOrUpdateIndex

public Mono<SearchIndex> createOrUpdateIndex(SearchIndex index)

Creates a new Azure AI Search index or updates an index if it already exists.

Code Sample

Create or update search index named "searchIndex".

SEARCH_INDEX_ASYNC_CLIENT.getIndex("searchIndex")
     .doOnNext(indexFromService -> indexFromService.setSuggesters(Collections.singletonList(
         new SearchSuggester("sg", Collections.singletonList("hotelName")))))
     .flatMap(SEARCH_INDEX_ASYNC_CLIENT::createOrUpdateIndex)
     .subscribe(updatedIndex ->
         System.out.printf("The index name is %s. The suggester name of index is %s.%n",
             updatedIndex.getName(), updatedIndex.getSuggesters().get(0).getName()));

Parameters:

index - the definition of the SearchIndex to create or update.

Returns:

the index that was created or updated.

createOrUpdateIndexWithResponse

public Mono<Response<SearchIndex>> createOrUpdateIndexWithResponse(SearchIndex index, boolean allowIndexDowntime, boolean onlyIfUnchanged)

Creates a new Azure AI Search index or updates an index if it already exists.

Code Sample

Create or update search index named "searchIndex".

SearchIndex indexFromService = SEARCH_INDEX_CLIENT.getIndex("searchIndex");
 indexFromService.setSuggesters(Collections.singletonList(new SearchSuggester("sg",
     Collections.singletonList("hotelName"))));
 Response<SearchIndex> updatedIndexResponse = SEARCH_INDEX_CLIENT.createOrUpdateIndexWithResponse(indexFromService, true,
     false, new Context(KEY_1, VALUE_1));
 System.out.printf("The status code of the normal response is %s.%n"
         + "The index name is %s. The ETag of index is %s.%n", updatedIndexResponse.getStatusCode(),
     updatedIndexResponse.getValue().getName(), updatedIndexResponse.getValue().getETag());

Parameters:

index - the definition of the index to create or update
allowIndexDowntime - 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
onlyIfUnchanged - true to update if the index is the same as the current service value. false to always update existing value.

Returns:

a response containing the index that was created or updated

createOrUpdateKnowledgeBase

public Mono<KnowledgeBase> createOrUpdateKnowledgeBase(KnowledgeBase knowledgeBase)

Creates a new agent or updates an agent if it already exists.

Parameters:

knowledgeBase - The definition of the agent to create or update.

Returns:

the response body on successful completion of Mono.

createOrUpdateKnowledgeBaseWithResponse

public Mono<Response<KnowledgeBase>> createOrUpdateKnowledgeBaseWithResponse(KnowledgeBase knowledgeBase, MatchConditions matchConditions)

Creates a new agent or updates an agent if it already exists.

Parameters:

knowledgeBase - The definition of the agent to create or update.
matchConditions - Defining If-Match and If-None-Match conditions. If null is passed, no conditions will be applied.

Returns:

the response body along with Response<T> on successful completion of Mono.

createOrUpdateKnowledgeSource

public Mono<KnowledgeSource> createOrUpdateKnowledgeSource(KnowledgeSource knowledgeSource)

Creates or updates a knowledge source.

Parameters:

knowledgeSource - The definition of the knowledge source to create or update.

Returns:

A Mono that will produce the created or updated knowledge source.

createOrUpdateKnowledgeSourceWithResponse

public Mono<Response<KnowledgeSource>> createOrUpdateKnowledgeSourceWithResponse(KnowledgeSource knowledgeSource, MatchConditions matchConditions)

Creates or updates a knowledge source.

Parameters:

knowledgeSource - The definition of the knowledge source to create or update.
matchConditions - Defining If-Match and If-None-Match conditions. If null is passed, no conditions will be applied.

Returns:

A Mono that produces a Response<T> containing the created or updated knowledge source.

createOrUpdateSynonymMap

public Mono<SynonymMap> createOrUpdateSynonymMap(SynonymMap synonymMap)

Creates a new Azure AI Search synonym map or updates a synonym map if it already exists.

Code Sample

Create or update synonym map named "synonymMap".

SEARCH_INDEX_ASYNC_CLIENT.getSynonymMap("searchIndex")
     .doOnNext(synonymMap -> synonymMap
         .setSynonyms("United States, United States of America, USA, America\nWashington, Wash. => WA"))
     .flatMap(SEARCH_INDEX_ASYNC_CLIENT::createOrUpdateSynonymMap)
     .subscribe(updatedSynonymMap ->
         System.out.printf("The synonym map name is %s. The synonyms are %s.%n", updatedSynonymMap.getName(),
         updatedSynonymMap.getSynonyms()));

Parameters:

synonymMap - the definition of the SynonymMap to create or update

Returns:

the synonym map that was created or updated.

createOrUpdateSynonymMapWithResponse

public Mono<Response<SynonymMap>> createOrUpdateSynonymMapWithResponse(SynonymMap synonymMap, boolean onlyIfUnchanged)

Creates a new Azure AI Search synonym map or updates a synonym map if it already exists.

Code Sample

Create or update synonym map named "synonymMap".

SEARCH_INDEX_ASYNC_CLIENT.getSynonymMap("searchIndex")
     .flatMap(synonymMap -> {
         synonymMap.setSynonyms(
             "United States, United States of America, USA, America\nWashington, Wash. => WA");
         return SEARCH_INDEX_ASYNC_CLIENT.createOrUpdateSynonymMapWithResponse(synonymMap, true);
     })
     .subscribe(updatedSynonymMap ->
         System.out.printf("The status code of the normal response is %s.%n"
             + "The synonym map name is %s. The synonyms are %s.%n", updatedSynonymMap.getStatusCode(),
         updatedSynonymMap.getValue().getName(), updatedSynonymMap.getValue().getSynonyms()));

Parameters:

synonymMap - the definition of the SynonymMap to create or update
onlyIfUnchanged - true to update if the synonymMap is the same as the current service value. false to always update existing value.

Returns:

a response containing the synonym map that was created or updated.

createSynonymMap

public Mono<SynonymMap> createSynonymMap(SynonymMap synonymMap)

Creates a new Azure AI Search synonym map.

Code Sample

Create synonym map named "synonymMap".

SynonymMap synonymMap = new SynonymMap("synonymMap",
     "United States, United States of America, USA\nWashington, Wash. => WA");
 SEARCH_INDEX_ASYNC_CLIENT.createSynonymMap(synonymMap)
     .subscribe(synonymMapFromService ->
         System.out.printf("The synonym map name is %s. The ETag of synonym map is %s.%n",
         synonymMapFromService.getName(), synonymMapFromService.getETag()));

Parameters:

synonymMap - the definition of the synonym map to create

Returns:

the created SynonymMap.

createSynonymMapWithResponse

public Mono<Response<SynonymMap>> createSynonymMapWithResponse(SynonymMap synonymMap)

Creates a new Azure AI Search synonym map.

Code Sample

Create synonym map named "synonymMap".

SynonymMap synonymMap = new SynonymMap("synonymMap",
     "United States, United States of America, USA\nWashington, Wash. => WA");
 SEARCH_INDEX_ASYNC_CLIENT.createSynonymMapWithResponse(synonymMap)
     .subscribe(synonymMapFromService ->
         System.out.printf("The status code of the response is %d.%n"
             + "The synonym map name is %s. The ETag of synonym map is %s.%n",
             synonymMapFromService.getStatusCode(),
         synonymMapFromService.getValue().getName(), synonymMapFromService.getValue().getETag()));

Parameters:

synonymMap - the definition of the SynonymMap to create

Returns:

a response containing the created SynonymMap.

deleteAlias

public Mono<Void> deleteAlias(String aliasName)

Deletes the Azure AI Search alias.

Code Sample

Delete the search alias named "my-alias".

SEARCH_INDEX_ASYNC_CLIENT.deleteAlias("my-alias")
     .subscribe(ignored -> System.out.println("Deleted alias 'my-alias'."));

Parameters:

aliasName - name of the alias to delete.

Returns:

a reactive response indicating deletion has completed.

deleteAliasWithResponse

public Mono<Response<Void>> deleteAliasWithResponse(SearchAlias alias, boolean onlyIfUnchanged)

Deletes the Azure AI Search alias.

Code Sample

Get the search alias named "my-alias".

SEARCH_INDEX_ASYNC_CLIENT.getAlias("my-alias")
     .flatMap(searchAlias -> SEARCH_INDEX_ASYNC_CLIENT.deleteAliasWithResponse(searchAlias, true))
     .subscribe(response -> System.out.printf("Response status code %d. Deleted alias 'my-alias'.",
         response.getStatusCode()));

Parameters:

alias - the alias to delete.
onlyIfUnchanged - only delete the alias if the eTag matches the alias on the service

Returns:

a reactive response indicating deletion has completed.

deleteIndex

public Mono<Void> deleteIndex(String indexName)

Deletes an Azure AI Search index and all the documents it contains.

Code Sample

Delete search index with name "searchIndex".

SEARCH_INDEX_ASYNC_CLIENT.deleteIndex("searchIndex")
     .subscribe();

Parameters:

indexName - the name of the index to delete

Returns:

a response signalling completion.

deleteIndexWithResponse

public Mono<Response<Void>> deleteIndexWithResponse(SearchIndex index, boolean onlyIfUnchanged)

Deletes an Azure AI Search index and all the documents it contains.

Code Sample

Delete search index with name "searchIndex".

SEARCH_INDEX_ASYNC_CLIENT.getIndex("searchIndex")
     .flatMap(indexFromService -> SEARCH_INDEX_ASYNC_CLIENT.deleteIndexWithResponse(indexFromService, true))
     .subscribe(deleteResponse ->
         System.out.printf("The status code of the response is %d.%n", deleteResponse.getStatusCode()));

Parameters:

index - the SearchIndex to delete.
onlyIfUnchanged - true to delete if the index is the same as the current service value. false to always delete existing value.

Returns:

a response signalling completion.

deleteKnowledgeBase

public Mono<Void> deleteKnowledgeBase(String knowledgeBaseName)

Deletes an existing agent.

Parameters:

knowledgeBaseName - The name of the agent to delete.

Returns:

A Mono that completes when a successful response is received.

deleteKnowledgeBaseWithResponse

public Mono<Response<Void>> deleteKnowledgeBaseWithResponse(String knowledgeBaseName, MatchConditions matchConditions)

Deletes an existing agent.

Parameters:

knowledgeBaseName - The name of the agent to delete.
matchConditions - Defining If-Match and If-None-Match conditions. If null is passed, no conditions will be applied.

Returns:

the Response<T> on successful completion of Mono.

deleteKnowledgeSource

public Mono<Void> deleteKnowledgeSource(String sourceName)

Deletes an existing knowledge source.

Parameters:

sourceName - The name of the knowledge source to delete.

Returns:

A Mono that completes successfully if the knowledge source was deleted.

deleteKnowledgeSourceWithResponse

public Mono<Response<Void>> deleteKnowledgeSourceWithResponse(String sourceName, MatchConditions matchConditions)

Deletes an existing knowledge source.

Parameters:

sourceName - The name of the knowledge source to delete.
matchConditions - Defining If-Match and If-None-Match conditions. If null is passed, no conditions will be applied.

Returns:

A Mono that produces a Response<T> if the knowledge source was deleted.

deleteSynonymMap

public Mono<Void> deleteSynonymMap(String synonymMapName)

Deletes an Azure AI Search synonym map.

Code Sample

Delete synonym map with name "synonymMap".

SEARCH_INDEX_ASYNC_CLIENT.deleteSynonymMap("synonymMap")
     .subscribe();

Parameters:

synonymMapName - the name of the SynonymMap to delete

Returns:

a response signalling completion.

deleteSynonymMapWithResponse

public Mono<Response<Void>> deleteSynonymMapWithResponse(SynonymMap synonymMap, boolean onlyIfUnchanged)

Deletes an Azure AI Search synonym map.

Code Sample

Delete synonym map with name "synonymMap".

SEARCH_INDEX_ASYNC_CLIENT.getSynonymMap("synonymMap")
     .flatMap(synonymMap -> SEARCH_INDEX_ASYNC_CLIENT.deleteSynonymMapWithResponse(synonymMap, true))
     .subscribe(response -> System.out.println("The status code of the response is" + response.getStatusCode()));

Parameters:

synonymMap - the SynonymMap to delete.
onlyIfUnchanged - true to delete if the synonymMap is the same as the current service value. false to always delete existing value.

Returns:

a response signalling completion.

getAlias

public Mono<SearchAlias> getAlias(String aliasName)

Gets the Azure AI Search alias.

Code Sample

Get the search alias named "my-alias".

SEARCH_INDEX_ASYNC_CLIENT.getAlias("my-alias")
     .subscribe(searchAlias -> System.out.printf("Retrieved alias '%s' that aliases index '%s'.",
         searchAlias.getName(), searchAlias.getIndexes().get(0)));

Parameters:

aliasName - name of the alias to get.

Returns:

the retrieved alias.

getAliasWithResponse

public Mono<Response<SearchAlias>> getAliasWithResponse(String aliasName)

Gets the Azure AI Search alias.

Code Sample

Get the search alias named "my-alias".

SEARCH_INDEX_ASYNC_CLIENT.getAliasWithResponse("my-alias")
     .subscribe(response ->
         System.out.printf("Response status code %d. Retrieved alias '%s' that aliases index '%s'.",
             response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0)));

Parameters:

aliasName - name of the alias to get.

Returns:

the retrieved alias.

getEndpoint

public String getEndpoint()

Gets the endpoint for the Azure AI Search service.

Returns:

the endpoint value.

getIndex

public Mono<SearchIndex> getIndex(String indexName)

Retrieves an index definition from the Azure AI Search.

Code Sample

Get search index with name "searchIndex".

SEARCH_INDEX_ASYNC_CLIENT.getIndex("searchIndex")
     .subscribe(indexFromService ->
         System.out.printf("The index name is %s. The ETag of index is %s.%n", indexFromService.getName(),
             indexFromService.getETag()));

Parameters:

indexName - The name of the index to retrieve

Returns:

the Index.

getIndexStatistics

public Mono<SearchIndexStatistics> getIndexStatistics(String indexName)

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

Code Sample

Get search index "searchIndex" statistics.

SEARCH_INDEX_ASYNC_CLIENT.getIndexStatistics("searchIndex")
     .subscribe(statistics ->
         System.out.printf("There are %d documents and storage size of %d available in 'searchIndex'.%n",
         statistics.getDocumentCount(), statistics.getStorageSize()));

Parameters:

indexName - the name of the index for which to retrieve statistics

Returns:

the index statistics result.

getIndexStatisticsWithResponse

public Mono<Response<SearchIndexStatistics>> getIndexStatisticsWithResponse(String indexName)

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

Code Sample

Get search index "searchIndex" statistics.

SEARCH_INDEX_ASYNC_CLIENT.getIndexStatisticsWithResponse("searchIndex")
     .subscribe(statistics -> System.out.printf("The status code of the response is %s.%n"
             + "There are %d documents and storage size of %d available in 'searchIndex'.%n",
         statistics.getStatusCode(), statistics.getValue().getDocumentCount(),
         statistics.getValue().getStorageSize()));

Parameters:

indexName - the name of the index for which to retrieve statistics

Returns:

a response containing the index statistics result.

getIndexStatsSummary

public PagedFlux<IndexStatisticsSummary> getIndexStatsSummary()

Retrieves a summary of statistics for all indexes in the search service.

Returns:

response from a request to retrieve stats summary of all indexes as paginated response with PagedFlux<T>.

getIndexWithResponse

public Mono<Response<SearchIndex>> getIndexWithResponse(String indexName)

Retrieves an index definition from the Azure AI Search.

Code Sample

Get search index with "searchIndex.

SEARCH_INDEX_ASYNC_CLIENT.getIndexWithResponse("searchIndex")
     .subscribe(indexFromServiceResponse ->
         System.out.printf("The status code of the response is %s. The index name is %s.%n",
             indexFromServiceResponse.getStatusCode(), indexFromServiceResponse.getValue().getName()));

Parameters:

indexName - the name of the index to retrieve

Returns:

a response containing the Index.

getKnowledgeBase

public Mono<KnowledgeBase> getKnowledgeBase(String knowledgeBaseName)

Retrieves an agent definition.

Parameters:

knowledgeBaseName - The name of the agent to retrieve.

Returns:

the response body on successful completion of Mono.

getKnowledgeBaseWithResponse

public Mono<Response<KnowledgeBase>> getKnowledgeBaseWithResponse(String knowledgeBaseName)

Retrieves an agent definition.

Parameters:

knowledgeBaseName - The name of the agent to retrieve.

Returns:

the response body along with Response<T> on successful completion of Mono.

getKnowledgeSource

public Mono<KnowledgeSource> getKnowledgeSource(String sourceName)

Retrieves a knowledge source.

Parameters:

sourceName - The name of the knowledge source to retrieve.

Returns:

A Mono that will produce the retrieved knowledge source.

getKnowledgeSourceWithResponse

public Mono<Response<KnowledgeSource>> getKnowledgeSourceWithResponse(String sourceName)

Retrieves a knowledge source.

Parameters:

sourceName - The name of the knowledge source to retrieve.

Returns:

A Mono that will produce a Response<T> containing the retrieved knowledge source.

getSearchAsyncClient

public SearchAsyncClient getSearchAsyncClient(String indexName)

Initializes a new SearchAsyncClient using the given Index name and the same configuration as the SearchServiceAsyncClient.

Parameters:

indexName - the name of the Index for the client

Returns:

a SearchAsyncClient created from the service client configuration

getServiceStatistics

public Mono<SearchServiceStatistics> getServiceStatistics()

Returns service level statistics for a search service, including service counters and limits.

Contains the tracking ID sent with the request to help with debugging

Code Sample

Get service statistics.

SEARCH_INDEX_ASYNC_CLIENT.getServiceStatistics()
     .subscribe(serviceStatistics -> System.out.printf("There are %s search indexes in your service.%n",
         serviceStatistics.getCounters().getIndexCounter()));

Returns:

the search service statistics result.

getServiceStatisticsWithResponse

public Mono<Response<SearchServiceStatistics>> getServiceStatisticsWithResponse()

Returns service level statistics for a search service, including service counters and limits.

Code Sample

Get service statistics.

SEARCH_INDEX_ASYNC_CLIENT.getServiceStatisticsWithResponse()
     .subscribe(serviceStatistics ->
         System.out.printf("The status code of the response is %s.%n"
                 + "There are %s search indexes in your service.%n",
         serviceStatistics.getStatusCode(),
         serviceStatistics.getValue().getCounters().getIndexCounter()));

Returns:

the search service statistics result.

getSynonymMap

public Mono<SynonymMap> getSynonymMap(String synonymMapName)

Retrieves a synonym map definition.

Code Sample

Get synonym map with name "synonymMap".

SEARCH_INDEX_ASYNC_CLIENT.getSynonymMap("synonymMap")
     .subscribe(synonymMapFromService ->
         System.out.printf("The synonym map is %s. The ETag of synonym map is %s.%n",
             synonymMapFromService.getName(), synonymMapFromService.getETag()));

Parameters:

synonymMapName - name of the synonym map to retrieve

Returns:

the SynonymMap definition

getSynonymMapWithResponse

public Mono<Response<SynonymMap>> getSynonymMapWithResponse(String synonymMapName)

Retrieves a synonym map definition.

Code Sample

Get synonym map with name "synonymMap".

SEARCH_INDEX_ASYNC_CLIENT.getSynonymMap("synonymMap")
     .subscribe(synonymMapFromService ->
         System.out.printf("The synonym map is %s. The ETag of synonym map is %s.%n",
             synonymMapFromService.getName(), synonymMapFromService.getETag()));

Parameters:

synonymMapName - name of the synonym map to retrieve

Returns:

a response containing the SynonymMap.

listAliases

public PagedFlux<SearchAlias> listAliases()

Lists all aliases in the Azure AI Search service.

Code Sample

List aliases

SEARCH_INDEX_ASYNC_CLIENT.listAliases()
     .doOnNext(searchAlias -> System.out.printf("Listed alias '%s' that aliases index '%s'.",
         searchAlias.getName(), searchAlias.getIndexes().get(0)))
     .subscribe();

Returns:

a list of aliases in the service.

listIndexes

public PagedFlux<SearchIndex> listIndexes()

Lists all indexes available for an Azure AI Search service.

Code Sample

List all search indexes.

SEARCH_INDEX_ASYNC_CLIENT.listIndexes()
     .subscribe(index ->
         System.out.printf("The index name is %s. The ETag of index is %s.%n", index.getName(),
             index.getETag()));

Returns:

a reactive response emitting the list of indexes.

listIndexNames

public PagedFlux<String> listIndexNames()

Lists all indexes names for an Azure AI Search service.

Code Sample

List all search indexes names.

SEARCH_INDEX_ASYNC_CLIENT.listIndexNames()
     .subscribe(indexName -> System.out.printf("The index name is %s.%n", indexName));

Returns:

a reactive response emitting the list of index names.

listKnowledgeBases

public PagedFlux<KnowledgeBase> listKnowledgeBases()

Lists all knowledgebases available for a search service.

Returns:

the paginated response with PagedFlux<T>.

listKnowledgeSources

public PagedFlux<KnowledgeSource> listKnowledgeSources()

Lists all knowledge sources available for a search service.

Returns:

A PagedFlux<T> of knowledge source.

listSynonymMapNames

public PagedFlux<String> listSynonymMapNames()

Lists all synonym map names for an Azure AI Search service.

Code Sample

List all synonym map names.

SEARCH_INDEX_ASYNC_CLIENT.listSynonymMapNames()
     .subscribe(synonymMap -> System.out.printf("The synonymMap name is %s.%n", synonymMap));

Returns:

a reactive response emitting the list of synonym map names.

listSynonymMaps

public PagedFlux<SynonymMap> listSynonymMaps()

Lists all synonym maps available for an Azure AI Search service.

Code Sample

List all synonym maps.

SEARCH_INDEX_ASYNC_CLIENT.listSynonymMaps()
     .subscribe(synonymMap -> System.out.printf("The synonymMap name is %s. The ETag of synonymMap is %s.%n",
         synonymMap.getName(), synonymMap.getETag()));

Returns:

a reactive response emitting the list of synonym maps.

Applies to