public final class SearchClientBuilder extends Object
SearchClients and SearchAsyncClients. Call buildClient and buildAsyncClient respectively to construct an instance of the desired client.
The following must be provided to construct a client instance.
AzureKeyCredential that grants access to the Azure Cognitive Search service.Instantiating an asynchronous Search Client
SearchAsyncClient searchAsyncClient = new SearchClientBuilder()
.credential(new AzureKeyCredential("{key}"))
.endpoint("{endpoint}")
.indexName("{indexName}")
.buildAsyncClient();
Instantiating a synchronous Search Client
SearchClient searchClient = new SearchClientBuilder()
.credential(new AzureKeyCredential("{key}"))
.endpoint("{endpoint}")
.indexName("{indexName}")
.buildClient();
SearchClient,
SearchAsyncClient| Constructor and Description |
|---|
SearchClientBuilder()
Creates a builder instance that is able to configure and construct
SearchClients and SearchAsyncClients. |
| Modifier and Type | Method and Description |
|---|---|
SearchClientBuilder |
addPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy)
Adds a pipeline policy to apply to each request sent.
|
SearchAsyncClient |
buildAsyncClient()
Creates a
SearchAsyncClient based on options set in the builder. |
SearchClient |
buildClient()
Creates a
SearchClient based on options set in the builder. |
SearchClientBuilder |
configuration(com.azure.core.util.Configuration configuration)
Sets the configuration store that is used during construction of the service client.
|
SearchClientBuilder |
credential(com.azure.core.credential.AzureKeyCredential credential)
Sets the
AzureKeyCredential used to authenticate HTTP requests. |
SearchClientBuilder |
endpoint(String endpoint)
Sets the service endpoint for the Azure Cognitive Search instance.
|
static com.azure.core.http.policy.HttpLogOptions |
getDefaultLogOptions()
Gets the default Azure Search headers and query parameters allow list.
|
SearchClientBuilder |
httpClient(com.azure.core.http.HttpClient client)
Sets the HTTP client to use for sending requests and receiving responses.
|
SearchClientBuilder |
httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)
Sets the logging configuration for HTTP requests and responses.
|
SearchClientBuilder |
indexName(String indexName)
Sets the name of the index.
|
SearchClientBuilder |
pipeline(com.azure.core.http.HttpPipeline httpPipeline)
Sets the HTTP pipeline to use for the service client.
|
SearchClientBuilder |
retryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)
Sets the
HttpPipelinePolicy that will attempt to retry requests when needed. |
SearchClientBuilder |
serializer(com.azure.core.util.serializer.JsonSerializer jsonSerializer)
Custom JSON serializer that is used to handle model types that are not contained in the Azure Search Documents
library.
|
SearchClientBuilder |
serviceVersion(SearchServiceVersion serviceVersion)
Sets the
SearchServiceVersion that is used when making API requests. |
public SearchClientBuilder()
SearchClients and SearchAsyncClients.public SearchClient buildClient()
SearchClient based on options set in the builder. Every time buildClient() is called a
new instance of SearchClient is created.
If pipeline is set, then only the pipeline, endpoint, and indexName are used to create the client. All other
builder settings are ignored.
NullPointerException - If indexName or endpoint are null.public SearchAsyncClient buildAsyncClient()
SearchAsyncClient based on options set in the builder. Every time buildAsyncClient() is
called a new instance of SearchAsyncClient is created.
If pipeline is set, then only the pipeline, endpoint, and indexName are used to create the client. All
other builder settings are ignored.
NullPointerException - If indexName or endpoint are null.public SearchClientBuilder endpoint(String endpoint)
endpoint - The URL of the Azure Cognitive Search instance.IllegalArgumentException - If endpoint is null or it cannot be parsed into a valid URL.public SearchClientBuilder credential(com.azure.core.credential.AzureKeyCredential credential)
AzureKeyCredential used to authenticate HTTP requests.credential - The AzureKeyCredential used to authenticate HTTP requests.NullPointerException - If credential is null.IllegalArgumentException - If AzureKeyCredential.getKey() is null or empty.public SearchClientBuilder indexName(String indexName)
indexName - Name of the index.IllegalArgumentException - If indexName is null or empty.public SearchClientBuilder httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)
If logging configurations aren't provided HTTP requests and responses won't be logged.
logOptions - The logging configuration for HTTP requests and responses.public static com.azure.core.http.policy.HttpLogOptions getDefaultLogOptions()
HttpLogOptions allow list.public SearchClientBuilder addPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy)
This method may be called multiple times, each time it is called the policy will be added to the end of added policy list. All policies will be added after the retry policy.
policy - The pipeline policies to added to the policy list.NullPointerException - If policy is null.public SearchClientBuilder serializer(com.azure.core.util.serializer.JsonSerializer jsonSerializer)
jsonSerializer - The serializer to serialize user defined models.public SearchClientBuilder httpClient(com.azure.core.http.HttpClient client)
client - The HTTP client that will handle sending requests and receiving responses.public SearchClientBuilder pipeline(com.azure.core.http.HttpPipeline httpPipeline)
If pipeline is set, all other settings are ignored, aside from endpoint and
index when building a SearchClient or SearchAsyncClient.
httpPipeline - The HTTP pipeline to use for sending service requests and receiving responses.public SearchClientBuilder configuration(com.azure.core.util.Configuration configuration)
The default configuration store is a clone of the global
configuration store, use Configuration.NONE to bypass using configuration settings during construction.
configuration - The configuration store that will be used.public SearchClientBuilder retryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)
HttpPipelinePolicy that will attempt to retry requests when needed.
A default retry policy will be supplied if one isn't provided.
retryPolicy - The RetryPolicy that will attempt to retry requests when needed.public SearchClientBuilder serviceVersion(SearchServiceVersion serviceVersion)
SearchServiceVersion that is used when making API requests.
If a service version is not provided, SearchServiceVersion.getLatest() will be used as a default. When
the default is used, updating to a newer client library may implicitly use a newer version of the service.
serviceVersion - The version of the service to be used when making requests.Copyright © 2020 Microsoft Corporation. All rights reserved.