SearchClient Class

  • java.lang.Object
    • com.azure.search.documents.SearchClient

public final class SearchClient

Initializes a new instance of the synchronous SearchClient type.

Method Summary

Modifier and Type Method and Description
AutocompleteResult autocomplete(AutocompleteOptions options)

Autocompletes incomplete query terms based on input text and matching terms in the index.

Response<AutocompleteResult> autocompleteWithResponse(AutocompleteOptions options, RequestOptions requestOptions)

Autocompletes incomplete query terms based on input text and matching terms in the index.

LookupDocument getDocument(String key)

Retrieves a document from the index.

LookupDocument getDocument(String key, List<String> selectedFields)

Retrieves a document from the index.

long getDocumentCount()

Queries the number of documents in the index.

Response<Long> getDocumentCountWithResponse(RequestOptions requestOptions)

Queries the number of documents in the index.

Response<LookupDocument> getDocumentWithResponse(String key, RequestOptions requestOptions)

Retrieves a document from the index.

String getEndpoint()

Gets the endpoint used to communicate with the Azure AI Search service.

String getIndexName()

Gets the name of the Azure AI Search index.

SearchServiceVersion getServiceVersion()

Gets the SearchServiceVersion used to communicate with the Azure AI Search service.

IndexDocumentsResult indexDocuments(IndexDocumentsBatch batch)

Sends a batch of document write actions to the index.

Response<IndexDocumentsResult> indexDocumentsWithResponse(IndexDocumentsBatch batch, IndexDocumentsOptions options, RequestOptions requestOptions)

Sends a batch of document write actions to the index.

SearchPagedIterable search(SearchOptions options)

Searches for documents in the Azure AI Search index.

SearchPagedIterable search(SearchOptions options, RequestOptions requestOptions)

Searches for documents in the Azure AI Search index.

SuggestDocumentsResult suggest(SuggestOptions options)

Suggests documents in the index that match the given partial query text.

Response<SuggestDocumentsResult> suggestWithResponse(SuggestOptions options, RequestOptions requestOptions)

Suggests documents in the index that match the given partial query text.

Methods inherited from java.lang.Object

Method Details

autocomplete

public AutocompleteResult autocomplete(AutocompleteOptions options)

Autocompletes incomplete query terms based on input text and matching terms in the index.

Parameters:

options - Options for autocomplete API.

Returns:

the result of Autocomplete query.

autocompleteWithResponse

public Response<AutocompleteResult> autocompleteWithResponse(AutocompleteOptions options, RequestOptions requestOptions)

Autocompletes incomplete query terms based on input text and matching terms in the index.

Parameters:

options - Options for autocomplete API.
requestOptions - The options to configure the HTTP request before HTTP client sends it.

Returns:

the result of Autocomplete query along with Response<T>.

getDocument

public LookupDocument getDocument(String key)

Retrieves a document from the index.

Parameters:

key - The key of the document to retrieve.

Returns:

a document retrieved via a document lookup operation.

getDocument

public LookupDocument getDocument(String key, List<String> selectedFields)

Retrieves a document from the index.

Parameters:

key - The key of the document to retrieve.
selectedFields - List of field names to retrieve for the document; Any field not retrieved will be missing from the returned document.

Returns:

a document retrieved via a document lookup operation.

getDocumentCount

public long getDocumentCount()

Queries the number of documents in the index.

Returns:

a 64-bit integer.

getDocumentCountWithResponse

public Response<Long> getDocumentCountWithResponse(RequestOptions requestOptions)

Queries the number of documents in the index.

Parameters:

requestOptions - The options to configure the HTTP request before HTTP client sends it.

Returns:

a 64-bit integer along with Response<T>.

getDocumentWithResponse

public Response<LookupDocument> getDocumentWithResponse(String key, RequestOptions requestOptions)

Retrieves a document from the index.

Query Parameters

| ------- | ------------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Name    | Type         | Required | Description                                                                                                                                                |
| $select | List<String> | No       | List of field names to retrieve for the document; Any field not retrieved will be missing from the returned document. In the form of "," separated string. |

You can add these to a request with RequestOptions#addQueryParam

Header Parameters

