public class ElasticsearchRepository extends Object implements IBigDataRepositorySPI
Modifier and Type | Field and Description |
---|---|
protected BulkProcessor |
bulkProcessor
The
BulkProcessor instance shared with IBatchIndexer generated by this repository. |
protected org.elasticsearch.client.Client |
client |
static List<Locale> |
NATIVE_TEMPLATES_SYNONYMS_LOCALES |
protected ElasticsearchRepository |
repository |
static String |
UNIQUE_DOC_TYPE_NAME |
Constructor and Description |
---|
ElasticsearchRepository() |
Modifier and Type | Method and Description |
---|---|
void |
addDocument(Document document)
Adds a document to the index.
|
void |
addDocumentToIndexQueue(Document document)
Adds a document that may be delayed until it is indexed.
|
void |
addIndex(Locale locale)
Adds the indices relative to the given locale in Elasticsearch.
|
void |
addOrUpdateDocument(Document document)
Adds or updates a document on the index.
|
void |
addOrUpdateDocumentType(DocumentType documentType)
Deprecated.
|
void |
addOrUpdateDocumentType(DocumentType documentType,
boolean force)
Adds or updates a document type into managed indices.
If the managed indices couldn't be updated in underlying big data repository: If force parameter is true , they will be recreated, causing data loss.
Else, an IllegalArgumentException will be raised.
|
void |
deleteDocument(DocumentType documentType,
Locale locale,
String documentId)
Deletes a document from the index with the given specifications.
|
void |
deleteDocumentsByFieldValue(String fieldId,
Collection<?> values)
Deletes documents that are matched by one of the given values in the field of given field
identifier.
|
void |
deleteDocumentsByFieldValue(String fieldId,
Object... values)
Deletes documents that are matched by one of the given values in the field of given field
identifier.
|
void |
deleteDocumentsByQuery(SearchQuery searchQuery)
Deletes documents that are matched by the given search query.
The search query's sorts ,
initial hit and maximum hit count will be
ignored. |
void |
deleteDocumentType(String documentTypeId)
Deletes a given document type from managed indices.
|
void |
deleteIndex(Locale locale)
Deletes the indices related to the given locale.
|
void |
deleteIndicesTemplates()
Delete the all index templates.
|
void |
destroy()
Destroy this repository and performs any required resource freeing.
|
protected void |
executeAsync(org.elasticsearch.action.ActionRequest request)
Sends a request to Elasticsearch to be executed asynchronously.
|
protected void |
executeAsync(org.elasticsearch.action.ActionRequest request,
boolean doFlush)
Sends a request to Elasticsearch to be executed asynchronously.
|
protected <T extends org.elasticsearch.action.ActionResponse> |
executeSync(org.elasticsearch.action.Action<T> action,
org.elasticsearch.action.ActionRequest request)
Executes a request to Elasticsearch synchronously and returns the response.
|
protected <T extends org.elasticsearch.action.ActionResponse> |
executeSync(org.elasticsearch.action.ActionRequestBuilder<?,T> request)
Executes a request to Elasticsearch synchronously and returns the response.
|
protected <T extends org.elasticsearch.action.ActionResponse> |
executeSync(org.elasticsearch.action.ActionRequestBuilder<?,T> request,
boolean remapException)
Executes a request to Elasticsearch synchronously and returns the response.
|
Map<String,? extends DocumentType> |
getAllDocumentTypes()
Returns all document types, indexed by document type identifier.
|
String[] |
getAllIndicesNames(DocumentType type)
Return all portal indices names for a type - for each locale - include null - generate a index name.
|
List<String> |
getAutoCompleteSuggestions(SearchQuery searchQuery,
AutoCompleteSuggestionConfig autoCompleteSuggestion)
Returns a list of auto complete suggestions for the given auto complete suggestion configuration and the search
query.
|
protected org.elasticsearch.action.search.SearchRequestBuilder |
getBaseQuery(SearchQuery searchQuery)
Returns a search request builder based on the given
SearchQuery . |
BulkProcessor |
getBulkProcessor()
Returns an internal bulk processor used by this repository.
|
org.elasticsearch.client.Client |
getDelegate()
Returns the underlying Elasticsearch client of this repository.
|
DocumentType |
getDocumentType(String documentTypeId)
Returns the document type of the given identifier.
|
DocumentType |
getDocumentTypeByIndex(String index)
Return the
DocumentType for index name. |
DocumentTypeField |
getDocumentTypeField(String documentTypeFieldFullId)
Return the document type field of the field that has the given identifier.
|
org.elasticsearch.action.search.SearchRequestBuilder |
getElasticsearchQuery(SearchQuery searchQuery)
Returns the Elasticsearch search query for the given
SearchQuery . |
String |
getElasticsearchType(DocumentType documentType)
Return the doctype that is save in elasticsearch mapping.
|
String |
getIndexTemplateSettings(Locale locale)
Returns the index template settings for the given locale.
|
String[] |
getIndices(SearchQuery searchQuery)
Returns the indices to be used for a search query.
|
org.elasticsearch.index.query.QueryBuilder |
getQueryBuilder(SearchQuery searchQuery)
Generates a Elasticsearch's
QueryBuilder initialized according to a LumisXP's SearchQuery . |
String |
getRetiredAliasName()
Returns the alias used for LumisXP indices that were used in previous versions but are no longer used in
current version.
|
String |
getSearchAliasName()
Returns the alias used for searching in LumisXP indices.
|
Map<Locale,IFile> |
getSynonymsFiles()
Return a map with all files that the portal need to create based the Locales of synonyms and Locales of portal.
|
void |
init(String repositoryId)
Initializes this repository using the given
node as configuration. |
protected void |
logRequest(Object request)
Logs at debug level a request that will be sent to Elasticsearch.
|
Document |
readDocument(DocumentType documentType,
Locale locale,
String documentId)
Reads a document from the repository with the given specifications.
|
void |
refreshIndices(Collection<String> documentTypeIds,
Locale... locales)
Refresh the indices of the given document type.
|
void |
refreshIndices(DocumentType documentType,
Locale... locales)
Refresh the indices of the given document type.
|
void |
refreshIndices(String documentTypeId,
Locale... locales)
Refresh the indices of the given document type.
|
void |
reloadSynonyms()
Reloads the synonyms in this repository.
|
ISearchResults |
search(SearchQuery searchQuery)
Runs the given
search query and returns the search results . |
<T> List<T> |
searchUsingScroll(org.elasticsearch.action.search.SearchRequestBuilder query,
int startAt,
int maxResults,
java.util.function.Function<org.elasticsearch.action.search.SearchResponse,List<T>> collector)
Performs the searching using scroll and collect data from all ranges.
|
IBatchIndexer |
startBatch()
Returns an indexer to perform bulk actions.
The caller must assure IBatchIndexer.close() is called after the desired bulk operations were
performed. |
void |
updateDocumentsByQuerySync(SearchQuery searchQuery,
Map<String,Object> fieldValues)
Updates documents that matches a
SearchQuery updating their field values according to the
fieldValues map. |
void |
validate(SearchQuery searchQuery)
Checks is the given
search query is syntactically correct. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addDocument, addOrUpdateDocument, deleteDocument, deleteDocumentsByFieldValue, deleteDocumentsByFieldValue, updateDocumentsByQuerySync
public static final String UNIQUE_DOC_TYPE_NAME
public static final List<Locale> NATIVE_TEMPLATES_SYNONYMS_LOCALES
protected org.elasticsearch.client.Client client
protected BulkProcessor bulkProcessor
BulkProcessor
instance shared with IBatchIndexer
generated by this repository.startBatch()
protected ElasticsearchRepository repository
public void init(String repositoryId)
IBigDataRepositorySPI
node
as configuration.init
in interface IBigDataRepositorySPI
repositoryId
- the repository identifier.public void deleteIndicesTemplates()
public String getSearchAliasName()
public String getRetiredAliasName()
This method is intended for use by special upgrade tasks so they can find the indices with previous versions data so they can convert them to current format.
public void addIndex(Locale locale)
locale
- the locale the indices to be created refers to.public void deleteIndex(Locale locale)
locale
- the locale.public String getIndexTemplateSettings(Locale locale)
locale
- the locale or null
for locale agnostic settings.public void destroy()
IBigDataRepositorySPI
destroy
in interface IBigDataRepositorySPI
@Deprecated public void addOrUpdateDocumentType(DocumentType documentType)
IBigDataRepository
addOrUpdateDocumentType
in interface IBigDataRepository
documentType
- the document type to be added.DocumentTypes
public void addOrUpdateDocumentType(DocumentType documentType, boolean force)
IBigDataRepository
force
parameter is true
, they will be recreated, causing data loss.IllegalArgumentException
will be raised.addOrUpdateDocumentType
in interface IBigDataRepository
documentType
- the document type to be added.force
- indicates whether the update should be forced.DocumentTypes
public String[] getAllIndicesNames(DocumentType type)
typeName
- the type.public String[] getIndices(SearchQuery searchQuery)
searchQuery
- the search query.SearchQuery.getDocumentTypeIds()
or getSearchAliasName()
if
SearchQuery.getDocumentTypeIds()
is empty.public void deleteDocumentType(String documentTypeId) throws PortalObjectNotFoundException
IBigDataRepository
deleteDocumentType
in interface IBigDataRepository
documentTypeId
- the document type identifier to be deleted.PortalObjectNotFoundException
- if the document type with the given identifier couldn't be found.public DocumentType getDocumentType(String documentTypeId) throws PortalObjectNotFoundException
IBigDataRepository
getDocumentType
in interface IBigDataRepository
documentTypeId
- the document type identifier.PortalObjectNotFoundException
- if the desired type does not exist.public DocumentType getDocumentTypeByIndex(String index) throws PortalObjectNotFoundException
DocumentType
for index name.index
- the index name.DocumentType
PortalObjectNotFoundException
public DocumentTypeField getDocumentTypeField(String documentTypeFieldFullId) throws PortalObjectNotFoundException
IBigDataRepository
getDocumentTypeField
in interface IBigDataRepository
documentTypeFieldFullId
- the (full) identifier of the document type field.PortalObjectNotFoundException
- if the desired field does not exist.public Map<String,? extends DocumentType> getAllDocumentTypes()
IBigDataRepositorySPI
getAllDocumentTypes
in interface IBigDataRepositorySPI
public Document readDocument(DocumentType documentType, Locale locale, String documentId) throws PortalObjectNotFoundException
IBigDataRepository
readDocument
in interface IBigDataRepository
documentType
- the document's type.locale
- the document's locale as set in its standard
locale field. Must be null
if the document does not have a locale specified.documentId
- the document's identifier.PortalObjectNotFoundException
- if no matching document was found.public IBatchIndexer startBatch()
IBigDataRepository
IBatchIndexer.close()
is called after the desired bulk operations were
performed.
Example of usage:
Or using try-with-resources:
startBatch
in interface IBigDataRepository
public void deleteDocumentsByQuery(SearchQuery searchQuery)
IBigDataIndexer
sorts
,
initial hit
and maximum hit count
will be
ignored.deleteDocumentsByQuery
in interface IBigDataIndexer
searchQuery
- the search query.public ISearchResults search(SearchQuery searchQuery)
IBigDataSearcher
search query
and returns the search results
.search
in interface IBigDataSearcher
searchQuery
- the query to run.public org.elasticsearch.action.search.SearchRequestBuilder getElasticsearchQuery(SearchQuery searchQuery)
SearchQuery
.searchQuery
- the search query.SearchQuery
.public <T> List<T> searchUsingScroll(org.elasticsearch.action.search.SearchRequestBuilder query, int startAt, int maxResults, java.util.function.Function<org.elasticsearch.action.search.SearchResponse,List<T>> collector)
query
- the query.startAt
- the start at position (1-based).maxResults
- maximum results of query.collector
- the function interface that will collect from response the required data.public List<String> getAutoCompleteSuggestions(SearchQuery searchQuery, AutoCompleteSuggestionConfig autoCompleteSuggestion)
IBigDataSearcher
getAutoCompleteSuggestions
in interface IBigDataSearcher
searchQuery
- the search query the auto complete request will be based on.autoCompleteSuggestion
- the auto complete suggestion request.public void validate(SearchQuery searchQuery) throws PortalException
IBigDataSearcher
search query
is syntactically correct.validate
in interface IBigDataSearcher
searchQuery
- the search query
to be validatedPortalException
- if there is a syntax error in query.public org.elasticsearch.client.Client getDelegate()
getDelegate
in interface IBigDataRepository
public BulkProcessor getBulkProcessor()
public void reloadSynonyms() throws AccessDeniedException, PortalException
IBigDataRepositorySPI
reloadSynonyms
in interface IBigDataRepositorySPI
AccessDeniedException
- if user doesn't have the appropriate permission.PortalException
- if some error occur.public Map<Locale,IFile> getSynonymsFiles()
IBigDataRepositorySPI
getSynonymsFiles
in interface IBigDataRepositorySPI
public String getElasticsearchType(DocumentType documentType)
documentType
- the documentType.public void refreshIndices(DocumentType documentType, Locale... locales)
documentType
- the document type.locales
- the locales.public void refreshIndices(String documentTypeId, Locale... locales)
documentType
- the document type.locales
- the locales.public void refreshIndices(Collection<String> documentTypeIds, Locale... locales)
documentTypeIds
- the document type identifiers.locales
- the locales.public void addDocument(Document document)
IBigDataIndexer
addDocument
in interface IBigDataIndexer
document
- the document
to be added.IBigDataIndexer.addOrUpdateDocument(Document)
public void addDocumentToIndexQueue(Document document)
document
- the document.public void addOrUpdateDocument(Document document)
IBigDataIndexer
addOrUpdateDocument
in interface IBigDataIndexer
document
- the document
to be added.IBigDataIndexer.addDocument(Document)
public void deleteDocument(DocumentType documentType, Locale locale, String documentId)
IBigDataIndexer
deleteDocument
in interface IBigDataIndexer
documentType
- the document's type.locale
- the document's locale as set in its standard
locale field. Must be null
if the document does not have a locale specified.documentId
- the document's identifier.public void deleteDocumentsByFieldValue(String fieldId, Object... values)
IBigDataIndexer
deleteDocumentsByFieldValue
in interface IBigDataIndexer
fieldId
- the field identifier.values
- the values.public void deleteDocumentsByFieldValue(String fieldId, Collection<?> values)
IBigDataIndexer
deleteDocumentsByFieldValue
in interface IBigDataIndexer
fieldId
- the field identifier.values
- the values.public void updateDocumentsByQuerySync(SearchQuery searchQuery, Map<String,Object> fieldValues)
IBigDataIndexer
SearchQuery
updating their field values according to the
fieldValues
map.
This operation is synchronous in relation to the completion of the update execution. Searches performed after this method returns may not reflect the update, since internal optimizations and behavior of the underlying big data storage may demand some time for the update to be visible to searches.
updateDocumentsByQuerySync
in interface IBigDataIndexer
searchQuery
- the search query.fieldValues
- a map where the key is a field's full identifier and the value is the value to be set on the
corresponding field. The value must be of a type compatible with the field type. If the value is null
,protected org.elasticsearch.action.search.SearchRequestBuilder getBaseQuery(SearchQuery searchQuery)
SearchQuery
.
Does not add sort, aggregations, start at and max rows.searchQuery
- the search query.SearchQuery
.public org.elasticsearch.index.query.QueryBuilder getQueryBuilder(SearchQuery searchQuery)
QueryBuilder
initialized according to a LumisXP's SearchQuery
.searchQuery
- the LumisXP's search query.protected <T extends org.elasticsearch.action.ActionResponse> T executeSync(org.elasticsearch.action.ActionRequestBuilder<?,T> request)
protected <T extends org.elasticsearch.action.ActionResponse> T executeSync(org.elasticsearch.action.ActionRequestBuilder<?,T> request, boolean remapException)
protected <T extends org.elasticsearch.action.ActionResponse> T executeSync(org.elasticsearch.action.Action<T> action, org.elasticsearch.action.ActionRequest request)
action
- the request action.request
- the request.protected void executeAsync(org.elasticsearch.action.ActionRequest request)
protected void executeAsync(org.elasticsearch.action.ActionRequest request, boolean doFlush)
protected void logRequest(Object request)
request
- the request object.LumisXP 12.5.0.200928 - Copyright © 2006–2020 Lumis EIP Tecnologia da Informação LTDA. All Rights Reserved.