public final class SearchIndexClient extends Object
SearchIndexClientBuilder
Modifier and Type | Method and Description |
---|---|
com.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 a
Class's Fields and Methods into SearchFields to help aid the creation of a SearchField which represents the Class . |
SearchIndex |
createIndex(SearchIndex index)
Creates a new Azure Cognitive Search index
|
com.azure.core.http.rest.Response<SearchIndex> |
createIndexWithResponse(SearchIndex index,
com.azure.core.util.Context context)
Creates a new Azure Cognitive Search index
|
SearchIndex |
createOrUpdateIndex(SearchIndex index)
Creates a new Azure Cognitive 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 Cognitive Search index or updates an index if it already exists.
|
SynonymMap |
createOrUpdateSynonymMap(SynonymMap synonymMap)
Creates a new Azure Cognitive 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 Cognitive Search synonym map or updates a synonym map if it already exists.
|
SynonymMap |
createSynonymMap(SynonymMap synonymMap)
Creates a new Azure Cognitive Search synonym map.
|
com.azure.core.http.rest.Response<SynonymMap> |
createSynonymMapWithResponse(SynonymMap synonymMap,
com.azure.core.util.Context context)
Creates a new Azure Cognitive Search synonym map.
|
void |
deleteIndex(String indexName)
Deletes an Azure Cognitive 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 Cognitive Search index and all the documents it contains.
|
void |
deleteSynonymMap(String synonymMapName)
Deletes an Azure Cognitive Search synonym map.
|
com.azure.core.http.rest.Response<Void> |
deleteSynonymMapWithResponse(SynonymMap synonymMap,
boolean onlyIfUnchanged,
com.azure.core.util.Context context)
Deletes an Azure Cognitive Search synonym map.
|
String |
getEndpoint()
Gets the endpoint for the Azure Cognitive Search service.
|
SearchIndex |
getIndex(String indexName)
Retrieves an index definition from the Azure Cognitive Search.
|
SearchIndexStatistics |
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.Response<SearchIndex> |
getIndexWithResponse(String indexName,
com.azure.core.util.Context context)
Retrieves an index definition from the Azure Cognitive Search.
|
SearchClient |
getSearchClient(String indexName)
Initializes a new
SearchClient using the given Index name and the same configuration as the
SearchServiceClient. |
SearchServiceStatistics |
getServiceStatistics()
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.
|
SynonymMap |
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> |
listIndexes()
Lists all indexes available for an Azure Cognitive Search service.
|
com.azure.core.http.rest.PagedIterable<SearchIndex> |
listIndexes(com.azure.core.util.Context context)
Lists all indexes available for an Azure Cognitive Search service.
|
com.azure.core.http.rest.PagedIterable<String> |
listIndexNames()
Lists all index names for an Azure Cognitive Search service.
|
com.azure.core.http.rest.PagedIterable<String> |
listIndexNames(com.azure.core.util.Context context)
Lists all indexes names for an Azure Cognitive Search service.
|
com.azure.core.http.rest.PagedIterable<String> |
listSynonymMapNames()
Lists all synonym maps names for an Azure Cognitive Search service.
|
com.azure.core.http.rest.PagedIterable<String> |
listSynonymMapNames(com.azure.core.util.Context context)
Lists all synonym maps names for an Azure Cognitive Search service.
|
com.azure.core.http.rest.PagedIterable<SynonymMap> |
listSynonymMaps()
Lists all synonym maps available for an Azure Cognitive Search service.
|
com.azure.core.http.rest.PagedIterable<SynonymMap> |
listSynonymMaps(com.azure.core.util.Context context)
Lists all synonym maps available for an Azure Cognitive Search service.
|
public String getEndpoint()
public SearchClient getSearchClient(String indexName)
SearchClient
using the given Index name and the same configuration as the
SearchServiceClient.indexName
- the name of the Index for the clientSearchClient
created from the service client configurationpublic SearchIndex createIndex(SearchIndex 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 = searchIndexClient.createIndex(searchIndex); System.out.printf("The index name is %s. The ETag of index is %s.%n", indexFromService.getName(), indexFromService.getETag());
index
- definition of the index to createpublic com.azure.core.http.rest.Response<SearchIndex> createIndexWithResponse(SearchIndex index, com.azure.core.util.Context context)
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 = searchIndexClient.createIndexWithResponse(searchIndex, new Context(key1, value1)); System.out.printf("The status code of the response is %s. The index name is %s.%n", indexFromServiceResponse.getStatusCode(), indexFromServiceResponse.getValue().getName());
index
- definition of the index to createcontext
- additional context that is passed through the HTTP pipeline during the service callpublic SearchIndex getIndex(String indexName)
Code Sample
Get search index with name "searchIndex".
SearchIndex indexFromService = searchIndexClient.getIndex("searchIndex"); System.out.printf("The index name is %s. The ETag of index is %s.%n", indexFromService.getName(), indexFromService.getETag());
indexName
- the name of the index to retrievepublic com.azure.core.http.rest.Response<SearchIndex> getIndexWithResponse(String indexName, com.azure.core.util.Context context)
Code Sample
Get search index with "searchIndex.
Response<SearchIndex> indexFromServiceResponse = searchIndexClient.getIndexWithResponse("searchIndex", new Context(key1, value1)); System.out.printf("The status code of the response is %s. The index name is %s.%n", indexFromServiceResponse.getStatusCode(), indexFromServiceResponse.getValue().getName());
indexName
- the name of the index to retrievecontext
- additional context that is passed through the HTTP pipeline during the service callpublic SearchIndexStatistics getIndexStatistics(String indexName)
Code Sample
Get search index "searchIndex" statistics.
SearchIndexStatistics statistics = searchIndexClient.getIndexStatistics("searchIndex"); System.out.printf("There are %d documents and storage size of %d available in 'searchIndex'.%n", statistics.getDocumentCount(), statistics.getStorageSize());
indexName
- the name of the index for which to retrieve statisticspublic com.azure.core.http.rest.Response<SearchIndexStatistics> getIndexStatisticsWithResponse(String indexName, com.azure.core.util.Context context)
Code Sample
Get search index "searchIndex" statistics.
Response<SearchIndexStatistics> statistics = searchIndexClient.getIndexStatisticsWithResponse("searchIndex", new Context(key1, value1)); 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());
indexName
- the name of the index for which to retrieve statisticscontext
- additional context that is passed through the HTTP pipeline during the service callpublic com.azure.core.http.rest.PagedIterable<SearchIndex> listIndexes()
Code Sample
List all search indexes.
PagedIterable<SearchIndex> indexes = searchIndexClient.listIndexes(); for (SearchIndex index: indexes) { System.out.printf("The index name is %s. The ETag of index is %s.%n", index.getName(), index.getETag()); }
public com.azure.core.http.rest.PagedIterable<SearchIndex> listIndexes(com.azure.core.util.Context context)
Code Sample
List all search indexes.
PagedIterable<SearchIndex> indexes = searchIndexClient.listIndexes(new Context(key1, value1)); 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()); }
context
- additional context that is passed through the HTTP pipeline during the service callpublic com.azure.core.http.rest.PagedIterable<String> listIndexNames()
Code Sample
List all search indexes names.
PagedIterable<String> indexes = searchIndexClient.listIndexNames(); for (String indexName: indexes) { System.out.printf("The index name is %s.%n", indexName); }
public com.azure.core.http.rest.PagedIterable<String> listIndexNames(com.azure.core.util.Context context)
Code Sample
List all search indexes names.
PagedIterable<String> indexes = searchIndexClient.listIndexNames(new Context(key1, value1)); 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); }
context
- additional context that is passed through the HTTP pipeline during the service callpublic SearchIndex createOrUpdateIndex(SearchIndex index)
Code Sample
Create or update search index named "searchIndex".
SearchIndex indexFromService = searchIndexClient.getIndex("searchIndex"); indexFromService.setSuggesters(Collections.singletonList(new SearchSuggester("sg", Collections.singletonList("hotelName")))); SearchIndex updatedIndex = searchIndexClient.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());
index
- the definition of the index to create or updatepublic com.azure.core.http.rest.Response<SearchIndex> createOrUpdateIndexWithResponse(SearchIndex index, boolean allowIndexDowntime, boolean onlyIfUnchanged, com.azure.core.util.Context context)
Code Sample
Create or update search index named "searchIndex".
SearchIndex indexFromService = searchIndexClient.getIndex("searchIndex"); indexFromService.setSuggesters(Collections.singletonList(new SearchSuggester("sg", Collections.singletonList("hotelName")))); Response<SearchIndex> updatedIndexResponse = searchIndexClient.createOrUpdateIndexWithResponse(indexFromService, true, false, new Context(key1, value1)); 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());
index
- the SearchIndex
to 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
- true
to update if the index
is the same as the current service value.
false
to always update existing value.context
- additional context that is passed through the HTTP pipeline during the service callpublic void deleteIndex(String indexName)
Code Sample
Delete search index with name "searchIndex".
searchIndexClient.deleteIndex("searchIndex");
indexName
- the name of the index to deletepublic com.azure.core.http.rest.Response<Void> deleteIndexWithResponse(SearchIndex index, boolean onlyIfUnchanged, com.azure.core.util.Context context)
Code Sample
Delete search index with name "searchIndex".
SearchIndex indexFromService = searchIndexClient.getIndex("searchIndex"); Response<Void> deleteResponse = searchIndexClient.deleteIndexWithResponse(indexFromService, true, new Context(key1, value1)); System.out.printf("The status code of the response is %d.%n", deleteResponse.getStatusCode());
index
- the Search SearchIndex
to delete.onlyIfUnchanged
- true
to delete if the index
is the same as the current service value.
false
to always delete existing value.context
- additional context that is passed through the Http pipeline during the service callpublic com.azure.core.http.rest.PagedIterable<AnalyzedTokenInfo> analyzeText(String indexName, AnalyzeTextOptions analyzeTextOptions)
Code Sample
Analyzer text with LexicalTokenizerName "Classic" in search index "searchIndex".
PagedIterable<AnalyzedTokenInfo> tokenInfos = searchIndexClient.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()); }
indexName
- the name of the index for which to test an analyzeranalyzeTextOptions
- the text and analyzer or analysis components to test. Requires to provide either LexicalTokenizerName
or LexicalAnalyzerName
.public com.azure.core.http.rest.PagedIterable<AnalyzedTokenInfo> analyzeText(String indexName, AnalyzeTextOptions analyzeTextOptions, com.azure.core.util.Context context)
Code Sample
Analyzer text response with LexicalTokenizerName "Classic" in search index "searchIndex".
PagedIterable<AnalyzedTokenInfo> tokenInfos = searchIndexClient.analyzeText("searchIndex", new AnalyzeTextOptions("The quick brown fox", LexicalTokenizerName.CLASSIC), new Context(key1, value1)); 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()); }
indexName
- the name of the index for which to test an analyzeranalyzeTextOptions
- the text and analyzer or analysis components to test. Requires to provide either LexicalTokenizerName
or LexicalAnalyzerName
.context
- additional context that is passed through the HTTP pipeline during the service callpublic SynonymMap createSynonymMap(SynonymMap synonymMap)
Code Sample
Create synonym map named "synonymMap".
SynonymMap synonymMap = new SynonymMap("synonymMap", "United States, United States of America, USA\nWashington, Wash. => WA"); SynonymMap synonymMapFromService = searchIndexClient.createSynonymMap(synonymMap); System.out.printf("The synonym map name is %s. The ETag of synonym map is %s.%n", synonymMapFromService.getName(), synonymMapFromService.getETag());
synonymMap
- the definition of the synonym map to createSynonymMap
.public com.azure.core.http.rest.Response<SynonymMap> createSynonymMapWithResponse(SynonymMap synonymMap, com.azure.core.util.Context context)
Code Sample
Create synonym map named "synonymMap".
synonymMap
- the definition of the synonym map to createcontext
- additional context that is passed through the HTTP pipeline during the service callpublic SynonymMap getSynonymMap(String synonymMapName)
Code Sample
Get synonym map with name "synonymMap".
SynonymMap synonymMapFromService = searchIndexClient.getSynonymMap("synonymMap"); System.out.printf("The synonym map is %s. The ETag of synonym map is %s.%n", synonymMapFromService.getName(), synonymMapFromService.getETag());
synonymMapName
- name of the synonym map to retrieveSynonymMap
definitionpublic com.azure.core.http.rest.Response<SynonymMap> getSynonymMapWithResponse(String synonymMapName, com.azure.core.util.Context context)
Code Sample
Get synonym map with name "synonymMap".
Response<SynonymMap> synonymMapFromService = searchIndexClient.getSynonymMapWithResponse("synonymMap", new Context(key1, value1)); 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());
synonymMapName
- name of the synonym map to retrievecontext
- a context that is passed through the HTTP pipeline during the service callpublic com.azure.core.http.rest.PagedIterable<SynonymMap> listSynonymMaps()
Code Sample
List all synonym maps.
PagedIterable<SynonymMap> synonymMaps = searchIndexClient.listSynonymMaps(); for (SynonymMap synonymMap: synonymMaps) { System.out.printf("The synonymMap name is %s. The ETag of synonymMap is %s.%n", synonymMap.getName(), synonymMap.getETag()); }
public com.azure.core.http.rest.PagedIterable<SynonymMap> listSynonymMaps(com.azure.core.util.Context context)
Code Sample
List all synonym maps.
PagedIterable<SynonymMap> synonymMaps = searchIndexClient.listSynonymMaps(new Context(key1, value1)); 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()); }
context
- additional context that is passed through the HTTP pipeline during the service callpublic com.azure.core.http.rest.PagedIterable<String> listSynonymMapNames()
Code Sample
List all synonym map names.
PagedIterable<String> synonymMaps = searchIndexClient.listSynonymMapNames(); for (String synonymMap: synonymMaps) { System.out.printf("The synonymMap name is %s.%n", synonymMap); }
public com.azure.core.http.rest.PagedIterable<String> listSynonymMapNames(com.azure.core.util.Context context)
Code Sample
List all synonym map names.
PagedIterable<String> synonymMaps = searchIndexClient.listIndexNames(new Context(key1, value1)); 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); }
context
- additional context that is passed through the HTTP pipeline during the service callpublic SynonymMap createOrUpdateSynonymMap(SynonymMap synonymMap)
Code Sample
Create or update synonym map named "synonymMap".
SynonymMap synonymMap = searchIndexClient.getSynonymMap("searchIndex"); synonymMap.setSynonyms("United States, United States of America, USA, America\nWashington, Wash. => WA"); SynonymMap updatedSynonymMap = searchIndexClient.createOrUpdateSynonymMap(synonymMap); System.out.printf("The synonym map name is %s. The synonyms are %s.%n", updatedSynonymMap.getName(), updatedSynonymMap.getSynonyms());
synonymMap
- the definition of the synonym map to create or updatepublic com.azure.core.http.rest.Response<SynonymMap> createOrUpdateSynonymMapWithResponse(SynonymMap synonymMap, boolean onlyIfUnchanged, com.azure.core.util.Context context)
Code Sample
Create or update synonym map named "synonymMap".
SynonymMap synonymMap = searchIndexClient.getSynonymMap("searchIndex"); synonymMap.setSynonyms("United States, United States of America, USA, America\nWashington, Wash. => WA"); Response<SynonymMap> updatedSynonymMap = searchIndexClient.createOrUpdateSynonymMapWithResponse(synonymMap, true, new Context(key1, value1)); 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());
synonymMap
- the definition of the synonym map to create or updateonlyIfUnchanged
- true
to update if the synonymMap
is the same as the current service value.
false
to always update existing value.context
- additional context that is passed through the HTTP pipeline during the service callpublic void deleteSynonymMap(String synonymMapName)
Code Sample
Delete synonym map with name "synonymMap".
searchIndexClient.deleteSynonymMap("synonymMap");
synonymMapName
- the name of the synonym map to deletepublic com.azure.core.http.rest.Response<Void> deleteSynonymMapWithResponse(SynonymMap synonymMap, boolean onlyIfUnchanged, com.azure.core.util.Context context)
Code Sample
Delete synonym map with name "synonymMap".
SynonymMap synonymMap = searchIndexClient.getSynonymMap("synonymMap"); Response<Void> response = searchIndexClient.deleteSynonymMapWithResponse(synonymMap, true, new Context(key1, value1)); System.out.println("The status code of the response is" + response.getStatusCode());
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.context
- additional context that is passed through the Http pipeline during the service callpublic SearchServiceStatistics getServiceStatistics()
Code Sample
Get service statistics.
SearchServiceStatistics serviceStatistics = searchIndexClient.getServiceStatistics(); System.out.printf("There are %s search indexes in your service.%n", serviceStatistics.getCounters().getIndexCounter());
public com.azure.core.http.rest.Response<SearchServiceStatistics> getServiceStatisticsWithResponse(com.azure.core.util.Context context)
Code Sample
Get service statistics.
Response<SearchServiceStatistics> serviceStatistics = searchIndexClient.getServiceStatisticsWithResponse(new Context(key1, value1)); 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());
context
- additional context that is passed through the HTTP pipeline during the service callpublic static List<SearchField> buildSearchFields(Class<?> model, FieldBuilderOptions options)
Class's
Fields
and Methods
into SearchFields
to help aid the creation of a SearchField
which represents the Class
.model
- The model Class
that will have SearchFields
generated from its
structure.options
- Configuration used to determine generation of the SearchFields
.SearchFields
which represent the model Class
.Copyright © 2021 Microsoft Corporation. All rights reserved.