Class SearchIndexClient
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 from search indexes. Once uploaded, you can point any searchable field to the synonym map (one per field).
This client provides a synchronous 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:
SearchIndexClient searchIndexClient = new SearchIndexClientBuilder()
.credential(new AzureKeyCredential("{key}"))
.endpoint("{endpoint}")
.buildClient();
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))
));
searchIndexClient.createIndex(searchIndex);
For an asynchronous sample see SearchIndexAsyncClient.createIndex(SearchIndex).
List indexes
The following sample lists all indexes.
searchIndexClient.listIndexes().forEach(index -> System.out.println(index.getName()));For an asynchronous sample see
SearchIndexAsyncClient.listIndexes().
Retrieve an Index
The following sample retrieves an index.
SearchIndex searchIndex = searchIndexClient.getIndex("indexName");
if (searchIndex != null) {
System.out.println("The ETag of the index is " + searchIndex.getETag());
}
For an asynchronous sample see SearchIndexAsyncClient.getIndex(String).
Update an Index
The following sample updates an index.
SearchIndex searchIndex = searchIndexClient.getIndex("indexName");
if (searchIndex != null) {
searchIndex.setFields(new SearchField("newField", SearchFieldDataType.STRING));
searchIndexClient.createOrUpdateIndex(searchIndex);
}
For an asynchronous sample see SearchIndexAsyncClient.createOrUpdateIndex(SearchIndex).
Delete an Index
The following sample deletes an index.
String indexName = "indexName"; searchIndexClient.deleteIndex(indexName);For an asynchronous sample see
SearchIndexAsyncClient.deleteIndex(String).
Create a Synonym Map
The following sample creates a synonym map.
SynonymMap synonymMap = new SynonymMap("synonymMapName", "hotel, motel, \"motor inn\"");
searchIndexClient.createSynonymMap(synonymMap);
For an asynchronous sample see SearchIndexAsyncClient.createSynonymMap(SynonymMap).
List Synonym Maps
The following sample lists all synonym maps.
searchIndexClient.listSynonymMaps().forEach(synonymMap -> System.out.println(synonymMap.getName()));For an asynchronous sample see
SearchIndexAsyncClient.listSynonymMaps().
Retrieve a Synonym Map
The following sample retrieves a synonym map.
SynonymMap synonymMap = searchIndexClient.getSynonymMap("synonymMapName");
if (synonymMap != null) {
System.out.println("The ETag of the synonymMap is " + synonymMap.getETag());
}
For an asynchronous sample see SearchIndexAsyncClient.getSynonymMap(String).
Update a Synonym Map
The following sample updates a synonym map.
SynonymMap synonymMap = searchIndexClient.getSynonymMap("synonymMapName");
if (synonymMap != null) {
synonymMap.setSynonyms("inn,hotel,motel");
searchIndexClient.createOrUpdateSynonymMap(synonymMap);
}
For an asynchronous sample see SearchIndexAsyncClient.createOrUpdateSynonymMap(SynonymMap).
Delete a Synonym Map
The following sample deletes a synonym map.
String synonymMapName = "synonymMapName"; searchIndexClient.deleteSynonymMap(synonymMapName);For an asynchronous sample see
SearchIndexAsyncClient.deleteSynonymMap(String).
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncom.azure.core.http.rest.PagedIterable<AnalyzedTokenInfo> analyzeText(String indexName, AnalyzeTextOptions analyzeTextOptions) Shows how an analyzer breaks text into tokens.com.azure.core.http.rest.PagedIterable<AnalyzedTokenInfo> analyzeText(String indexName, AnalyzeTextOptions analyzeTextOptions, com.azure.core.util.Context context) Shows how an analyzer breaks text into tokens.static List<SearchField> buildSearchFields(Class<?> model, FieldBuilderOptions options) Convenience method to convert aClass'sFieldsandMethodsintoSearchFieldsto help aid the creation of aSearchFieldwhich represents theClass.createIndex(SearchIndex index) Creates a new Azure AI Search indexcom.azure.core.http.rest.Response<SearchIndex> createIndexWithResponse(SearchIndex index, com.azure.core.util.Context context) Creates a new Azure AI Search indexcreateOrUpdateIndex(SearchIndex index) Creates a new Azure AI Search index or updates an index if it already exists.com.azure.core.http.rest.Response<SearchIndex> createOrUpdateIndexWithResponse(SearchIndex index, boolean allowIndexDowntime, boolean onlyIfUnchanged, com.azure.core.util.Context context) Creates a new Azure AI Search index or updates an index if it already exists.createOrUpdateSynonymMap(SynonymMap synonymMap) Creates a new Azure AI Search synonym map or updates a synonym map if it already exists.com.azure.core.http.rest.Response<SynonymMap> createOrUpdateSynonymMapWithResponse(SynonymMap synonymMap, boolean onlyIfUnchanged, com.azure.core.util.Context context) Creates a new Azure AI Search synonym map or updates a synonym map if it already exists.createSynonymMap(SynonymMap synonymMap) Creates a new Azure AI Search synonym map.com.azure.core.http.rest.Response<SynonymMap> createSynonymMapWithResponse(SynonymMap synonymMap, com.azure.core.util.Context context) Creates a new Azure AI Search synonym map.voiddeleteIndex(String indexName) Deletes an Azure AI Search index and all the documents it contains.com.azure.core.http.rest.Response<Void> deleteIndexWithResponse(SearchIndex index, boolean onlyIfUnchanged, com.azure.core.util.Context context) Deletes an Azure AI Search index and all the documents it contains.voiddeleteSynonymMap(String synonymMapName) Deletes an Azure AI Search synonym map.com.azure.core.http.rest.Response<Void> deleteSynonymMapWithResponse(SynonymMap synonymMap, boolean onlyIfUnchanged, com.azure.core.util.Context context) Deletes an Azure AI Search synonym map.Gets the endpoint for the Azure AI Search service.Retrieves an index definition from the Azure AI Search.getIndexStatistics(String indexName) Returns statistics for the given index, including a document count and storage usage.com.azure.core.http.rest.Response<SearchIndexStatistics> getIndexStatisticsWithResponse(String indexName, com.azure.core.util.Context context) Returns statistics for the given index, including a document count and storage usage.com.azure.core.http.rest.PagedIterable<IndexStatisticsSummary> Retrieves a summary of statistics for all indexes in the search service.com.azure.core.http.rest.PagedIterable<IndexStatisticsSummary> getIndexStatsSummary(com.azure.core.util.Context context) Retrieves a summary of statistics for all indexes in the search service.com.azure.core.http.rest.Response<SearchIndex> getIndexWithResponse(String indexName, com.azure.core.util.Context context) Retrieves an index definition from the Azure AI Search.getSearchClient(String indexName) Initializes a newSearchClientusing the given Index name and the same configuration as the SearchServiceClient.Returns service level statistics for a search service, including service counters and limits.com.azure.core.http.rest.Response<SearchServiceStatistics> getServiceStatisticsWithResponse(com.azure.core.util.Context context) Returns service level statistics for a search service, including service counters and limits.getSynonymMap(String synonymMapName) Retrieves a synonym map definition.com.azure.core.http.rest.Response<SynonymMap> getSynonymMapWithResponse(String synonymMapName, com.azure.core.util.Context context) Retrieves a synonym map definition.com.azure.core.http.rest.PagedIterable<SearchIndex> Lists all indexes available for an Azure AI Search service.com.azure.core.http.rest.PagedIterable<SearchIndex> listIndexes(com.azure.core.util.Context context) Lists all indexes available for an Azure AI Search service.com.azure.core.http.rest.PagedIterable<String> Lists all index names for an Azure AI Search service.com.azure.core.http.rest.PagedIterable<String> listIndexNames(com.azure.core.util.Context context) Lists all indexes names for an Azure AI Search service.com.azure.core.http.rest.PagedIterable<String> Lists all synonym maps names for an Azure AI Search service.com.azure.core.http.rest.PagedIterable<String> listSynonymMapNames(com.azure.core.util.Context context) Lists all synonym maps names for an Azure AI Search service.com.azure.core.http.rest.PagedIterable<SynonymMap> Lists all synonym maps available for an Azure AI Search service.com.azure.core.http.rest.PagedIterable<SynonymMap> listSynonymMaps(com.azure.core.util.Context context) Lists all synonym maps available for an Azure AI Search service.
-
Method Details
-
getEndpoint
Gets the endpoint for the Azure AI Search service.- Returns:
- the endpoint value.
-
getSearchClient
Initializes a newSearchClientusing the given Index name and the same configuration as the SearchServiceClient.- Parameters:
indexName- the name of the Index for the client- Returns:
- a
SearchClientcreated from the service client configuration
-
createIndex
Creates a new Azure AI Search indexCode 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); SearchIndex indexFromService = SEARCH_INDEX_CLIENT.createIndex(searchIndex); 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 com.azure.core.http.rest.Response<SearchIndex> createIndexWithResponse(SearchIndex index, com.azure.core.util.Context context) Creates a new Azure AI Search indexCode 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); Response<SearchIndex> indexFromServiceResponse = SEARCH_INDEX_CLIENT.createIndexWithResponse(searchIndex, new Context(KEY_1, VALUE_1)); 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 createcontext- additional context that is passed through the HTTP pipeline during the service call- Returns:
- a response containing the created Index.
-
getIndex
Retrieves an index definition from the Azure AI Search.Code Sample
Get search index with name "searchIndex".
SearchIndex indexFromService = SEARCH_INDEX_CLIENT.getIndex("searchIndex"); 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.
-
getIndexWithResponse
public com.azure.core.http.rest.Response<SearchIndex> getIndexWithResponse(String indexName, com.azure.core.util.Context context) Retrieves an index definition from the Azure AI Search.Code Sample
Get search index with "searchIndex.
Response<SearchIndex> indexFromServiceResponse = SEARCH_INDEX_CLIENT.getIndexWithResponse("searchIndex", new Context(KEY_1, VALUE_1)); 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 retrievecontext- additional context that is passed through the HTTP pipeline during the service call- Returns:
- a response containing the Index.
-
getIndexStatistics
Returns statistics for the given index, including a document count and storage usage.Code Sample
Get search index "searchIndex" statistics.
SearchIndexStatistics statistics = SEARCH_INDEX_CLIENT.getIndexStatistics("searchIndex"); 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 com.azure.core.http.rest.Response<SearchIndexStatistics> getIndexStatisticsWithResponse(String indexName, com.azure.core.util.Context context) Returns statistics for the given index, including a document count and storage usage.Code Sample
Get search index "searchIndex" statistics.
Response<SearchIndexStatistics> statistics = SEARCH_INDEX_CLIENT.getIndexStatisticsWithResponse("searchIndex", new Context(KEY_1, VALUE_1)); 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 statisticscontext- additional context that is passed through the HTTP pipeline during the service call- Returns:
- a response containing the index statistics result.
-
listIndexes
Lists all indexes available for an Azure AI Search service.Code Sample
List all search indexes.
PagedIterable<SearchIndex> indexes = SEARCH_INDEX_CLIENT.listIndexes(); for (SearchIndex index: indexes) { System.out.printf("The index name is %s. The ETag of index is %s.%n", index.getName(), index.getETag()); }- Returns:
- the list of indexes.
-
listIndexes
public com.azure.core.http.rest.PagedIterable<SearchIndex> listIndexes(com.azure.core.util.Context context) Lists all indexes available for an Azure AI Search service.Code Sample
List all search indexes.
PagedIterable<SearchIndex> indexes = SEARCH_INDEX_CLIENT.listIndexes(new Context(KEY_1, VALUE_1)); System.out.println("The status code of the response is" + indexes.iterableByPage().iterator().next().getStatusCode()); for (SearchIndex index: indexes) { System.out.printf("The index name is %s. The ETag of index is %s.%n", index.getName(), index.getETag()); }- Parameters:
context- additional context that is passed through the HTTP pipeline during the service call- Returns:
- the list of indexes.
-
listIndexNames
Lists all index names for an Azure AI Search service.Code Sample
List all search indexes names.
PagedIterable<String> indexes = SEARCH_INDEX_CLIENT.listIndexNames(); for (String indexName: indexes) { System.out.printf("The index name is %s.%n", indexName); }- Returns:
- the list of index names.
-
listIndexNames
public com.azure.core.http.rest.PagedIterable<String> listIndexNames(com.azure.core.util.Context context) Lists all indexes names for an Azure AI Search service.Code Sample
List all search indexes names.
PagedIterable<String> indexes = SEARCH_INDEX_CLIENT.listIndexNames(new Context(KEY_1, VALUE_1)); System.out.println("The status code of the response is" + indexes.iterableByPage().iterator().next().getStatusCode()); for (String indexName: indexes) { System.out.printf("The index name is %s.%n", indexName); }- Parameters:
context- additional context that is passed through the HTTP pipeline during the service call- Returns:
- the list of index names.
-
createOrUpdateIndex
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")))); SearchIndex updatedIndex = SEARCH_INDEX_CLIENT.createOrUpdateIndex(indexFromService); 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 index to create or update- Returns:
- the index that was created or updated.
-
createOrUpdateIndexWithResponse
public com.azure.core.http.rest.Response<SearchIndex> createOrUpdateIndexWithResponse(SearchIndex index, boolean allowIndexDowntime, boolean onlyIfUnchanged, com.azure.core.util.Context context) 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- theSearchIndexto create or updateallowIndexDowntime- 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-trueto update if theindexis the same as the current service value.falseto always update existing value.context- additional context that is passed through the HTTP pipeline during the service call- Returns:
- a response containing the Index that was created or updated.
-
deleteIndex
Deletes an Azure AI Search index and all the documents it contains.Code Sample
Delete search index with name "searchIndex".
SEARCH_INDEX_CLIENT.deleteIndex("searchIndex");- Parameters:
indexName- the name of the index to delete
-
deleteIndexWithResponse
public com.azure.core.http.rest.Response<Void> deleteIndexWithResponse(SearchIndex index, boolean onlyIfUnchanged, com.azure.core.util.Context context) Deletes an Azure AI Search index and all the documents it contains.Code Sample
Delete search index with name "searchIndex".
SearchIndex indexFromService = SEARCH_INDEX_CLIENT.getIndex("searchIndex"); Response<Void> deleteResponse = SEARCH_INDEX_CLIENT.deleteIndexWithResponse(indexFromService, true, new Context(KEY_1, VALUE_1)); System.out.printf("The status code of the response is %d.%n", deleteResponse.getStatusCode());- Parameters:
index- the SearchSearchIndexto delete.onlyIfUnchanged-trueto delete if theindexis the same as the current service value.falseto always delete existing value.context- additional context that is passed through the Http pipeline during the service call- Returns:
- a response signalling completion.
-
analyzeText
public com.azure.core.http.rest.PagedIterable<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".
PagedIterable<AnalyzedTokenInfo> tokenInfos = SEARCH_INDEX_CLIENT.analyzeText("searchIndex", new AnalyzeTextOptions("The quick brown fox", LexicalTokenizerName.CLASSIC)); for (AnalyzedTokenInfo tokenInfo : tokenInfos) { 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 analyzeranalyzeTextOptions- the text and analyzer or analysis components to test. Requires to provide eitherLexicalTokenizerNameorLexicalAnalyzerName.- Returns:
- analyze result.
-
analyzeText
public com.azure.core.http.rest.PagedIterable<AnalyzedTokenInfo> analyzeText(String indexName, AnalyzeTextOptions analyzeTextOptions, com.azure.core.util.Context context) Shows how an analyzer breaks text into tokens.Code Sample
Analyzer text response with LexicalTokenizerName "Classic" in search index "searchIndex".
PagedIterable<AnalyzedTokenInfo> tokenInfos = SEARCH_INDEX_CLIENT.analyzeText("searchIndex", new AnalyzeTextOptions("The quick brown fox", LexicalTokenizerName.CLASSIC), new Context(KEY_1, VALUE_1)); System.out.println("The status code of the response is " + tokenInfos.iterableByPage().iterator().next().getStatusCode()); for (AnalyzedTokenInfo tokenInfo : tokenInfos) { 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 analyzeranalyzeTextOptions- the text and analyzer or analysis components to test. Requires to provide eitherLexicalTokenizerNameorLexicalAnalyzerName.context- additional context that is passed through the HTTP pipeline during the service call- Returns:
- analyze result.
-
createSynonymMap
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"); SynonymMap synonymMapFromService = SEARCH_INDEX_CLIENT.createSynonymMap(synonymMap); 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 com.azure.core.http.rest.Response<SynonymMap> createSynonymMapWithResponse(SynonymMap synonymMap, com.azure.core.util.Context context) 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"); Response<SynonymMap> synonymMapFromService = SEARCH_INDEX_CLIENT.createSynonymMapWithResponse(synonymMap, new Context(KEY_1, VALUE_1)); 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 synonym map to createcontext- additional context that is passed through the HTTP pipeline during the service call- Returns:
- a response containing the created SynonymMap.
-
getSynonymMap
Retrieves a synonym map definition.Code Sample
Get synonym map with name "synonymMap".
SynonymMap synonymMapFromService = SEARCH_INDEX_CLIENT.getSynonymMap("synonymMap"); 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
SynonymMapdefinition
-
getSynonymMapWithResponse
public com.azure.core.http.rest.Response<SynonymMap> getSynonymMapWithResponse(String synonymMapName, com.azure.core.util.Context context) Retrieves a synonym map definition.Code Sample
Get synonym map with name "synonymMap".
Response<SynonymMap> synonymMapFromService = SEARCH_INDEX_CLIENT.getSynonymMapWithResponse("synonymMap", new Context(KEY_1, VALUE_1)); 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:
synonymMapName- name of the synonym map to retrievecontext- a context that is passed through the HTTP pipeline during the service call- Returns:
- a response containing the SynonymMap.
-
listSynonymMaps
Lists all synonym maps available for an Azure AI Search service.Code Sample
List all synonym maps.
PagedIterable<SynonymMap> synonymMaps = SEARCH_INDEX_CLIENT.listSynonymMaps(); for (SynonymMap synonymMap: synonymMaps) { System.out.printf("The synonymMap name is %s. The ETag of synonymMap is %s.%n", synonymMap.getName(), synonymMap.getETag()); }- Returns:
- the list of synonym maps.
-
listSynonymMaps
public com.azure.core.http.rest.PagedIterable<SynonymMap> listSynonymMaps(com.azure.core.util.Context context) Lists all synonym maps available for an Azure AI Search service.Code Sample
List all synonym maps.
PagedIterable<SynonymMap> synonymMaps = SEARCH_INDEX_CLIENT.listSynonymMaps(new Context(KEY_1, VALUE_1)); System.out.println("The status code of the response is" + synonymMaps.iterableByPage().iterator().next().getStatusCode()); for (SynonymMap index: synonymMaps) { System.out.printf("The index name is %s. The ETag of index is %s.%n", index.getName(), index.getETag()); }- Parameters:
context- additional context that is passed through the HTTP pipeline during the service call- Returns:
- the list of synonym map names.
-
listSynonymMapNames
Lists all synonym maps names for an Azure AI Search service.Code Sample
List all synonym map names.
PagedIterable<String> synonymMaps = SEARCH_INDEX_CLIENT.listSynonymMapNames(); for (String synonymMap: synonymMaps) { System.out.printf("The synonymMap name is %s.%n", synonymMap); }- Returns:
- the list of synonym maps.
-
listSynonymMapNames
public com.azure.core.http.rest.PagedIterable<String> listSynonymMapNames(com.azure.core.util.Context context) Lists all synonym maps names for an Azure AI Search service.Code Sample
List all synonym map names.
PagedIterable<String> synonymMaps = SEARCH_INDEX_CLIENT.listIndexNames(new Context(KEY_1, VALUE_1)); System.out.println("The status code of the response is" + synonymMaps.iterableByPage().iterator().next().getStatusCode()); for (String synonymMapNames: synonymMaps) { System.out.printf("The synonymMap name is %s.%n", synonymMapNames); }- Parameters:
context- additional context that is passed through the HTTP pipeline during the service call- Returns:
- the list of synonym map names.
-
createOrUpdateSynonymMap
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".
SynonymMap synonymMap = SEARCH_INDEX_CLIENT.getSynonymMap("synonymMapName"); synonymMap.setSynonyms("United States, United States of America, USA, America\nWashington, Wash. => WA"); SynonymMap updatedSynonymMap = SEARCH_INDEX_CLIENT.createOrUpdateSynonymMap(synonymMap); System.out.printf("The synonym map name is %s. The synonyms are %s.%n", updatedSynonymMap.getName(), updatedSynonymMap.getSynonyms());- Parameters:
synonymMap- the definition of the synonym map to create or update- Returns:
- the synonym map that was created or updated.
-
createOrUpdateSynonymMapWithResponse
public com.azure.core.http.rest.Response<SynonymMap> createOrUpdateSynonymMapWithResponse(SynonymMap synonymMap, boolean onlyIfUnchanged, com.azure.core.util.Context context) 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".
SynonymMap synonymMap = SEARCH_INDEX_CLIENT.getSynonymMap("synonymMap"); synonymMap.setSynonyms("United States, United States of America, USA, America\nWashington, Wash. => WA"); Response<SynonymMap> updatedSynonymMap = SEARCH_INDEX_CLIENT.createOrUpdateSynonymMapWithResponse(synonymMap, true, new Context(KEY_1, VALUE_1)); 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 synonym map to create or updateonlyIfUnchanged-trueto update if thesynonymMapis the same as the current service value.falseto always update existing value.context- additional context that is passed through the HTTP pipeline during the service call- Returns:
- a response containing the synonym map that was created or updated.
-
deleteSynonymMap
Deletes an Azure AI Search synonym map.Code Sample
Delete synonym map with name "synonymMap".
SEARCH_INDEX_CLIENT.deleteSynonymMap("synonymMap");- Parameters:
synonymMapName- the name of the synonym map to delete
-
deleteSynonymMapWithResponse
public com.azure.core.http.rest.Response<Void> deleteSynonymMapWithResponse(SynonymMap synonymMap, boolean onlyIfUnchanged, com.azure.core.util.Context context) Deletes an Azure AI Search synonym map.Code Sample
Delete synonym map with name "synonymMap".
SynonymMap synonymMap = SEARCH_INDEX_CLIENT.getSynonymMap("synonymMap"); Response<Void> response = SEARCH_INDEX_CLIENT.deleteSynonymMapWithResponse(synonymMap, true, new Context(KEY_1, VALUE_1)); System.out.println("The status code of the response is" + response.getStatusCode());- Parameters:
synonymMap- theSynonymMapto delete.onlyIfUnchanged-trueto delete if thesynonymMapis the same as the current service value.falseto always delete existing value.context- additional context that is passed through the Http pipeline during the service call- Returns:
- a response signalling completion.
-
getServiceStatistics
Returns service level statistics for a search service, including service counters and limits.Code Sample
Get service statistics.
SearchServiceStatistics serviceStatistics = SEARCH_INDEX_CLIENT.getServiceStatistics(); System.out.printf("There are %s search indexes in your service.%n", serviceStatistics.getCounters().getIndexCounter());- Returns:
- the search service statistics result.
-
getServiceStatisticsWithResponse
public com.azure.core.http.rest.Response<SearchServiceStatistics> getServiceStatisticsWithResponse(com.azure.core.util.Context context) Returns service level statistics for a search service, including service counters and limits.Code Sample
Get service statistics.
Response<SearchServiceStatistics> serviceStatistics = SEARCH_INDEX_CLIENT.getServiceStatisticsWithResponse(new Context(KEY_1, VALUE_1)); System.out.printf("The status code of the response is %s.%nThere are %s search indexes in your service.%n", serviceStatistics.getStatusCode(), serviceStatistics.getValue().getCounters().getIndexCounter());- Parameters:
context- additional context that is passed through the HTTP pipeline during the service call- Returns:
- the search service statistics result.
-
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
PagedIterable. - Throws:
IllegalArgumentException- thrown if parameters fail the validation.com.azure.search.documents.indexes.implementation.models.ErrorResponseException- thrown if the request is rejected by server.RuntimeException- all other wrapped checked exceptions if the request fails to be sent.
-
getIndexStatsSummary
public com.azure.core.http.rest.PagedIterable<IndexStatisticsSummary> getIndexStatsSummary(com.azure.core.util.Context context) Retrieves a summary of statistics for all indexes in the search service.- Parameters:
context- The context to associate with this operation.- Returns:
- response from a request to retrieve stats summary of all indexes as paginated response with
PagedResponse. - Throws:
IllegalArgumentException- thrown if parameters fail the validation.com.azure.search.documents.indexes.implementation.models.ErrorResponseException- thrown if the request is rejected by server.RuntimeException- all other wrapped checked exceptions if the request fails to be sent.
-
buildSearchFields
Convenience method to convert aClass'sFieldsandMethodsintoSearchFieldsto help aid the creation of aSearchFieldwhich represents theClass.- Parameters:
model- The modelClassthat will haveSearchFieldsgenerated from its structure.options- Configuration used to determine generation of theSearchFields.- Returns:
- A list
SearchFieldswhich represent the modelClass.
-