Class AbstractElasticsearchIndex
java.lang.Object
org.opencastproject.elasticsearch.impl.AbstractElasticsearchIndex
- All Implemented Interfaces:
SearchIndex
- Direct Known Subclasses:
ElasticsearchIndex
A search index implementation based on ElasticSearch.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConfiguration key defining the password of an external Elasticsearch serverstatic final StringConfiguration key defining the hostname of an external Elasticsearch serverstatic final StringConfiguration key defining the port of an external Elasticsearch serverstatic final StringConfiguration key defining the scheme (http/https) of an external Elasticsearch serverstatic final StringConfiguration key defining the username of an external Elasticsearch serverprotected StringThe path to the index settingsFields inherited from interface org.opencastproject.elasticsearch.api.SearchIndex
INDEX_VERSION -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidOSGi callback to activate this component instance.protected org.elasticsearch.action.bulk.BulkResponsebulkUpdate(int maxRetryAttempts, int retryWaitingPeriod, List<ElasticsearchDocument> documents) Posts the input documents to the search index.voidclear()Clears the search index.protected voidclose()Closes the client.protected org.elasticsearch.action.delete.DeleteResponseDelete document from index.protected <T> SearchResult<T> executeQuery(SearchQuery query, org.elasticsearch.action.search.SearchRequest request, Function<SearchMetadataCollection, T> toSearchResult, int maxRetryAttempts, int retryWaitingPeriod) Execute a query on the index.org.elasticsearch.client.RestHighLevelClientabstract String[]Returns an array of document types for the index.Returns the name of this index.intReturns the index's version number.protected org.elasticsearch.action.search.SearchRequestgetSearchRequest(SearchQuery query, org.elasticsearch.index.query.QueryBuilder queryBuilder) Creates a request for a search query based on the properties known by the search query.protected StringgetSubIndexIdentifier(String type) Returns the name of the sub index for the given type.getTermsForField(String field, String type) Returns all the known terms for a field (aka facets).protected longgetTotalHits(org.elasticsearch.search.SearchHits hits) protected voidinit(int version) Initializes an Elasticsearch node for the given index.voidOSGi callback for configuration changes.protected org.elasticsearch.action.index.IndexResponseupdate(int maxRetryAttempts, int retryWaitingPeriod, ElasticsearchDocument document) Posts the input document to the search index.
-
Field Details
-
ELASTICSEARCH_SERVER_HOSTNAME_KEY
Configuration key defining the hostname of an external Elasticsearch server- See Also:
-
ELASTICSEARCH_SERVER_SCHEME_KEY
Configuration key defining the scheme (http/https) of an external Elasticsearch server- See Also:
-
ELASTICSEARCH_SERVER_PORT_KEY
Configuration key defining the port of an external Elasticsearch server- See Also:
-
ELASTICSEARCH_USERNAME_KEY
Configuration key defining the username of an external Elasticsearch server- See Also:
-
ELASTICSEARCH_PASSWORD_KEY
Configuration key defining the password of an external Elasticsearch server- See Also:
-
indexSettingsPath
The path to the index settings
-
-
Constructor Details
-
AbstractElasticsearchIndex
public AbstractElasticsearchIndex()
-
-
Method Details
-
getDocumentTypes
Returns an array of document types for the index. For every one of these, the corresponding document type definition will be loaded.- Returns:
- the document types
-
activate
public void activate(Map<String, Object> properties, org.osgi.framework.BundleContext bundleContext) throws org.osgi.service.component.ComponentExceptionOSGi callback to activate this component instance.- Parameters:
properties- The configurationbundleContext- the bundle context- Throws:
org.osgi.service.component.ComponentException- if the search index cannot be initialized
-
modified
OSGi callback for configuration changes.- Parameters:
properties- The configuration
-
getIndexVersion
public int getIndexVersion()Description copied from interface:SearchIndexReturns the index's version number. If that number is different fromSearchIndex.INDEX_VERSION, a reindex is needed, since the index's structure could have changed significantly.- Specified by:
getIndexVersionin interfaceSearchIndex- Returns:
- the index version
-
clear
Description copied from interface:SearchIndexClears the search index.- Specified by:
clearin interfaceSearchIndex- Throws:
IOException- if clearing the index fails
-
update
protected org.elasticsearch.action.index.IndexResponse update(int maxRetryAttempts, int retryWaitingPeriod, ElasticsearchDocument document) throws IOException, InterruptedException Posts the input document to the search index.- Parameters:
maxRetryAttempts- How often to retry update in case of ElasticsearchStatusExceptionretryWaitingPeriod- How long to wait (in ms) between retriesdocument- The Elasticsearch document- Returns:
- the query response
- Throws:
IOException- If updating the index failsInterruptedException- If waiting during retry is interrupted
-
bulkUpdate
protected org.elasticsearch.action.bulk.BulkResponse bulkUpdate(int maxRetryAttempts, int retryWaitingPeriod, List<ElasticsearchDocument> documents) throws IOException, InterruptedException Posts the input documents to the search index.- Parameters:
maxRetryAttempts- How often to retry update in case of ElasticsearchStatusExceptionretryWaitingPeriod- How long to wait (in ms) between retriesdocuments- The Elasticsearch documents- Returns:
- the query response
- Throws:
IOException- If updating the index failsInterruptedException- If waiting during retry is interrupted
-
delete
protected org.elasticsearch.action.delete.DeleteResponse delete(String type, String id, int maxRetryAttempts, int retryWaitingPeriod) throws IOException, InterruptedException Delete document from index.- Parameters:
type- The type of document we want to deleteid- The identifier of the document- Returns:
- The delete response
- Throws:
IOException- If deleting from the index failsInterruptedException- If waiting during retry is interrupted
-
init
Initializes an Elasticsearch node for the given index.- Parameters:
version- the index version- Throws:
SearchIndexException- if the index configuration cannot be loadedIOException- if loading of settings failsIllegalArgumentException- if the index identifier is blank.
-
close
Closes the client.- Throws:
IOException- if stopping the Elasticsearch node fails
-
getSearchRequest
protected org.elasticsearch.action.search.SearchRequest getSearchRequest(SearchQuery query, org.elasticsearch.index.query.QueryBuilder queryBuilder) Creates a request for a search query based on the properties known by the search query.Once this query builder has been created, support for ordering needs to be configured as needed.
- Parameters:
query- the search query- Returns:
- the request builder
-
getIndexName
Returns the name of this index.- Returns:
- the index name
-
getTotalHits
protected long getTotalHits(org.elasticsearch.search.SearchHits hits) -
getSubIndexIdentifier
Returns the name of the sub index for the given type.- Parameters:
type- The type to get the sub index for.- Returns:
- the index name
-
getClient
public org.elasticsearch.client.RestHighLevelClient getClient() -
executeQuery
protected <T> SearchResult<T> executeQuery(SearchQuery query, org.elasticsearch.action.search.SearchRequest request, Function<SearchMetadataCollection, T> toSearchResult, int maxRetryAttempts, int retryWaitingPeriod) throws IOException, InterruptedExceptionExecute a query on the index.- Parameters:
query- The query to use to find the resultsrequest- The builder to use to create the query.toSearchResult- The function to convert the results to aSearchResultmaxRetryAttempts- How often to retry query in case of ElasticsearchStatusExceptionretryWaitingPeriod- How long to wait (in ms) between retries- Returns:
- A
SearchResultcontaining the relevant objects. - Throws:
IOException- If querying the index failsInterruptedException- If waiting during retry is interrupted
-
getTermsForField
Returns all the known terms for a field (aka facets).- Parameters:
field- the field nametype- the document type- Returns:
- the list of terms
-