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 Cognitive Search service.
Method Summary
Modifier and Type | Method and Description |
---|---|
Paged |
analyzeText(String indexName, AnalyzeTextOptions analyzeTextOptions)
Shows how an analyzer breaks text into tokens. |
Paged |
analyzeText(String indexName, AnalyzeTextOptions analyzeTextOptions, Context context)
Shows how an analyzer breaks text into tokens. |
static
List<Search |
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. |
Search |
createIndex(SearchIndex index)
Creates a new Azure Cognitive Search index |
Response<Search |
createIndexWithResponse(SearchIndex index, Context context)
Creates a new Azure Cognitive Search index |
Search |
createOrUpdateIndex(SearchIndex index)
Creates a new Azure Cognitive Search index or updates an index if it already exists. |
Response<Search |
createOrUpdateIndexWithResponse(SearchIndex index, boolean allowIndexDowntime, boolean onlyIfUnchanged, Context context)
Creates a new Azure Cognitive Search index or updates an index if it already exists. |
Synonym |
createOrUpdateSynonymMap(SynonymMap synonymMap)
Creates a new Azure Cognitive Search synonym map or updates a synonym map if it already exists. |
Response<Synonym |
createOrUpdateSynonymMapWithResponse(SynonymMap synonymMap, boolean onlyIfUnchanged, Context context)
Creates a new Azure Cognitive Search synonym map or updates a synonym map if it already exists. |
Synonym |
createSynonymMap(SynonymMap synonymMap)
Creates a new Azure Cognitive Search synonym map. |
Response<Synonym |
createSynonymMapWithResponse(SynonymMap synonymMap, 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. |
Response<Void> |
deleteIndexWithResponse(SearchIndex index, boolean onlyIfUnchanged, 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. |
Response<Void> |
deleteSynonymMapWithResponse(SynonymMap synonymMap, boolean onlyIfUnchanged, Context context)
Deletes an Azure Cognitive Search synonym map. |
String |
getEndpoint()
Gets the endpoint for the Azure Cognitive Search service. |
Search |
getIndex(String indexName)
Retrieves an index definition from the Azure Cognitive Search. |
Search |
getIndexStatistics(String indexName)
Returns statistics for the given index, including a document count and storage usage. |
Response<Search |
getIndexStatisticsWithResponse(String indexName, Context context)
Returns statistics for the given index, including a document count and storage usage. |
Response<Search |
getIndexWithResponse(String indexName, Context context)
Retrieves an index definition from the Azure Cognitive Search. |
Search |
getSearchClient(String indexName)
Initializes a new SearchClient using the given Index name and the same configuration as the Search |
Search |
getServiceStatistics()
Returns service level statistics for a search service, including service counters and limits. |
Response<Search |
getServiceStatisticsWithResponse(Context context)
Returns service level statistics for a search service, including service counters and limits. |
Synonym |
getSynonymMap(String synonymMapName)
Retrieves a synonym map definition. |
Response<Synonym |
getSynonymMapWithResponse(String synonymMapName, Context context)
Retrieves a synonym map definition. |
Paged |
listIndexNames()
Lists all index names for an Azure Cognitive Search service. |
Paged |
listIndexNames(Context context)
Lists all indexes names for an Azure Cognitive Search service. |
Paged |
listIndexes()
Lists all indexes available for an Azure Cognitive Search service. |
Paged |
listIndexes(Context context)
Lists all indexes available for an Azure Cognitive Search service. |
Paged |
listSynonymMapNames()
Lists all synonym maps names for an Azure Cognitive Search service. |
Paged |
listSynonymMapNames(Context context)
Lists all synonym maps names for an Azure Cognitive Search service. |
Paged |
listSynonymMaps()
Lists all synonym maps available for an Azure Cognitive Search service. |
Paged |
listSynonymMaps(Context context)
Lists all synonym maps available for an Azure Cognitive Search service. |
Methods inherited from java.lang.Object
Method Details
analyzeText
public PagedIterable
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
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
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:
createIndex
public SearchIndex createIndex(SearchIndex index)
Creates a new Azure Cognitive 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
Creates a new Azure Cognitive 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:
createOrUpdateIndex
public SearchIndex createOrUpdateIndex(SearchIndex index)
Creates a new Azure Cognitive 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
Creates a new Azure Cognitive 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:
createOrUpdateSynonymMap
public SynonymMap createOrUpdateSynonymMap(SynonymMap synonymMap)
Creates a new Azure Cognitive 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("searchIndex");
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
Creates a new Azure Cognitive 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("searchIndex");
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 Cognitive 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
Creates a new Azure Cognitive 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:
deleteIndex
public void deleteIndex(String indexName)
Deletes an Azure Cognitive 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
Deletes an Azure Cognitive 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:
deleteSynonymMap
public void deleteSynonymMap(String synonymMapName)
Deletes an Azure Cognitive Search synonym map.
Code Sample
Delete synonym map with name "synonymMap".
SEARCH_INDEX_CLIENT.deleteSynonymMap("synonymMap");
Parameters:
deleteSynonymMapWithResponse
public Response
Deletes an Azure Cognitive 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:
getEndpoint
public String getEndpoint()
Gets the endpoint for the Azure Cognitive Search service.
Returns:
getIndex
public SearchIndex getIndex(String indexName)
Retrieves an index definition from the Azure Cognitive 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
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:
getIndexWithResponse
public Response
Retrieves an index definition from the Azure Cognitive 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:
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
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
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:
listIndexNames
public PagedIterable
Lists all index names for an Azure Cognitive 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
Lists all indexes names for an Azure Cognitive 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:
listIndexes
public PagedIterable
Lists all indexes available for an Azure Cognitive 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
Lists all indexes available for an Azure Cognitive 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:
listSynonymMapNames
public PagedIterable
Lists all synonym maps names for an Azure Cognitive 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
Lists all synonym maps names for an Azure Cognitive 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
Lists all synonym maps available for an Azure Cognitive 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
Lists all synonym maps available for an Azure Cognitive 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:
Applies to
Azure SDK for Java
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour