Interface IndexSearcher
- All Known Implementing Classes:
IndexSearcherWithStats,LuceneIndexSearcher,OpenSearchIndexSearcher
Document doc = indexSearcher.get(GetRequest.builder()
.id("253")
.fields(TITLE, BODY, CREATION)
.build()).get();
Collection<String> titles = TITLE.get(doc);
Collection<Long> creations = CREATION.get(doc);
- Since:
- 10.4
-
Method Summary
Modifier and TypeMethodDescriptionlonggetHitCount(SearchRequest request, Long timeout) Return the number of documents that match the requestsearch(SearchRequest request, PageRequest pageRequest) Retrieves a search response that includes a collection of document hits and aggregated results.searchStream(SearchRequest request) Retrieves a search response that provides streamable access to document hits and aggregated results.
-
Method Details
-
search
Retrieves a search response that includes a collection of document hits and aggregated results.By default, the hits are sorted in descending order of relevance score produced by the query ranking. The amount of hits returned is controlled by
PageRequest.- Parameters:
request- request describing the query, optional sort order, fields to retrieve and aggregation requestpageRequest- the page request- Returns:
SearchResponsecontaining the ordered list of document hits and any relevant aggregated data.- Throws:
SearchException
-
searchStream
Retrieves a search response that provides streamable access to document hits and aggregated results.By default, the hits are sorted in descending order of relevance score produced by the query ranking.
It is important to
closethe resulting response after use in order to clean up its resources. We recommend using try-with-resources.Performance note: this operation has an overhead over the normal
search, so use it only when you specifically need to iterate through a large number of data, for example for data exports or migrations.Also consider a
searchwithaggregationsinstead of computing it with this stream operation. Search aggregation API off-loads the computation to the search index, which is vastly more efficient than streaming all the documents, especially on OpenSearch.Sorting is not supported when streaming results and will result in a
SearchExceptionbeing thrown.- Parameters:
request- request describing the query, optional sort order, fields to retrieve and aggregation request- Returns:
SearchStreamResponsecontaining the ordered stream of document hits and any relevant aggregated data.- Throws:
SearchException
-
getHitCount
Return the number of documents that match the request- Parameters:
request- request describing the query on which document should be countedtimeout- request timeout in milliseconds, or null if no timeout- Returns:
- the number of documents satisfying the query
- Throws:
SearchException- if search requests takes longer than timeout
-