SearchIndexAsyncClient Class
- java.
lang. Object - com.
azure. search. documents. indexes. SearchIndexAsyncClient
- com.
public final class SearchIndexAsyncClient
This class provides a client that contains the operations for creating, getting, listing, updating, or deleting indexes or synonym map and analyzing text in an Azure 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. |
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. |
Mono<Search |
createIndex(SearchIndex index)
Creates a new Azure Cognitive Search index. |
Mono<Response<Search |
createIndexWithResponse(SearchIndex index)
Creates a new Azure Cognitive Search index. |
Mono<Search |
createOrUpdateIndex(SearchIndex index)
Creates a new Azure Cognitive Search index or updates an index if it already exists. |
Mono<Response<Search |
createOrUpdateIndexWithResponse(SearchIndex index, boolean allowIndexDowntime, boolean onlyIfUnchanged)
Creates a new Azure Cognitive Search index or updates an index if it already exists. |
Mono<Synonym |
createOrUpdateSynonymMap(SynonymMap synonymMap)
Creates a new Azure Cognitive Search synonym map or updates a synonym map if it already exists. |
Mono<Response<Synonym |
createOrUpdateSynonymMapWithResponse(SynonymMap synonymMap, boolean onlyIfUnchanged)
Creates a new Azure Cognitive Search synonym map or updates a synonym map if it already exists. |
Mono<Synonym |
createSynonymMap(SynonymMap synonymMap)
Creates a new Azure Cognitive Search synonym map. |
Mono<Response<Synonym |
createSynonymMapWithResponse(SynonymMap synonymMap)
Creates a new Azure Cognitive Search synonym map. |
Mono<Void> |
deleteIndex(String indexName)
Deletes an Azure Cognitive Search index and all the documents it contains. |
Mono<Response<Void>> |
deleteIndexWithResponse(SearchIndex index, boolean onlyIfUnchanged)
Deletes an Azure Cognitive Search index and all the documents it contains. |
Mono<Void> |
deleteSynonymMap(String synonymMapName)
Deletes an Azure Cognitive Search synonym map. |
Mono<Response<Void>> |
deleteSynonymMapWithResponse(SynonymMap synonymMap, boolean onlyIfUnchanged)
Deletes an Azure Cognitive Search synonym map. |
String |
getEndpoint()
Gets the endpoint for the Azure Cognitive Search service. |
Mono<Search |
getIndex(String indexName)
Retrieves an index definition from the Azure Cognitive Search. |
Mono<Search |
getIndexStatistics(String indexName)
Returns statistics for the given index, including a document count and storage usage. |
Mono<Response<Search |
getIndexStatisticsWithResponse(String indexName)
Returns statistics for the given index, including a document count and storage usage. |
Mono<Response<Search |
getIndexWithResponse(String indexName)
Retrieves an index definition from the Azure Cognitive Search. |
Search |
getSearchAsyncClient(String indexName)
Initializes a new SearchAsyncClient using the given Index name and the same configuration as the Search |
Mono<Search |
getServiceStatistics()
Returns service level statistics for a search service, including service counters and limits. |
Mono<Response<Search |
getServiceStatisticsWithResponse()
Returns service level statistics for a search service, including service counters and limits. |
Mono<Synonym |
getSynonymMap(String synonymMapName)
Retrieves a synonym map definition. |
Mono<Response<Synonym |
getSynonymMapWithResponse(String synonymMapName)
Retrieves a synonym map definition. |
Paged |
listIndexNames()
Lists all indexes names for an Azure Cognitive Search service. |
Paged |
listIndexes()
Lists all indexes available for an Azure Cognitive Search service. |
Paged |
listSynonymMapNames()
Lists all synonym map names for an Azure Cognitive Search service. |
Paged |
listSynonymMaps()
Lists all synonym maps available for an Azure Cognitive Search service. |
Methods inherited from java.lang.Object
Method Details
analyzeText
public PagedFlux
Shows how an analyzer breaks text into tokens.
Code Sample
Analyzer text with LexicalTokenizerName "Classic" in search index "searchIndex".
SEARCH_INDEX_ASYNC_CLIENT.analyzeText("searchIndex",
new AnalyzeTextOptions("The quick brown fox", LexicalTokenizerName.CLASSIC))
.subscribe(tokenInfo ->
System.out.printf("The token emitted by the analyzer is %s.%n", tokenInfo.getToken()));
Parameters:
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 Mono
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);
SEARCH_INDEX_ASYNC_CLIENT.createIndex(searchIndex)
.subscribe(indexFromService ->
System.out.printf("The index name is %s. The ETag of index is %s.%n", indexFromService.getName(),
indexFromService.getETag()));
Parameters:
Returns:
createIndexWithResponse
public Mono<>
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);
SEARCH_INDEX_ASYNC_CLIENT.createIndexWithResponse(searchIndex)
.subscribe(indexFromServiceResponse ->
System.out.printf("The status code of the response is %s. The index name is %s.%n",
indexFromServiceResponse.getStatusCode(), indexFromServiceResponse.getValue().getName()));
Parameters:
Returns:
createOrUpdateIndex
public Mono
Creates a new Azure Cognitive Search index or updates an index if it already exists.
Code Sample
Create or update search index named "searchIndex".
SEARCH_INDEX_ASYNC_CLIENT.getIndex("searchIndex")
.doOnNext(indexFromService -> indexFromService.setSuggesters(Collections.singletonList(
new SearchSuggester("sg", Collections.singletonList("hotelName")))))
.flatMap(SEARCH_INDEX_ASYNC_CLIENT::createOrUpdateIndex)
.subscribe(updatedIndex ->
System.out.printf("The index name is %s. The suggester name of index is %s.%n",
updatedIndex.getName(), updatedIndex.getSuggesters().get(0).getName()));
Parameters:
Returns:
createOrUpdateIndexWithResponse
public Mono<>
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 Mono
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".
SEARCH_INDEX_ASYNC_CLIENT.getSynonymMap("searchIndex")
.doOnNext(synonymMap -> synonymMap
.setSynonyms("United States, United States of America, USA, America\nWashington, Wash. => WA"))
.flatMap(SEARCH_INDEX_ASYNC_CLIENT::createOrUpdateSynonymMap)
.subscribe(updatedSynonymMap ->
System.out.printf("The synonym map name is %s. The synonyms are %s.%n", updatedSynonymMap.getName(),
updatedSynonymMap.getSynonyms()));
Parameters:
Returns:
createOrUpdateSynonymMapWithResponse
public Mono<>
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".
SEARCH_INDEX_ASYNC_CLIENT.getSynonymMap("searchIndex")
.flatMap(synonymMap -> {
synonymMap.setSynonyms(
"United States, United States of America, USA, America\nWashington, Wash. => WA");
return SEARCH_INDEX_ASYNC_CLIENT.createOrUpdateSynonymMapWithResponse(synonymMap, true);
})
.subscribe(updatedSynonymMap ->
System.out.printf("The status code of the normal response is %s.%n"
+ "The synonym map name is %s. The synonyms are %s.%n", updatedSynonymMap.getStatusCode(),
updatedSynonymMap.getValue().getName(), updatedSynonymMap.getValue().getSynonyms()));
Parameters:
true
to update if the synonymMap
is the same as the current service value.
false
to always update existing value.
Returns:
createSynonymMap
public Mono
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");
SEARCH_INDEX_ASYNC_CLIENT.createSynonymMap(synonymMap)
.subscribe(synonymMapFromService ->
System.out.printf("The synonym map name is %s. The ETag of synonym map is %s.%n",
synonymMapFromService.getName(), synonymMapFromService.getETag()));
Parameters:
Returns:
createSynonymMapWithResponse
public Mono<>
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");
SEARCH_INDEX_ASYNC_CLIENT.createSynonymMapWithResponse(synonymMap)
.subscribe(synonymMapFromService ->
System.out.printf("The status code of the response is %d.%n"
+ "The synonym map name is %s. The ETag of synonym map is %s.%n",
synonymMapFromService.getStatusCode(),
synonymMapFromService.getValue().getName(), synonymMapFromService.getValue().getETag()));
Parameters:
Returns:
deleteIndex
public Mono
Deletes an Azure Cognitive Search index and all the documents it contains.
Code Sample
Delete search index with name "searchIndex".
SEARCH_INDEX_ASYNC_CLIENT.deleteIndex("searchIndex")
.subscribe();
Parameters:
Returns:
deleteIndexWithResponse
public Mono<>
Deletes an Azure Cognitive Search index and all the documents it contains.
Code Sample
Delete search index with name "searchIndex".
SEARCH_INDEX_ASYNC_CLIENT.getIndex("searchIndex")
.flatMap(indexFromService -> SEARCH_INDEX_ASYNC_CLIENT.deleteIndexWithResponse(indexFromService, true))
.subscribe(deleteResponse ->
System.out.printf("The status code of the response is %d.%n", deleteResponse.getStatusCode()));
Parameters:
true
to delete if the index
is the same as the current service value.
false
to always delete existing value.
Returns:
deleteSynonymMap
public Mono
Deletes an Azure Cognitive Search synonym map.
Code Sample
Delete synonym map with name "synonymMap".
SEARCH_INDEX_ASYNC_CLIENT.deleteSynonymMap("synonymMap")
.subscribe();
Parameters:
Returns:
deleteSynonymMapWithResponse
public Mono<>
Deletes an Azure Cognitive Search synonym map.
Code Sample
Delete synonym map with name "synonymMap".
SEARCH_INDEX_ASYNC_CLIENT.getSynonymMap("synonymMap")
.flatMap(synonymMap -> SEARCH_INDEX_ASYNC_CLIENT.deleteSynonymMapWithResponse(synonymMap, true))
.subscribe(response -> System.out.println("The status code of the response is" + response.getStatusCode()));
Parameters:
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 Mono
Retrieves an index definition from the Azure Cognitive Search.
Code Sample
Get search index with name "searchIndex".
SEARCH_INDEX_ASYNC_CLIENT.getIndex("searchIndex")
.subscribe(indexFromService ->
System.out.printf("The index name is %s. The ETag of index is %s.%n", indexFromService.getName(),
indexFromService.getETag()));
Parameters:
Returns:
getIndexStatistics
public Mono
Returns statistics for the given index, including a document count and storage usage.
Code Sample
Get search index "searchIndex" statistics.
SEARCH_INDEX_ASYNC_CLIENT.getIndexStatistics("searchIndex")
.subscribe(statistics ->
System.out.printf("There are %d documents and storage size of %d available in 'searchIndex'.%n",
statistics.getDocumentCount(), statistics.getStorageSize()));
Parameters:
Returns:
getIndexStatisticsWithResponse
public Mono<>
Returns statistics for the given index, including a document count and storage usage.
Code Sample
Get search index "searchIndex" statistics.
SEARCH_INDEX_ASYNC_CLIENT.getIndexStatisticsWithResponse("searchIndex")
.subscribe(statistics -> System.out.printf("The status code of the response is %s.%n"
+ "There are %d documents and storage size of %d available in 'searchIndex'.%n",
statistics.getStatusCode(), statistics.getValue().getDocumentCount(),
statistics.getValue().getStorageSize()));
Parameters:
Returns:
getIndexWithResponse
public Mono<>
Retrieves an index definition from the Azure Cognitive Search.
Code Sample
Get search index with "searchIndex.
SEARCH_INDEX_ASYNC_CLIENT.getIndexWithResponse("searchIndex")
.subscribe(indexFromServiceResponse ->
System.out.printf("The status code of the response is %s. The index name is %s.%n",
indexFromServiceResponse.getStatusCode(), indexFromServiceResponse.getValue().getName()));
Parameters:
Returns:
getSearchAsyncClient
public SearchAsyncClient getSearchAsyncClient(String indexName)
Initializes a new SearchAsyncClient using the given Index name and the same configuration as the SearchServiceAsyncClient.
Parameters:
Returns:
getServiceStatistics
public Mono
Returns service level statistics for a search service, including service counters and limits.
Contains the tracking ID sent with the request to help with debugging
Code Sample
Get service statistics.
SEARCH_INDEX_ASYNC_CLIENT.getServiceStatistics()
.subscribe(serviceStatistics -> System.out.printf("There are %s search indexes in your service.%n",
serviceStatistics.getCounters().getIndexCounter()));
Returns:
getServiceStatisticsWithResponse
public Mono<>
Returns service level statistics for a search service, including service counters and limits.
Code Sample
Get service statistics.
SEARCH_INDEX_ASYNC_CLIENT.getServiceStatisticsWithResponse()
.subscribe(serviceStatistics ->
System.out.printf("The status code of the response is %s.%n"
+ "There are %s search indexes in your service.%n",
serviceStatistics.getStatusCode(),
serviceStatistics.getValue().getCounters().getIndexCounter()));
Returns:
getSynonymMap
public Mono
Retrieves a synonym map definition.
Code Sample
Get synonym map with name "synonymMap".
SEARCH_INDEX_ASYNC_CLIENT.getSynonymMap("synonymMap")
.subscribe(synonymMapFromService ->
System.out.printf("The synonym map is %s. The ETag of synonym map is %s.%n",
synonymMapFromService.getName(), synonymMapFromService.getETag()));
Parameters:
Returns:
getSynonymMapWithResponse
public Mono<>
Retrieves a synonym map definition.
Code Sample
Get synonym map with name "synonymMap".
SEARCH_INDEX_ASYNC_CLIENT.getSynonymMap("synonymMap")
.subscribe(synonymMapFromService ->
System.out.printf("The synonym map is %s. The ETag of synonym map is %s.%n",
synonymMapFromService.getName(), synonymMapFromService.getETag()));
Parameters:
Returns:
listIndexNames
public PagedFlux
Lists all indexes names for an Azure Cognitive Search service.
Code Sample
List all search indexes names.
SEARCH_INDEX_ASYNC_CLIENT.listIndexNames()
.subscribe(indexName -> System.out.printf("The index name is %s.%n", indexName));
Returns:
listIndexes
public PagedFlux
Lists all indexes available for an Azure Cognitive Search service.
Code Sample
List all search indexes.
SEARCH_INDEX_ASYNC_CLIENT.listIndexes()
.subscribe(index ->
System.out.printf("The index name is %s. The ETag of index is %s.%n", index.getName(),
index.getETag()));
Returns:
listSynonymMapNames
public PagedFlux
Lists all synonym map names for an Azure Cognitive Search service.
Code Sample
List all synonym map names.
SEARCH_INDEX_ASYNC_CLIENT.listSynonymMapNames()
.subscribe(synonymMap -> System.out.printf("The synonymMap name is %s.%n", synonymMap));
Returns:
listSynonymMaps
public PagedFlux
Lists all synonym maps available for an Azure Cognitive Search service.
Code Sample
List all synonym maps.
SEARCH_INDEX_ASYNC_CLIENT.listSynonymMaps()
.subscribe(synonymMap -> System.out.printf("The synonymMap name is %s. The ETag of synonymMap is %s.%n",
synonymMap.getName(), synonymMap.getETag()));
Returns:
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