public class ElasticSearchPersistenceServiceImpl extends Object implements PersistenceService, org.osgi.framework.SynchronousBundleListener
Modifier and Type | Class and Description |
---|---|
static class |
ElasticSearchPersistenceServiceImpl.InClassLoaderExecute<T> |
Modifier and Type | Field and Description |
---|---|
static String |
BULK_PROCESSOR_BACKOFF_POLICY |
static String |
BULK_PROCESSOR_BULK_SIZE |
static String |
BULK_PROCESSOR_FLUSH_INTERVAL |
static String |
PRIMARY_TERM |
static String |
SEQ_NO |
Constructor and Description |
---|
ElasticSearchPersistenceServiceImpl() |
Modifier and Type | Method and Description |
---|---|
Map<String,Long> |
aggregateQuery(Condition filter,
BaseAggregate aggregate,
String itemType)
Deprecated.
As of version 1.3.0-incubating, use
aggregateWithOptimizedQuery(Condition, BaseAggregate, String) instead |
Map<String,Long> |
aggregateWithOptimizedQuery(Condition filter,
BaseAggregate aggregate,
String itemType)
Retrieves the number of items with the specified type as defined by the Item subclass public field
ITEM_TYPE matching the optional specified condition and
aggregated according to the specified BaseAggregate . |
Map<String,Long> |
aggregateWithOptimizedQuery(Condition filter,
BaseAggregate aggregate,
String itemType,
int size)
Retrieves the number of items with the specified type as defined by the Item subclass public field
ITEM_TYPE matching the optional specified condition and
aggregated according to the specified BaseAggregate . |
void |
bindConditionESQueryBuilder(org.osgi.framework.ServiceReference<ConditionESQueryBuilder> conditionESQueryBuilderServiceReference) |
void |
bindConditionEvaluator(org.osgi.framework.ServiceReference<ConditionEvaluator> conditionEvaluatorServiceReference) |
void |
bundleChanged(org.osgi.framework.BundleEvent event) |
PartialList<CustomItem> |
continueCustomItemScrollQuery(String customItemType,
String scrollIdentifier,
String scrollTimeValidity)
Continues the execution of a scroll query, to retrieve the next results.
|
<T extends Item> |
continueScrollQuery(Class<T> clazz,
String scrollIdentifier,
String scrollTimeValidity)
Continues the execution of a scroll query, to retrieve the next results.
|
boolean |
createIndex(String itemType)
Creates an index with for the specified item type in the persistence engine.
|
void |
createMapping(String type,
String source)
Create mapping
|
<T extends Item> |
getAllItems(Class<T> clazz)
Retrieves all known items of the specified class.
|
<T extends Item> |
getAllItems(Class<T> clazz,
int offset,
int size,
String sortBy)
Retrieves all known items of the specified class, ordered according to the specified
sortBy String and and paged: only size of them are retrieved,
starting with the offset -th one. |
<T extends Item> |
getAllItems(Class<T> clazz,
int offset,
int size,
String sortBy,
String scrollTimeValidity)
Retrieves all known items of the specified class, ordered according to the specified
sortBy String and and paged: only size of them are retrieved,
starting with the offset -th one. |
long |
getAllItemsCount(String itemType)
Retrieves the number of items with the specified type as defined by the Item subclass public field
ITEM_TYPE . |
org.elasticsearch.action.bulk.BulkProcessor |
getBulkProcessor() |
Map<String,Map<String,Object>> |
getPropertiesMapping(String itemType)
Retrieve the type mappings for a given itemType.
|
Map<String,Object> |
getPropertyMapping(String property,
String itemType)
Retrieve the mapping for one specific property for a given type.
|
Map<String,Double> |
getSingleValuesMetrics(Condition condition,
String[] metrics,
String field,
String itemType)
Retrieves the specified metrics for the specified field of items of the specified type as defined by the Item subclass public field
ITEM_TYPE and matching the
specified Condition . |
boolean |
indexTemplateExists(String templateName) |
boolean |
isConsistent(Item item)
Return true if the item which is saved in the persistence service is consistent
|
boolean |
isValidCondition(Condition condition,
Item item)
validates if a condition throws exception at query build.
|
<T extends Item> |
load(String itemId,
Class<T> clazz)
Retrieves the item identified with the specified identifier and with the specified Item subclass if it exists.
|
<T extends Item> |
load(String itemId,
Date dateHint,
Class<T> clazz)
Deprecated.
|
CustomItem |
loadCustomItem(String itemId,
Date dateHint,
String customItemType)
Deprecated.
|
CustomItem |
loadCustomItem(String itemId,
String customItemType)
Load a custom item type identified by an identifier, an optional date hint and the identifier of the custom item type
|
void |
purge(Date date)
deprecated: (use: purgeTimeBasedItems instead)
|
void |
purge(String scope)
Removes all data associated with the provided scope.
|
<T extends Item> |
purgeTimeBasedItems(int existsNumberOfDays,
Class<T> clazz)
Purges time based data in the context server up to the specified days number of existence.
|
<T extends Item> |
query(Condition query,
String sortBy,
Class<T> clazz)
Same as
query(query, sortBy, clazz, 0, -1).getList() |
<T extends Item> |
query(Condition query,
String sortBy,
Class<T> clazz,
int offset,
int size)
Retrieves a list of items satisfying the specified
Condition , ordered according to the specified sortBy String and and paged: only size of them
are retrieved, starting with the offset -th one. |
<T extends Item> |
query(Condition query,
String sortBy,
Class<T> clazz,
int offset,
int size,
String scrollTimeValidity)
Retrieves a list of items satisfying the specified
Condition , ordered according to the specified sortBy String and and paged: only size of them
are retrieved, starting with the offset -th one. |
<T extends Item> |
query(String fieldName,
String[] fieldValues,
String sortBy,
Class<T> clazz)
Retrieves a list of items with the specified field having the specified values.
|
<T extends Item> |
query(String fieldName,
String fieldValue,
String sortBy,
Class<T> clazz)
Same as
query(fieldName, fieldValue, sortBy, clazz, 0, -1).getList() |
<T extends Item> |
query(String fieldName,
String fieldValue,
String sortBy,
Class<T> clazz,
int offset,
int size)
Retrieves a list of items with the specified field having the specified value.
|
long |
queryCount(Condition query,
String itemType)
Retrieves the number of items of the specified type as defined by the Item subclass public field
ITEM_TYPE and matching the specified Condition . |
PartialList<CustomItem> |
queryCustomItem(Condition query,
String sortBy,
String customItemType,
int offset,
int size,
String scrollTimeValidity)
Retrieves a list of items satisfying the specified
Condition , ordered according to the specified
sortBy String and paged: only size of them are retrieved, starting with the
offset -th one. |
<T extends Item> |
queryFullText(String fulltext,
Condition query,
String sortBy,
Class<T> clazz,
int offset,
int size)
Retrieves the same items as
query(query, sortBy, clazz, 0, -1) with the added constraints that the matching elements must also have at least a field matching the
specified full text query. |
<T extends Item> |
queryFullText(String fulltext,
String sortBy,
Class<T> clazz,
int offset,
int size)
Retrieves a list of items having at least a field with the specified full text value in it, ordered according to the specified
sortBy String and and paged: only
size of them are retrieved, starting with the offset -th one. |
<T extends Item> |
queryFullText(String fieldName,
String fieldValue,
String fulltext,
String sortBy,
Class<T> clazz,
int offset,
int size)
Retrieves a list of items with the specified field having the specified value and having at least a field with the specified full text value in it, ordered according to the
specified
sortBy String and and paged: only size of them are retrieved, starting with the offset -th one. |
<T extends Item> |
rangeQuery(String fieldName,
String from,
String to,
String sortBy,
Class<T> clazz,
int offset,
int size)
Retrieves all items of the specified Item subclass which specified ranged property is within the specified bounds, ordered according to the specified
sortBy String
and and paged: only size of them are retrieved, starting with the offset -th one. |
void |
refresh()
Updates the persistence's engine indices if needed.
|
<T extends Item> |
refreshIndex(Class<T> clazz,
Date dateHint) |
boolean |
registerRolloverLifecyclePolicy() |
<T extends Item> |
remove(String itemId,
Class<T> clazz)
Deletes the item identified with the specified identifier and with the specified Item subclass if it exists.
|
<T extends Item> |
removeByQuery(Condition query,
Class<T> clazz)
Deletes items with the specified Item subclass matching the specified
Condition . |
<T extends Item> |
removeByQuery(org.elasticsearch.index.query.QueryBuilder queryBuilder,
Class<T> clazz) |
boolean |
removeCustomItem(String itemId,
String customItemType)
Remove a custom item identified by the custom item identifier and the custom item type identifier
|
boolean |
removeIndex(String itemType)
Removes the index for the specified item type.
|
boolean |
removeIndexTemplate(String templateName) |
boolean |
removeQuery(String queryName)
Deletes the query identified by the specified name.
|
boolean |
save(Item item)
Persists the specified Item in the context server.
|
boolean |
save(Item item,
boolean useBatching)
Persists the specified Item in the context server.
|
boolean |
save(Item item,
Boolean useBatchingOption,
Boolean alwaysOverwriteOption)
Persists the specified Item in the context server.
|
boolean |
saveQuery(String queryName,
Condition query)
Persists the specified query under the specified name.
|
boolean |
saveQuery(String queryName,
String query) |
void |
setAggQueryMaxResponseSizeHttp(String aggQueryMaxResponseSizeHttp) |
void |
setAggQueryThrowOnMissingDocs(boolean aggQueryThrowOnMissingDocs) |
void |
setAggregateQueryBucketSize(int aggregateQueryBucketSize) |
void |
setAlwaysOverwrite(boolean alwaysOverwrite) |
void |
setBulkProcessorBackoffPolicy(String bulkProcessorBackoffPolicy) |
void |
setBulkProcessorBulkActions(String bulkProcessorBulkActions) |
void |
setBulkProcessorBulkSize(String bulkProcessorBulkSize) |
void |
setBulkProcessorConcurrentRequests(String bulkProcessorConcurrentRequests) |
void |
setBulkProcessorFlushInterval(String bulkProcessorFlushInterval) |
void |
setBundleContext(org.osgi.framework.BundleContext bundleContext) |
void |
setClientSocketTimeout(String clientSocketTimeout) |
void |
setClusterName(String clusterName) |
void |
setConditionESQueryBuilderDispatcher(ConditionESQueryBuilderDispatcher conditionESQueryBuilderDispatcher) |
void |
setConditionEvaluatorDispatcher(ConditionEvaluatorDispatcher conditionEvaluatorDispatcher) |
void |
setDefaultQueryLimit(Integer defaultQueryLimit) |
void |
setElasticSearchAddresses(String elasticSearchAddresses) |
void |
setFatalIllegalStateErrors(String fatalIllegalStateErrors) |
void |
setIndexMappingTotalFieldsLimit(String indexMappingTotalFieldsLimit) |
void |
setIndexMaxDocValueFieldsSearch(String indexMaxDocValueFieldsSearch) |
void |
setIndexPrefix(String indexPrefix) |
void |
setItemsMonthlyIndexedOverride(String itemsMonthlyIndexedOverride)
Deprecated.
|
void |
setItemTypeToRefreshPolicy(String itemTypeToRefreshPolicy) |
void |
setLogLevelRestClient(String logLevelRestClient) |
void |
setMaximalElasticSearchVersion(String maximalElasticSearchVersion) |
void |
setMetricsService(MetricsService metricsService) |
void |
setMinimalElasticSearchVersion(String minimalElasticSearchVersion) |
void |
setMonthlyIndexMappingTotalFieldsLimit(String monthlyIndexMappingTotalFieldsLimit)
Deprecated.
|
void |
setMonthlyIndexMaxDocValueFieldsSearch(String monthlyIndexMaxDocValueFieldsSearch)
Deprecated.
|
void |
setMonthlyIndexNumberOfReplicas(String monthlyIndexNumberOfReplicas)
Deprecated.
|
void |
setMonthlyIndexNumberOfShards(String monthlyIndexNumberOfShards)
Deprecated.
|
void |
setNumberOfReplicas(String numberOfReplicas) |
void |
setNumberOfShards(String numberOfShards) |
void |
setPassword(String password) |
void |
setPropertyMapping(PropertyType property,
String itemType)
Create the persistence mapping for specific property for a given type.
|
void |
setRolloverIndexMappingTotalFieldsLimit(String rolloverIndexMappingTotalFieldsLimit) |
void |
setRolloverIndexMaxDocValueFieldsSearch(String rolloverIndexMaxDocValueFieldsSearch) |
void |
setRolloverIndexNumberOfReplicas(String rolloverIndexNumberOfReplicas) |
void |
setRolloverIndexNumberOfShards(String rolloverIndexNumberOfShards) |
void |
setRolloverIndices(String rolloverIndices) |
void |
setRolloverMaxAge(String rolloverMaxAge) |
void |
setRolloverMaxDocs(String rolloverMaxDocs) |
void |
setRolloverMaxSize(String rolloverMaxSize) |
void |
setRoutingByType(Map<String,String> routingByType) |
void |
setSslEnable(boolean sslEnable) |
void |
setSslTrustAllCertificates(boolean sslTrustAllCertificates) |
void |
setThrowExceptions(boolean throwExceptions) |
void |
setUseBatchingForSave(boolean useBatchingForSave) |
void |
setUseBatchingForUpdate(boolean useBatchingForUpdate) |
void |
setUsername(String username) |
void |
start() |
void |
stop() |
boolean |
storeScripts(Map<String,String> scripts)
Store script in the Database for later usage with updateWithQueryAndStoredScript function for example.
|
boolean |
testMatch(Condition query,
Item item)
Checks whether the specified item satisfies the provided condition.
|
void |
unbindConditionESQueryBuilder(org.osgi.framework.ServiceReference<ConditionESQueryBuilder> conditionESQueryBuilderServiceReference) |
void |
unbindConditionEvaluator(org.osgi.framework.ServiceReference<ConditionEvaluator> conditionEvaluatorServiceReference) |
boolean |
update(Item item,
Class clazz,
Map source)
Updates the item of the specified class and identified by the specified identifier with new property values provided as name - value pairs in the specified Map.
|
boolean |
update(Item item,
Class clazz,
Map source,
boolean alwaysOverwrite)
Updates the item of the specified class and identified by the specified identifier with new property values provided as name - value pairs in the specified Map.
|
boolean |
update(Item item,
Class clazz,
String propertyName,
Object propertyValue)
Updates the item of the specified class and identified by the specified identifier with a new property value for the specified property name.
|
boolean |
update(Item item,
Date dateHint,
Class clazz,
Map source) |
boolean |
update(Item item,
Date dateHint,
Class clazz,
Map source,
boolean alwaysOverwrite) |
boolean |
update(Item item,
Date dateHint,
Class clazz,
String propertyName,
Object propertyValue) |
List<String> |
update(Map<Item,Map> items,
Date dateHint,
Class clazz) |
boolean |
updateWithQueryAndScript(Class<?> clazz,
String[] scripts,
Map<String,Object>[] scriptParams,
Condition[] conditions)
Updates the items of the specified class by a query with a new property value for the specified property name
based on provided scripts and script parameters
|
boolean |
updateWithQueryAndScript(Date dateHint,
Class<?> clazz,
String[] scripts,
Map<String,Object>[] scriptParams,
Condition[] conditions) |
boolean |
updateWithQueryAndStoredScript(Class<?> clazz,
String[] scripts,
Map<String,Object>[] scriptParams,
Condition[] conditions)
Updates the items of the specified class by a query with a new property value for the specified property name
based on provided stored scripts and script parameters
|
boolean |
updateWithQueryAndStoredScript(Date dateHint,
Class<?> clazz,
String[] scripts,
Map<String,Object>[] scriptParams,
Condition[] conditions) |
boolean |
updateWithScript(Item item,
Class<?> clazz,
String script,
Map<String,Object> scriptParams)
Updates the item of the specified class and identified by the specified identifier with a new property value for the specified property name.
|
boolean |
updateWithScript(Item item,
Date dateHint,
Class<?> clazz,
String script,
Map<String,Object> scriptParams) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
refreshIndex, update
public static final String BULK_PROCESSOR_BULK_SIZE
public static final String BULK_PROCESSOR_FLUSH_INTERVAL
public static final String BULK_PROCESSOR_BACKOFF_POLICY
public static final String SEQ_NO
public static final String PRIMARY_TERM
public void setBundleContext(org.osgi.framework.BundleContext bundleContext)
public void setClusterName(String clusterName)
public void setElasticSearchAddresses(String elasticSearchAddresses)
public void setItemTypeToRefreshPolicy(String itemTypeToRefreshPolicy) throws IOException
IOException
public void setFatalIllegalStateErrors(String fatalIllegalStateErrors)
public void setAggQueryMaxResponseSizeHttp(String aggQueryMaxResponseSizeHttp)
public void setIndexPrefix(String indexPrefix)
@Deprecated public void setMonthlyIndexNumberOfShards(String monthlyIndexNumberOfShards)
@Deprecated public void setMonthlyIndexNumberOfReplicas(String monthlyIndexNumberOfReplicas)
@Deprecated public void setMonthlyIndexMappingTotalFieldsLimit(String monthlyIndexMappingTotalFieldsLimit)
@Deprecated public void setMonthlyIndexMaxDocValueFieldsSearch(String monthlyIndexMaxDocValueFieldsSearch)
@Deprecated public void setItemsMonthlyIndexedOverride(String itemsMonthlyIndexedOverride)
public void setNumberOfShards(String numberOfShards)
public void setNumberOfReplicas(String numberOfReplicas)
public void setIndexMappingTotalFieldsLimit(String indexMappingTotalFieldsLimit)
public void setIndexMaxDocValueFieldsSearch(String indexMaxDocValueFieldsSearch)
public void setDefaultQueryLimit(Integer defaultQueryLimit)
public void setConditionEvaluatorDispatcher(ConditionEvaluatorDispatcher conditionEvaluatorDispatcher)
public void setConditionESQueryBuilderDispatcher(ConditionESQueryBuilderDispatcher conditionESQueryBuilderDispatcher)
public void setBulkProcessorConcurrentRequests(String bulkProcessorConcurrentRequests)
public void setBulkProcessorBulkActions(String bulkProcessorBulkActions)
public void setBulkProcessorBulkSize(String bulkProcessorBulkSize)
public void setBulkProcessorFlushInterval(String bulkProcessorFlushInterval)
public void setBulkProcessorBackoffPolicy(String bulkProcessorBackoffPolicy)
public void setRolloverIndices(String rolloverIndices)
public void setRolloverMaxSize(String rolloverMaxSize)
public void setRolloverMaxAge(String rolloverMaxAge)
public void setRolloverMaxDocs(String rolloverMaxDocs)
public void setRolloverIndexNumberOfShards(String rolloverIndexNumberOfShards)
public void setRolloverIndexNumberOfReplicas(String rolloverIndexNumberOfReplicas)
public void setRolloverIndexMappingTotalFieldsLimit(String rolloverIndexMappingTotalFieldsLimit)
public void setRolloverIndexMaxDocValueFieldsSearch(String rolloverIndexMaxDocValueFieldsSearch)
public void setMinimalElasticSearchVersion(String minimalElasticSearchVersion)
public void setMaximalElasticSearchVersion(String maximalElasticSearchVersion)
public void setAggregateQueryBucketSize(int aggregateQueryBucketSize)
public void setClientSocketTimeout(String clientSocketTimeout)
public void setMetricsService(MetricsService metricsService)
public void setUseBatchingForSave(boolean useBatchingForSave)
public void setUseBatchingForUpdate(boolean useBatchingForUpdate)
public void setUsername(String username)
public void setPassword(String password)
public void setSslEnable(boolean sslEnable)
public void setSslTrustAllCertificates(boolean sslTrustAllCertificates)
public void setAggQueryThrowOnMissingDocs(boolean aggQueryThrowOnMissingDocs)
public void setThrowExceptions(boolean throwExceptions)
public void setAlwaysOverwrite(boolean alwaysOverwrite)
public void setLogLevelRestClient(String logLevelRestClient)
public org.elasticsearch.action.bulk.BulkProcessor getBulkProcessor()
public void stop()
public void bindConditionEvaluator(org.osgi.framework.ServiceReference<ConditionEvaluator> conditionEvaluatorServiceReference)
public void unbindConditionEvaluator(org.osgi.framework.ServiceReference<ConditionEvaluator> conditionEvaluatorServiceReference)
public void bindConditionESQueryBuilder(org.osgi.framework.ServiceReference<ConditionESQueryBuilder> conditionESQueryBuilderServiceReference)
public void unbindConditionESQueryBuilder(org.osgi.framework.ServiceReference<ConditionESQueryBuilder> conditionESQueryBuilderServiceReference)
public void bundleChanged(org.osgi.framework.BundleEvent event)
bundleChanged
in interface org.osgi.framework.BundleListener
public <T extends Item> List<T> getAllItems(Class<T> clazz)
PersistenceService
PersistenceService.getAllItems(Class, int, int, String)
is preferred.getAllItems
in interface PersistenceService
T
- the type of the Item
s we want to retrieveclazz
- the Item
subclass of entities we want to retrievepublic long getAllItemsCount(String itemType)
PersistenceService
ITEM_TYPE
.getAllItemsCount
in interface PersistenceService
itemType
- the String representation of the item type we want to retrieve the count of, as defined by its class' ITEM_TYPE
fieldItem for a discussion of {@code ITEM_TYPE}
public <T extends Item> PartialList<T> getAllItems(Class<T> clazz, int offset, int size, String sortBy)
PersistenceService
sortBy
String and and paged: only size
of them are retrieved,
starting with the offset
-th one.
TODO: use a Query object instead of distinct parameters?
getAllItems
in interface PersistenceService
T
- the type of the Item
s we want to retrieveclazz
- the Item
subclass of entities we want to retrieveoffset
- zero or a positive integer specifying the position of the first item in the total ordered collection of matching itemssize
- a positive integer specifying how many matching items should be retrieved or -1
if all of them should be retrievedsortBy
- an optional (null
if no sorting is required) String of comma (,
) separated property names on which ordering should be performed, ordering
elements according to the property order in the
String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by
a column (:
) and an order specifier: asc
or desc
.PartialList
of pages items with the given typepublic <T extends Item> PartialList<T> getAllItems(Class<T> clazz, int offset, int size, String sortBy, String scrollTimeValidity)
PersistenceService
sortBy
String and and paged: only size
of them are retrieved,
starting with the offset
-th one.
TODO: use a Query object instead of distinct parameters?
getAllItems
in interface PersistenceService
T
- the type of the Item
s we want to retrieveclazz
- the Item
subclass of entities we want to retrieveoffset
- zero or a positive integer specifying the position of the first item in the total ordered collection of matching itemssize
- a positive integer specifying how many matching items should be retrieved or -1
if all of them should be retrievedsortBy
- an optional (null
if no sorting is required) String of comma (,
) separated property names on which ordering should be performed, ordering
elements according to the property order in the
String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by
a column (:
) and an order specifier: asc
or desc
.scrollTimeValidity
- the time the scrolling query should stay valid. This must contain a time unit value such as the ones supported by ElasticSearch, such as
* the ones declared here : https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-unitsPartialList
of pages items with the given typepublic <T extends Item> T load(String itemId, Class<T> clazz)
PersistenceService
load
in interface PersistenceService
T
- the type of the Item subclass we want to retrieveitemId
- the identifier of the item we want to retrieveclazz
- the Item
subclass of the item we want to retrievenull
otherwise@Deprecated public <T extends Item> T load(String itemId, Date dateHint, Class<T> clazz)
load
in interface PersistenceService
@Deprecated public CustomItem loadCustomItem(String itemId, Date dateHint, String customItemType)
loadCustomItem
in interface PersistenceService
public CustomItem loadCustomItem(String itemId, String customItemType)
PersistenceService
loadCustomItem
in interface PersistenceService
itemId
- the identifier of the custom type we want to retrievecustomItemType
- an identifier of the custom item type to loadnull
otherwisepublic boolean isConsistent(Item item)
PersistenceService
isConsistent
in interface PersistenceService
item
- the item to the check if consistenttrue
if the item is consistent, false otherwisepublic boolean save(Item item)
PersistenceService
save
in interface PersistenceService
item
- the item to persisttrue
if the item was properly persisted, false
otherwisepublic boolean save(Item item, boolean useBatching)
PersistenceService
save
in interface PersistenceService
item
- the item to persistuseBatching
- whether to use batching or not for saving the item. If activating there may be a delay between
the call to this method and the actual saving in the persistence backend.true
if the item was properly persisted, false
otherwisepublic boolean save(Item item, Boolean useBatchingOption, Boolean alwaysOverwriteOption)
PersistenceService
save
in interface PersistenceService
item
- the item to persistuseBatchingOption
- whether to use batching or not for saving the item. If activating there may be a delay between
the call to this method and the actual saving in the persistence backendalwaysOverwriteOption
- whether to overwrite a document even if we are holding an old item when savingtrue
if the item was properly persisted, false
otherwisepublic boolean update(Item item, Date dateHint, Class clazz, String propertyName, Object propertyValue)
update
in interface PersistenceService
public boolean update(Item item, Date dateHint, Class clazz, Map source)
update
in interface PersistenceService
public boolean update(Item item, Date dateHint, Class clazz, Map source, boolean alwaysOverwrite)
update
in interface PersistenceService
public boolean update(Item item, Class clazz, String propertyName, Object propertyValue)
PersistenceService
update(itemId, clazz, Collections.singletonMap(propertyName, propertyValue))
update
in interface PersistenceService
item
- the item we want to updateclazz
- the Item subclass of the item to updatepropertyName
- the name of the property to updatepropertyValue
- the new value of the propertytrue
if the update was successful, false
otherwisepublic boolean update(Item item, Class clazz, Map source)
PersistenceService
update
in interface PersistenceService
item
- the item we want to updateclazz
- the Item subclass of the item to updatesource
- a Map with entries specifying as key the property name to update and as value its new valuetrue
if the update was successful, false
otherwisepublic boolean update(Item item, Class clazz, Map source, boolean alwaysOverwrite)
PersistenceService
update
in interface PersistenceService
item
- the item we want to updateclazz
- the Item subclass of the item to updatesource
- a Map with entries specifying as key the property name to update and as value its new valuealwaysOverwrite
- whether to overwrite a document even if we are holding an old item when savingtrue
if the update was successful, false
otherwisepublic List<String> update(Map<Item,Map> items, Date dateHint, Class clazz)
update
in interface PersistenceService
public boolean updateWithQueryAndScript(Date dateHint, Class<?> clazz, String[] scripts, Map<String,Object>[] scriptParams, Condition[] conditions)
updateWithQueryAndScript
in interface PersistenceService
public boolean updateWithQueryAndScript(Class<?> clazz, String[] scripts, Map<String,Object>[] scriptParams, Condition[] conditions)
PersistenceService
updateWithQueryAndScript
in interface PersistenceService
clazz
- the Item subclass of the item to updatescripts
- inline scripts arrayscriptParams
- script params arrayconditions
- conditions arraytrue
if the update was successful, false
otherwisepublic boolean updateWithQueryAndStoredScript(Date dateHint, Class<?> clazz, String[] scripts, Map<String,Object>[] scriptParams, Condition[] conditions)
updateWithQueryAndStoredScript
in interface PersistenceService
public boolean updateWithQueryAndStoredScript(Class<?> clazz, String[] scripts, Map<String,Object>[] scriptParams, Condition[] conditions)
PersistenceService
updateWithQueryAndStoredScript
in interface PersistenceService
clazz
- the Item subclass of the item to updatescripts
- Stored scripts namescriptParams
- script params arrayconditions
- conditions arraytrue
if the update was successful, false
otherwisepublic boolean storeScripts(Map<String,String> scripts)
PersistenceService
storeScripts
in interface PersistenceService
scripts
- inline scripts map indexed by idtrue
if the update was successful, false
otherwisepublic boolean updateWithScript(Item item, Date dateHint, Class<?> clazz, String script, Map<String,Object> scriptParams)
updateWithScript
in interface PersistenceService
public boolean updateWithScript(Item item, Class<?> clazz, String script, Map<String,Object> scriptParams)
PersistenceService
update(itemId, clazz, Collections.singletonMap(propertyName, propertyValue))
updateWithScript
in interface PersistenceService
item
- the item we want to updateclazz
- the Item subclass of the item to updatescript
- inline scriptscriptParams
- script paramstrue
if the update was successful, false
otherwisepublic <T extends Item> boolean remove(String itemId, Class<T> clazz)
PersistenceService
remove
in interface PersistenceService
T
- the type of the Item subclass we want to deleteitemId
- the identifier of the item we want to deleteclazz
- the Item
subclass of the item we want to deletetrue
if the deletion was successful, false
otherwisepublic boolean removeCustomItem(String itemId, String customItemType)
PersistenceService
removeCustomItem
in interface PersistenceService
itemId
- the identifier of the custom item to be removedcustomItemType
- the name of the custom item typetrue
if the deletion was successful, false
otherwisepublic <T extends Item> boolean removeByQuery(Condition query, Class<T> clazz)
PersistenceService
Condition
.removeByQuery
in interface PersistenceService
T
- the type of the Item subclass we want to deletequery
- a Condition
identifying which elements we want to deleteclazz
- the Item
subclass of the items we want to deletetrue
if the deletion was successful, false
otherwisepublic <T extends Item> boolean removeByQuery(org.elasticsearch.index.query.QueryBuilder queryBuilder, Class<T> clazz) throws Exception
Exception
public boolean indexTemplateExists(String templateName)
public boolean removeIndexTemplate(String templateName)
public boolean registerRolloverLifecyclePolicy()
public boolean createIndex(String itemType)
PersistenceService
TODO: remove from API?
createIndex
in interface PersistenceService
itemType
- the item typetrue
if the operation was successful, false
otherwisepublic boolean removeIndex(String itemType)
PersistenceService
TODO: remove from API?
removeIndex
in interface PersistenceService
itemType
- the item typetrue
if the operation was successful, false
otherwisepublic void createMapping(String type, String source)
PersistenceService
createMapping
in interface PersistenceService
type
- the typesource
- the sourcepublic void setPropertyMapping(PropertyType property, String itemType)
PersistenceService
setPropertyMapping
in interface PersistenceService
property
- the PropertyType to create mapping foritemType
- the itemType we want to retrieve the mappings forpublic Map<String,Map<String,Object>> getPropertiesMapping(String itemType)
PersistenceService
This method may not return any results if the implementation doesn't support property type mappings
getPropertiesMapping
in interface PersistenceService
itemType
- the itemType we want to retrieve the mappings forpublic Map<String,Object> getPropertyMapping(String property, String itemType)
PersistenceService
getPropertyMapping
in interface PersistenceService
property
- the property name (can use nested dot notation)itemType
- the itemType we want to retrieve the mappings forpublic boolean saveQuery(String queryName, Condition query)
PersistenceService
saveQuery
in interface PersistenceService
queryName
- the name under which the specified query should be recordedquery
- the query to be recordedtrue
if the query was properly saved, false
otherwisepublic boolean removeQuery(String queryName)
PersistenceService
removeQuery
in interface PersistenceService
queryName
- the name under which the specified query was recordedtrue
if the deletion was successful, false
otherwisepublic boolean isValidCondition(Condition condition, Item item)
PersistenceService
isValidCondition
in interface PersistenceService
condition
- the condition we're testing the specified item againstitem
- the item we're checking against the specified conditiontrue
if the item satisfies the condition, false
otherwisepublic boolean testMatch(Condition query, Item item)
PersistenceService
TODO: rename to isMatching?
testMatch
in interface PersistenceService
query
- the condition we're testing the specified item againstitem
- the item we're checking against the specified conditiontrue
if the item satisfies the condition, false
otherwisepublic <T extends Item> List<T> query(Condition query, String sortBy, Class<T> clazz)
PersistenceService
query(query, sortBy, clazz, 0, -1).getList()
query
in interface PersistenceService
T
- the type of the Item subclass we want to retrievequery
- the Condition
the items must satisfy to be retrievedsortBy
- an optional (null
if no sorting is required) String of comma (,
) separated property names on which ordering should be performed, ordering
elements according to the property order in the
String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by
a column (:
) and an order specifier: asc
or desc
.clazz
- the Item
subclass of the items we want to retrievePartialList
of items matching the specified criteriaPersistenceService.query(Condition, String, Class, int, int)
public <T extends Item> PartialList<T> query(Condition query, String sortBy, Class<T> clazz, int offset, int size)
PersistenceService
Condition
, ordered according to the specified sortBy
String and and paged: only size
of them
are retrieved, starting with the offset
-th one.query
in interface PersistenceService
T
- the type of the Item subclass we want to retrievequery
- the Condition
the items must satisfy to be retrievedsortBy
- an optional (null
if no sorting is required) String of comma (,
) separated property names on which ordering should be performed, ordering
elements according to the property order in the
String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by
a column (:
) and an order specifier: asc
or desc
.clazz
- the Item
subclass of the items we want to retrieveoffset
- zero or a positive integer specifying the position of the first item in the total ordered collection of matching itemssize
- a positive integer specifying how many matching items should be retrieved or -1
if all of them should be retrievedPartialList
of items matching the specified criteriapublic <T extends Item> PartialList<T> query(Condition query, String sortBy, Class<T> clazz, int offset, int size, String scrollTimeValidity)
PersistenceService
Condition
, ordered according to the specified sortBy
String and and paged: only size
of them
are retrieved, starting with the offset
-th one. If a scroll identifier and time validity are specified, they will be used to perform a scrolling query, meaning
that only partial results will be returned, but the scrolling can be continued.query
in interface PersistenceService
T
- the type of the Item subclass we want to retrievequery
- the Condition
the items must satisfy to be retrievedsortBy
- an optional (null
if no sorting is required) String of comma (,
) separated property names on which ordering should be performed, ordering
elements according to the property order in the
String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by
a column (:
) and an order specifier: asc
or desc
.clazz
- the Item
subclass of the items we want to retrieveoffset
- zero or a positive integer specifying the position of the first item in the total ordered collection of matching itemssize
- a positive integer specifying how many matching items should be retrieved or -1
if all of them should be retrieved. In the case of a scroll query
this will be used as the scrolling window size.scrollTimeValidity
- the time the scrolling query should stay valid. This must contain a time unit value such as the ones supported by ElasticSearch, such as
the ones declared here : https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-unitsPartialList
of items matching the specified criteria, with an scroll identifier and the scroll validity used if a scroll query was requested.public PartialList<CustomItem> queryCustomItem(Condition query, String sortBy, String customItemType, int offset, int size, String scrollTimeValidity)
PersistenceService
Condition
, ordered according to the specified
sortBy
String and paged: only size
of them are retrieved, starting with the
offset
-th one. If a scroll identifier and time validity are specified, they will be used to perform a
scrolling query, meaning that only partial results will be returned, but the scrolling can be continued.queryCustomItem
in interface PersistenceService
query
- the Condition
the items must satisfy to be retrievedsortBy
- an optional (null
if no sorting is required) String of comma (,
) separated property names on which ordering should be performed, ordering
elements according to the property order in the
String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by
a column (:
) and an order specifier: asc
or desc
.customItemType
- the identifier of the custom item type we want to queryoffset
- zero or a positive integer specifying the position of the first item in the total ordered collection of matching itemssize
- a positive integer specifying how many matching items should be retrieved or -1
if all of them should be retrieved. In the case of a scroll query
this will be used as the scrolling window size.scrollTimeValidity
- the time the scrolling query should stay valid. This must contain a time unit value such as the ones supported by ElasticSearch, such as
the ones declared here : https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-unitsPartialList
of items matching the specified criteria, with an scroll identifier and the scroll validity used if a scroll query was requested.public <T extends Item> PartialList<T> queryFullText(String fulltext, Condition query, String sortBy, Class<T> clazz, int offset, int size)
PersistenceService
query(query, sortBy, clazz, 0, -1)
with the added constraints that the matching elements must also have at least a field matching the
specified full text query.queryFullText
in interface PersistenceService
T
- the type of the Item subclass we want to retrievefulltext
- the text that the item must have in one of its fields to be considered a matchquery
- the Condition
the items must satisfy to be retrievedsortBy
- an optional (null
if no sorting is required) String of comma (,
) separated property names on which ordering should be performed, ordering
elements according to the property order in the
String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by
a column (:
) and an order specifier: asc
or desc
.clazz
- the Item
subclass of the items we want to retrieveoffset
- zero or a positive integer specifying the position of the first item in the total ordered collection of matching itemssize
- a positive integer specifying how many matching items should be retrieved or -1
if all of them should be retrievedPartialList
of items matching the specified criteriapublic <T extends Item> List<T> query(String fieldName, String fieldValue, String sortBy, Class<T> clazz)
PersistenceService
query(fieldName, fieldValue, sortBy, clazz, 0, -1).getList()
query
in interface PersistenceService
T
- the type of the Item subclass we want to retrievefieldName
- the name of the field which we want items to have the specified valuesfieldValue
- the value the items to retrieve should have for the specified fieldsortBy
- an optional (null
if no sorting is required) String of comma (,
) separated property names on which ordering should be performed, ordering
elements according to the property order in the
String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by
a column (:
) and an order specifier: asc
or desc
.clazz
- the Item
subclass of the items we want to retrievePersistenceService.query(Condition, String, Class, int, int)
public <T extends Item> List<T> query(String fieldName, String[] fieldValues, String sortBy, Class<T> clazz)
PersistenceService
query
in interface PersistenceService
T
- the type of the Item subclass we want to retrievefieldName
- the name of the field which we want items to have the specified valuesfieldValues
- the values the items to retrieve should have for the specified fieldsortBy
- an optional (null
if no sorting is required) String of comma (,
) separated property names on which ordering should be performed, ordering
elements according to the property order in the
String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by
a column (:
) and an order specifier: asc
or desc
.clazz
- the Item
subclass of the items we want to retrievepublic <T extends Item> PartialList<T> query(String fieldName, String fieldValue, String sortBy, Class<T> clazz, int offset, int size)
PersistenceService
query
in interface PersistenceService
T
- the type of the Item subclass we want to retrievefieldName
- the name of the field which we want items to have the specified valuefieldValue
- the value the items to retrieve should have for the specified fieldsortBy
- an optional (null
if no sorting is required) String of comma (,
) separated property names on which ordering should be performed, ordering
elements according to the property order in the
String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by
a column (:
) and an order specifier: asc
or desc
.clazz
- the Item
subclass of the items we want to retrieveoffset
- zero or a positive integer specifying the position of the first item in the total ordered collection of matching itemssize
- a positive integer specifying how many matching items should be retrieved or -1
if all of them should be retrievedPartialList
of items matching the specified criteriapublic <T extends Item> PartialList<T> queryFullText(String fieldName, String fieldValue, String fulltext, String sortBy, Class<T> clazz, int offset, int size)
PersistenceService
sortBy
String and and paged: only size
of them are retrieved, starting with the offset
-th one.queryFullText
in interface PersistenceService
T
- the type of the Item subclass we want to retrievefieldName
- the name of the field which we want items to have the specified valuefieldValue
- the value the items to retrieve should have for the specified fieldfulltext
- the text that the item must have in one of its fields to be considered a matchsortBy
- an optional (null
if no sorting is required) String of comma (,
) separated property names on which ordering should be performed, ordering
elements according to the property order in the
String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by
a column (:
) and an order specifier: asc
or desc
.clazz
- the Item
subclass of the items we want to retrieveoffset
- zero or a positive integer specifying the position of the first item in the total ordered collection of matching itemssize
- a positive integer specifying how many matching items should be retrieved or -1
if all of them should be retrievedPartialList
of items matching the specified criteriapublic <T extends Item> PartialList<T> queryFullText(String fulltext, String sortBy, Class<T> clazz, int offset, int size)
PersistenceService
sortBy
String and and paged: only
size
of them are retrieved, starting with the offset
-th one.queryFullText
in interface PersistenceService
T
- the type of the Item subclass we want to retrievefulltext
- the text that the item must have in one of its fields to be considered a matchsortBy
- an optional (null
if no sorting is required) String of comma (,
) separated property names on which ordering should be performed, ordering
elements according to the property order in the
String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by
a column (:
) and an order specifier: asc
or desc
.clazz
- the Item
subclass of the items we want to retrieveoffset
- zero or a positive integer specifying the position of the first item in the total ordered collection of matching itemssize
- a positive integer specifying how many matching items should be retrieved or -1
if all of them should be retrievedPartialList
of items matching the specified criteriapublic <T extends Item> PartialList<T> rangeQuery(String fieldName, String from, String to, String sortBy, Class<T> clazz, int offset, int size)
PersistenceService
sortBy
String
and and paged: only size
of them are retrieved, starting with the offset
-th one.rangeQuery
in interface PersistenceService
T
- the type of the Item subclass we want to retrievefieldName
- the name of the range property we want items to retrieve to be included between the specified start and end pointsfrom
- the beginning of the range we want to considerto
- the end of the range we want to considersortBy
- an optional (null
if no sorting is required) String of comma (,
) separated property names on which ordering should be performed, ordering
elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones.
Each property name is optionally followed by a column (:
) and an order specifier: asc
or desc
.clazz
- the Item
subclass of the items we want to retrieveoffset
- zero or a positive integer specifying the position of the first item in the total ordered collection of matching itemssize
- a positive integer specifying how many matching items should be retrieved or -1
if all of them should be retrievedPartialList
of items matching the specified criteriapublic long queryCount(Condition query, String itemType)
PersistenceService
ITEM_TYPE
and matching the specified Condition
.queryCount
in interface PersistenceService
query
- the condition the items must satisfyitemType
- the String representation of the item type we want to retrieve the count of, as defined by its class' ITEM_TYPE
fieldItem for a discussion of {@code ITEM_TYPE}
public <T extends Item> PartialList<T> continueScrollQuery(Class<T> clazz, String scrollIdentifier, String scrollTimeValidity)
PersistenceService
continueScrollQuery
in interface PersistenceService
T
- the type of the Item subclass we want to retrieveclazz
- the Item
subclass of the items we want to retrievescrollIdentifier
- a scroll identifier obtained by the execution of a first query and returned in the PartialList
objectscrollTimeValidity
- a scroll time validity value for the scroll query to stay valid. This must contain a time unit value such as the ones supported by ElasticSearch, such as
the ones declared here : https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-unitsPartialList
of items matching the specified criteria, with an scroll identifier and the scroll validity used if a scroll query was requested. Note that if
there are no more results the list will be empty but not null.public PartialList<CustomItem> continueCustomItemScrollQuery(String customItemType, String scrollIdentifier, String scrollTimeValidity)
PersistenceService
continueCustomItemScrollQuery
in interface PersistenceService
customItemType
- the identifier of the custom item type we want to continue queryingscrollIdentifier
- a scroll identifier obtained by the execution of a first query and returned in the PartialList
objectscrollTimeValidity
- a scroll time validity value for the scroll query to stay valid. This must contain a time unit value such as the ones supported by ElasticSearch, such as
the ones declared here : https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-unitsPartialList
of items matching the specified criteria, with an scroll identifier and the scroll validity used if a scroll query was requested. Note that if
there are no more results the list will be empty but not null.@Deprecated public Map<String,Long> aggregateQuery(Condition filter, BaseAggregate aggregate, String itemType)
aggregateWithOptimizedQuery(Condition, BaseAggregate, String)
insteadPersistenceService
ITEM_TYPE
matching the optional specified condition and
aggregated according to the specified BaseAggregate
.
Also return the global count of document matching the ITEM_TYPE
aggregateQuery
in interface PersistenceService
filter
- the condition the items must match or null
if no filtering is neededaggregate
- an aggregate specifying how matching items must be bundleditemType
- the String representation of the item type we want to retrieve the count of, as defined by its class' ITEM_TYPE
fieldpublic Map<String,Long> aggregateWithOptimizedQuery(Condition filter, BaseAggregate aggregate, String itemType)
PersistenceService
ITEM_TYPE
matching the optional specified condition and
aggregated according to the specified BaseAggregate
.
This aggregate won't return the global count and should therefore be much faster than PersistenceService.aggregateQuery(Condition, BaseAggregate, String)
aggregateWithOptimizedQuery
in interface PersistenceService
filter
- the condition the items must match or null
if no filtering is neededaggregate
- an aggregate specifying how matching items must be bundleditemType
- the String representation of the item type we want to retrieve the count of, as defined by its class' ITEM_TYPE
fieldpublic Map<String,Long> aggregateWithOptimizedQuery(Condition filter, BaseAggregate aggregate, String itemType, int size)
PersistenceService
ITEM_TYPE
matching the optional specified condition and
aggregated according to the specified BaseAggregate
.aggregateWithOptimizedQuery
in interface PersistenceService
filter
- the condition the items must match or null
if no filtering is neededaggregate
- an aggregate specifying how matching items must be bundleditemType
- the String representation of the item type we want to retrieve the count of, as defined by its class' ITEM_TYPE
fieldsize
- size of returned buckets in the responsepublic void refresh()
PersistenceService
refresh
in interface PersistenceService
public <T extends Item> void refreshIndex(Class<T> clazz, Date dateHint)
refreshIndex
in interface PersistenceService
public void purge(Date date)
PersistenceService
purge
in interface PersistenceService
public <T extends Item> void purgeTimeBasedItems(int existsNumberOfDays, Class<T> clazz)
PersistenceService
purgeTimeBasedItems
in interface PersistenceService
existsNumberOfDays
- the number of daysclazz
- the item type to be purgedpublic void purge(String scope)
PersistenceService
purge
in interface PersistenceService
scope
- the scope for which we want to remove datapublic Map<String,Double> getSingleValuesMetrics(Condition condition, String[] metrics, String field, String itemType)
PersistenceService
ITEM_TYPE
and matching the
specified Condition
.getSingleValuesMetrics
in interface PersistenceService
condition
- the condition the items must satisfymetrics
- a String array which metrics should be computed (possible values: sum
for the sum of the values, avg
for the average of the values, min
for the minimum value and max
for the maximum value)field
- the name of the field for which the metrics should be computeditemType
- the String representation of the item type we want to retrieve the count of, as defined by its class' ITEM_TYPE
fieldCopyright © 2014–2023 Apache Software Foundation. All rights reserved.