| ------------------------------- | ------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| Name                            | Type    | Required | Description                                                                                                                         |
| x-ms-query-source-authorization | String  | No       | Token identifying the user for which the query is being executed. This token is used to enforce security restrictions on documents. |
| x-ms-enable-elevated-read       | Boolean | No       | A value that enables elevated read that bypass document level permission checks for the query operation.                            |

You can add these to a request with RequestOptions#addHeader

Parameters:

key - The key of the document to retrieve.
requestOptions - The options to configure the HTTP request before HTTP client sends it.

Returns:

a document retrieved via a document lookup operation along with Response<T>.

getEndpoint

public String getEndpoint()

Gets the endpoint used to communicate with the Azure AI Search service.

Returns:

The endpoint.

getIndexName

public String getIndexName()

Gets the name of the Azure AI Search index.

Returns:

The index name.

getServiceVersion

public SearchServiceVersion getServiceVersion()

Gets the SearchServiceVersion used to communicate with the Azure AI Search service.

Returns:

The service version.

indexDocuments

public IndexDocumentsResult indexDocuments(IndexDocumentsBatch batch)

Sends a batch of document write actions to the index.

Parameters:

batch - The batch of index actions.

Returns:

response containing the status of operations for all documents in the indexing request.

indexDocumentsWithResponse

public Response<IndexDocumentsResult> indexDocumentsWithResponse(IndexDocumentsBatch batch, IndexDocumentsOptions options, RequestOptions requestOptions)

Sends a batch of document write actions to the index.

Parameters:

batch - The batch of index actions.
options - Options that allow specifying document indexing behavior.
requestOptions - The options to configure the HTTP request before HTTP client sends it.

Returns:

response containing the status of operations for all documents in the indexing request.

search

public SearchPagedIterable search(SearchOptions options)

Searches for documents in the Azure AI Search index.

The ContinuablePagedIterable<C,T,P> will iterate through search result pages until all search results are returned. Each page is determined by the $skip and $top values and the Search service has a limit on the number of documents that can be skipped, more information about the $skip limit can be found at Search Documents REST API and reading the $skip description. If the total number of results exceeds the $skip limit the ContinuablePagedIterable<C,T,P> won't prevent you from exceeding the $skip limit. To prevent exceeding the limit you can track the number of documents returned and stop requesting new pages when the limit is reached.

Parameters:

options - Options for search API.

Returns:

A ContinuablePagedIterable<C,T,P> that iterates over search results and provides access to the SearchPagedResponse for each page containing HTTP response and count, facet, and coverage information.

search

public SearchPagedIterable search(SearchOptions options, RequestOptions requestOptions)

Searches for documents in the Azure AI Search index.

Header Parameters

| ------------------------------- | ------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| Name                            | Type    | Required | Description                                                                                                                         |
| x-ms-query-source-authorization | String  | No       | Token identifying the user for which the query is being executed. This token is used to enforce security restrictions on documents. |
| x-ms-enable-elevated-read       | Boolean | No       | A value that enables elevated read that bypass document level permission checks for the query operation.                            |

You can add these to a request with RequestOptions#addHeader

The ContinuablePagedIterable<C,T,P> will iterate through search result pages until all search results are returned. Each page is determined by the $skip and $top values and the Search service has a limit on the number of documents that can be skipped, more information about the $skip limit can be found at Search Documents REST API and reading the $skip description. If the total number of results exceeds the $skip limit the ContinuablePagedIterable<C,T,P> won't prevent you from exceeding the $skip limit. To prevent exceeding the limit you can track the number of documents returned and stop requesting new pages when the limit is reached.

Parameters:

options - Options for search API.
requestOptions - The options to configure the HTTP request before HTTP client sends it.

Returns:

A ContinuablePagedIterable<C,T,P> that iterates over search results and provides access to the SearchPagedResponse for each page containing HTTP response and count, facet, and coverage information.

suggest

public SuggestDocumentsResult suggest(SuggestOptions options)

Suggests documents in the index that match the given partial query text.

Parameters:

options - Options for suggest API.

Returns:

response containing suggestion query results from an index.

suggestWithResponse

public Response<SuggestDocumentsResult> suggestWithResponse(SuggestOptions options, RequestOptions requestOptions)

Suggests documents in the index that match the given partial query text.

Parameters:

options - Options for suggest API.
requestOptions - The options to configure the HTTP request before HTTP client sends it.

Returns:

response containing suggestion query results from an index along with Response<T>.

Applies to