Class OpenSearchSearchIndexAccessor
- All Implemented Interfaces:
SearchIndexAccessor
,org.springframework.beans.factory.DisposableBean
- Since:
- 8.6
-
Constructor Summary
ConstructorDescriptionOpenSearchSearchIndexAccessor
(OpenSearchIndexManager indexManager, org.opensearch.client.opensearch.OpenSearchClient client, OpenSearchSearchManager searchManager, OpenSearchIndexWriterFactory writerFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
void
execute
(SearchIndexAction action) Executes a SearchIndexAction on the underlying search index.long
Get the total size of the index in bytes.int
numDocs()
Get the total number of index documents for the underlying search indexvoid
Refresh the index immediately, which publishes its most recent changes and makes them available for searching.void
Execute a method after the index has been closed and before the index has been reopenedlong
scan
(SearchQuery searchQuery, Set<String> requestedFields, Consumer<ScannedDocument> consumer, float defaultScore) Scans the index for documents that match the provided searchQuery.long
Scans the index for documents that match the provided searchQuery.Perform asearch
, the returnedSearchResults
only have the fields requested in the projection filled out, no other fields are valid in thesearchResult
.void
Take a snapshot of the current index and store it into the destination directoryvoid
withBatchUpdate
(BatchUpdateAction batchUpdateAction) Execute the update action in a batch.
-
Constructor Details
-
OpenSearchSearchIndexAccessor
public OpenSearchSearchIndexAccessor(OpenSearchIndexManager indexManager, org.opensearch.client.opensearch.OpenSearchClient client, OpenSearchSearchManager searchManager, OpenSearchIndexWriterFactory writerFactory)
-
-
Method Details
-
search
public SearchResults search(ISearch search, Set<String> requestedFields) throws InvalidSearchException Description copied from interface:SearchIndexAccessor
Perform asearch
, the returnedSearchResults
only have the fields requested in the projection filled out, no other fields are valid in thesearchResult
.SearchResults will throw an
FieldNotRequestedException
if an attempt is made to access a field value that has not had it's key included in the projection Set.NOTE: the search limit will be capped at
SearchConstants.MAX_LIMIT
and the startOffset will be capped atSearchConstants.MAX_START_OFFSET
for more efficient heap usage. SeeSearchResults.getNextPageSearch()
for pagination.WARNING: there is no default permissions checking behaviour provided. You MUST provide a search which specifies permissions checking. See
SiteSearchPermissionsQueryFactory
to add one yourself. SeePredefinedSearchBuilder
to build a pre-defined search which contains permission checking.- Specified by:
search
in interfaceSearchIndexAccessor
- Parameters:
search
- the search to perform.requestedFields
- requested fields. Passingnull
will request all fields, and passing empty set will request none.- Throws:
InvalidSearchException
- if some error occurred converting the search object into * a search that could be performed in the back-end. Usually this is a sign that some plugin that was * used to create the search is no longer available.- See Also:
-
scan
public long scan(SearchQuery searchQuery, Set<String> requestedFields, Consumer<Map<String, String[]>> consumer) Description copied from interface:SearchIndexAccessor
Scans the index for documents that match the provided searchQuery. The requestedFields set is used to specify which values need to be returned. The consumer will collect all the results found by the scan.Note that it is possible for a document to match the query, but not have any of the requested fields. This will result in an empty String[] for those fields that don't exist on the document. If you don't want to return those documents, you should specify a consumer that filters these out.
WARNING: there is no default permissions checking behaviour provided. You MUST provide a search which specifies permissions checking. See
SiteSearchPermissionsQueryFactory
to add one yourself. SeePredefinedSearchBuilder
to build a pre-defined search which contains permission checking.- Specified by:
scan
in interfaceSearchIndexAccessor
- Parameters:
searchQuery
- SearchQuery to scan the index for.requestedFields
- Set of field names that are requested from the index. Any fields provided here that is not on the document will return an empty String[] Passingnull
will request all fields, and passing empty set will request none.consumer
- Consumer that handles each found document.- Returns:
- the number of documents that matched the searchQuery.
- See Also:
-
scan
public long scan(SearchQuery searchQuery, Set<String> requestedFields, Consumer<ScannedDocument> consumer, float defaultScore) Description copied from interface:SearchIndexAccessor
Scans the index for documents that match the provided searchQuery. The requestedFields set is used to specify which values need to be returned. The consumer will collect all the results found by the scan and convert them intoScannedDocument
, which contains a score (if scoreIncluded is true) and a field-value map of the requested fields.Note that it is possible for a document to match the query, but not have any of the requested fields as the other scan method.
This will result in an empty String[] for those fields that don't exist on the document. If you don't want to return those documents, you should specify a consumer that filters these out.
WARNING: there is no default permissions checking behaviour provided. You MUST provide a search which specifies permissions checking. See
SiteSearchPermissionsQueryFactory
to add one yourself. SeePredefinedSearchBuilder
to build a pre-defined search which contains permission checking.- Specified by:
scan
in interfaceSearchIndexAccessor
- Parameters:
searchQuery
- SearchQuery to scan the index for.requestedFields
- Set of field names that are requested from the index. Any fields provided here that is not on the document will return an empty String[] Passingnull
will request all fields, and passing empty set will request none.consumer
- Consumer that handles each found document.defaultScore
- a default score to be included in theScannedDocument
if it is not possible to retrieve the score for the document.- Returns:
- the number of documents that matched the searchQuery.
- See Also:
-
execute
Description copied from interface:SearchIndexAccessor
Executes a SearchIndexAction on the underlying search index.- Specified by:
execute
in interfaceSearchIndexAccessor
- Parameters:
action
- SearchIndexAction- Throws:
SearchIndexAccessException
- if there is an io error.
-
numDocs
Description copied from interface:SearchIndexAccessor
Get the total number of index documents for the underlying search index- Specified by:
numDocs
in interfaceSearchIndexAccessor
- Returns:
- the total number of index documents
- Throws:
SearchIndexAccessException
-
getSizeInBytes
Description copied from interface:SearchIndexAccessor
Get the total size of the index in bytes.- Specified by:
getSizeInBytes
in interfaceSearchIndexAccessor
- Returns:
- size of the index in bytes
- Throws:
SearchIndexAccessException
-
withBatchUpdate
Description copied from interface:SearchIndexAccessor
Execute the update action in a batch. Executions are transactional, reads can't see any writes made and the index will be locked for updating by other threads. Currently, there is no rollback when the transaction fails for any reason. This is a bug which will be investigated in future.- Specified by:
withBatchUpdate
in interfaceSearchIndexAccessor
- Parameters:
batchUpdateAction
- the batch update action
-
snapshot
Description copied from interface:SearchIndexAccessor
Take a snapshot of the current index and store it into the destination directory- Specified by:
snapshot
in interfaceSearchIndexAccessor
- Parameters:
destinationDirectory
- the destination directory- Throws:
SearchIndexAccessException
- if the snapshot could not be taken
-
reset
Description copied from interface:SearchIndexAccessor
Execute a method after the index has been closed and before the index has been reopened- Specified by:
reset
in interfaceSearchIndexAccessor
- Parameters:
replaceIndex
- the method that needs to be executed
-
getFieldMappings
- Specified by:
getFieldMappings
in interfaceSearchIndexAccessor
- Returns:
FieldMappings
associated with this index
-
destroy
- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
- Throws:
Exception
-
refreshIndex
Description copied from interface:SearchIndexAccessor
Refresh the index immediately, which publishes its most recent changes and makes them available for searching. This method is only applicable to the OpenSearch platform.- Specified by:
refreshIndex
in interfaceSearchIndexAccessor
- Throws:
IOException
-