SearchIndexClient Class
- java.
lang. Object - com.
azure. search. documents. indexes. SearchIndexClient
- com.
public final class SearchIndexClient
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 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 createIndex(SearchIndex index).
List indexes
The following sample lists all indexes.
searchIndexClient.listIndexes().forEach(index -> System.out.println(index.getName()));
For an asynchronous sample see 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 getIndex(String name).
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 createOrUpdateIndex(SearchIndex index).
Delete an Index
The following sample deletes an index.
String indexName = "indexName";
searchIndexClient.deleteIndex(indexName);
For an asynchronous 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\"");
searchIndexClient.createSynonymMap(synonymMap);
For an asynchronous sample see createSynonymMap(SynonymMap 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 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 getSynonymMap(String name).
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 createOrUpdateSynonymMap(SynonymMap synonymMap).
Delete a Synonym Map
The following sample deletes a synonym map.
String synonymMapName = "synonymMapName";
searchIndexClient.deleteSynonymMap(synonymMapName);
For an asynchronous sample see deleteSynonymMap(String name).
Method Summary
Methods inherited from java.lang.Object
Method Details
analyzeText
public 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:
Returns:
analyzeText
public PagedIterable<AnalyzedTokenInfo> analyzeText(String indexName, AnalyzeTextOptions analyzeTextOptions, 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:
Returns:
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:
Returns:
createAlias
public SearchAlias createAlias(SearchAlias alias)
Creates a new Azure AI Search alias.
Code Sample
Create the search alias named "my-alias".
SearchAlias searchAlias = SEARCH_INDEX_CLIENT.createAlias(new SearchAlias("my-alias",
Collections.singletonList("index-to-alias")));
System.out.printf("Created alias '%s' that aliases index '%s'.", searchAlias.getName(),
searchAlias.getIndexes().get(0));
Parameters:
Returns:
createAliasWithResponse
public Response<SearchAlias> createAliasWithResponse(SearchAlias alias, Context context)
Creates a new Azure AI Search alias.
Code Sample
Create the search alias named "my-alias".
Response<SearchAlias> response = SEARCH_INDEX_CLIENT.createAliasWithResponse(new SearchAlias("my-alias",
Collections.singletonList("index-to-alias")), new Context(KEY_1, VALUE_1));
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:
Returns:
createIndex
public 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);
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:
Returns:
createIndexWithResponse
public Response<SearchIndex> createIndexWithResponse(SearchIndex index, Context context)
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);
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:
Returns:
createKnowledgeBase
public KnowledgeBase createKnowledgeBase(KnowledgeBase knowledgeBases)
Creates a new agent.
Parameters:
Returns:
createKnowledgeBaseWithResponse
public Response<KnowledgeBase> createKnowledgeBaseWithResponse(KnowledgeBase knowledgeBases, Context context)
Creates a new agent.
Parameters:
Returns:
createKnowledgeSource
public KnowledgeSource createKnowledgeSource(KnowledgeSource knowledgeSource)
Creates a new knowledge source.
Parameters:
Returns:
createKnowledgeSourceWithResponse
public Response<KnowledgeSource> createKnowledgeSourceWithResponse(KnowledgeSource knowledgeSource, Context context)
Creates a new knowledge source.
Parameters:
Returns:
createOrUpdateAlias
public SearchAlias createOrUpdateAlias(SearchAlias alias)
Creates or updates an Azure AI Search alias.
Code Sample
Create then update the search alias named "my-alias".
SearchAlias searchAlias = SEARCH_INDEX_CLIENT.createOrUpdateAlias(
new SearchAlias("my-alias", Collections.singletonList("index-to-alias")));
System.out.printf("Created alias '%s' that aliases index '%s'.", searchAlias.getName(),
searchAlias.getIndexes().get(0));
searchAlias = SEARCH_INDEX_CLIENT.createOrUpdateAlias(new SearchAlias(searchAlias.getName(),
Collections.singletonList("new-index-to-alias")));
System.out.printf("Updated alias '%s' to aliases index '%s'.", searchAlias.getName(),
searchAlias.getIndexes().get(0));
Parameters:
Returns:
createOrUpdateAliasWithResponse
public Response<SearchAlias> createOrUpdateAliasWithResponse(SearchAlias alias, boolean onlyIfUnchanged, Context context)
Creates or updates an Azure AI Search alias.
Code Sample
Create then update the search alias named "my-alias".
Response<SearchAlias> response = SEARCH_INDEX_CLIENT.createOrUpdateAliasWithResponse(
new SearchAlias("my-alias", Collections.singletonList("index-to-alias")), false, new Context(KEY_1, VALUE_1));
System.out.printf("Response status code %d. Created alias '%s' that aliases index '%s'.",
response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0));
response = SEARCH_INDEX_CLIENT.createOrUpdateAliasWithResponse(
new SearchAlias(response.getValue().getName(), Collections.singletonList("new-index-to-alias"))
.setETag(response.getValue().getETag()), true, new Context(KEY_1, VALUE_1));
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:
Returns:
createOrUpdateIndex
public 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".
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:
Returns:
createOrUpdateIndexWithResponse
public Response<SearchIndex> createOrUpdateIndexWithResponse(SearchIndex index, boolean allowIndexDowntime, boolean onlyIfUnchanged, 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:
true to update if the index is the same as the current service value.
false to always update existing value.
Returns:
createOrUpdateKnowledgeBase
public KnowledgeBase createOrUpdateKnowledgeBase(KnowledgeBase knowledgeBases)
Creates a new agent or updates an agent if it already exists.
Parameters:
Returns:
createOrUpdateKnowledgeBaseWithResponse
public Response<KnowledgeBase> createOrUpdateKnowledgeBaseWithResponse(KnowledgeBase knowledgeBases, MatchConditions matchConditions, Context context)
Creates a new agent or updates an agent if it already exists.
Parameters:
If-Match and If-None-Match conditions. If null is passed, no
conditions will be applied.
Returns:
createOrUpdateKnowledgeSource
public KnowledgeSource createOrUpdateKnowledgeSource(KnowledgeSource knowledgeSource)
Creates or updates a knowledge source.
Parameters:
Returns:
createOrUpdateKnowledgeSourceWithResponse
public Response<KnowledgeSource> createOrUpdateKnowledgeSourceWithResponse(KnowledgeSource knowledgeSource, MatchConditions matchConditions, Context context)
Creates or updates a knowledge source.
Parameters:
If-Match and If-None-Match conditions. If null is passed, no
conditions will be applied.
Returns:
createOrUpdateSynonymMap
public 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".
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:
Returns:
createOrUpdateSynonymMapWithResponse
public Response<SynonymMap> createOrUpdateSynonymMapWithResponse(SynonymMap synonymMap, boolean onlyIfUnchanged, 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:
true to update if the synonymMap is the same as the current service value.
false to always update existing value.
Returns:
createSynonymMap
public 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");
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:
Returns:
createSynonymMapWithResponse
public Response<SynonymMap> createSynonymMapWithResponse(SynonymMap synonymMap, 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:
Returns:
deleteAlias
public void deleteAlias(String aliasName)
Deletes the Azure AI Search alias.
Code Sample
Delete the search alias named "my-alias".
SEARCH_INDEX_CLIENT.deleteAlias("my-alias");
System.out.println("Deleted alias 'my-alias'.");
Parameters:
deleteAliasWithResponse
public Response<Void> deleteAliasWithResponse(SearchAlias alias, boolean onlyIfUnchanged, Context context)
Deletes the Azure AI Search alias.
Code Sample
Delete the search alias named "my-alias".
SearchAlias searchAlias = SEARCH_INDEX_CLIENT.getAlias("my-alias");
Response<Void> response = SEARCH_INDEX_CLIENT.deleteAliasWithResponse(searchAlias, true,
new Context(KEY_1, VALUE_1));
System.out.printf("Response status code %d. Deleted alias 'my-alias'.", response.getStatusCode());
Parameters:
Returns:
deleteIndex
public 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_CLIENT.deleteIndex("searchIndex");
Parameters:
deleteIndexWithResponse
public Response<Void> deleteIndexWithResponse(SearchIndex index, boolean onlyIfUnchanged, 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:
true to delete if the index is the same as the current service value.
false to always delete existing value.
Returns:
deleteKnowledgeBase
public void deleteKnowledgeBase(String knowledgeBaseName)
Deletes an existing agent.
Parameters:
deleteKnowledgeBaseWithResponse
public Response<Void> deleteKnowledgeBaseWithResponse(String knowledgeBaseName, MatchConditions matchConditions, Context context)
Deletes an existing agent.
Parameters:
If-Match and If-None-Match conditions. If null is passed, no
conditions will be applied.
Returns:
deleteKnowledgeSource
public void deleteKnowledgeSource(String sourceName)
Deletes an existing knowledge agent.
Parameters:
deleteKnowledgeSourceWithResponse
public Response<Void> deleteKnowledgeSourceWithResponse(String sourceName, MatchConditions matchConditions, Context context)
Deletes an existing knowledge source.
Parameters:
If-Match and If-None-Match conditions. If null is passed, no
conditions will be applied.
Returns:
deleteSynonymMap
public void deleteSynonymMap(String synonymMapName)
Deletes an Azure AI Search synonym map.
Code Sample
Delete synonym map with name "synonymMap".
SEARCH_INDEX_CLIENT.deleteSynonymMap("synonymMap");
Parameters:
deleteSynonymMapWithResponse
public Response<Void> deleteSynonymMapWithResponse(SynonymMap synonymMap, boolean onlyIfUnchanged, 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:
true to delete if the synonymMap is the same as the current service value.
false to always delete existing value.
Returns:
getAlias
public SearchAlias getAlias(String aliasName)
Gets the Azure AI Search alias.
Code Sample
Get the search alias named "my-alias".
SearchAlias searchAlias = SEARCH_INDEX_CLIENT.getAlias("my-alias");
System.out.printf("Retrieved alias '%s' that aliases index '%s'.", searchAlias.getName(),
searchAlias.getIndexes().get(0));
Parameters:
Returns:
getAliasWithResponse
public Response<SearchAlias> getAliasWithResponse(String aliasName, Context context)
Gets the Azure AI Search alias.
Code Sample
Get the search alias named "my-alias".
Response<SearchAlias> response = SEARCH_INDEX_CLIENT.getAliasWithResponse("my-alias", new Context(KEY_1, VALUE_1));
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:
Returns:
getEndpoint
public String getEndpoint()
Gets the endpoint for the Azure AI Search service.
Returns:
getIndex
public SearchIndex getIndex(String indexName)
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:
Returns:
getIndexStatistics
public SearchIndexStatistics getIndexStatistics(String indexName)
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:
Returns:
getIndexStatisticsWithResponse
public Response<SearchIndexStatistics> getIndexStatisticsWithResponse(String indexName, 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:
Returns:
getIndexStatsSummary
public PagedIterable<IndexStatisticsSummary> getIndexStatsSummary()
Retrieves a summary of statistics for all indexes in the search service.
Returns:
getIndexStatsSummary
public PagedIterable<IndexStatisticsSummary> getIndexStatsSummary(Context context)
Retrieves a summary of statistics for all indexes in the search service.
Parameters:
Returns:
getIndexWithResponse
public Response<SearchIndex> getIndexWithResponse(String indexName, 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:
Returns:
getKnowledgeBase
public KnowledgeBase getKnowledgeBase(String knowledgeBaseName)
Retrieves an agent definition.
Parameters:
Returns:
getKnowledgeBaseWithResponse
public Response<KnowledgeBase> getKnowledgeBaseWithResponse(String knowledgeBaseName, Context context)
Retrieves an agent definition.
Parameters:
Returns:
getKnowledgeSource
public KnowledgeSource getKnowledgeSource(String sourceName)
Retrieves a knowledge source definition.
Parameters:
Returns:
getKnowledgeSourceWithResponse
public Response<KnowledgeSource> getKnowledgeSourceWithResponse(String sourceName, Context context)
Retrieves a knowledge source definition.
Parameters:
Returns:
getSearchClient
public SearchClient getSearchClient(String indexName)
Initializes a new SearchClient using the given Index name and the same configuration as the SearchServiceClient.
Parameters:
Returns:
getServiceStatistics
public SearchServiceStatistics 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:
getServiceStatisticsWithResponse
public Response<SearchServiceStatistics> getServiceStatisticsWithResponse(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:
Returns:
getSynonymMap
public SynonymMap getSynonymMap(String synonymMapName)
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:
Returns:
getSynonymMapWithResponse
public Response<SynonymMap> getSynonymMapWithResponse(String synonymMapName, 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:
Returns:
listAliases
public PagedIterable<SearchAlias> listAliases()
Lists all aliases in the Azure AI Search service.
Code Sample
List aliases
SEARCH_INDEX_CLIENT.listAliases()
.forEach(searchAlias -> System.out.printf("Listed alias '%s' that aliases index '%s'.",
searchAlias.getName(), searchAlias.getIndexes().get(0)));
Returns:
listAliases
public PagedIterable<SearchAlias> listAliases(Context context)
Lists all aliases in the Azure AI Search service.
Code Sample
List aliases
SEARCH_INDEX_CLIENT.listAliases(new Context(KEY_1, VALUE_1))
.forEach(searchAlias -> System.out.printf("Listed alias '%s' that aliases index '%s'.",
searchAlias.getName(), searchAlias.getIndexes().get(0)));
Parameters:
Returns:
listIndexes
public PagedIterable<SearchIndex> 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:
listIndexes
public PagedIterable<SearchIndex> listIndexes(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:
Returns:
listIndexNames
public PagedIterable<String> 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:
listIndexNames
public PagedIterable<String> listIndexNames(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:
Returns:
listKnowledgeBases
public PagedIterable<KnowledgeBase> listKnowledgeBases()
Lists all knowledgebases available for a search service.
Returns:
listKnowledgeBases
public PagedIterable<KnowledgeBase> listKnowledgeBases(Context context)
Lists all knowledgebases available for a search service.
Parameters:
Returns:
listKnowledgeSources
public PagedIterable<KnowledgeSource> listKnowledgeSources()
Lists all knowledge sources available for a search service.
Returns:
listKnowledgeSources
public PagedIterable<KnowledgeSource> listKnowledgeSources(Context context)
Lists all knowledge sources available for a search service.
Parameters:
Returns:
listSynonymMapNames
public PagedIterable<String> 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:
listSynonymMapNames
public PagedIterable<String> listSynonymMapNames(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:
Returns:
listSynonymMaps
public PagedIterable<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:
listSynonymMaps
public PagedIterable<SynonymMap> listSynonymMaps(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:
Returns: