Interface SearchIndexingPlan
This class is stateful: it queues operations internally to apply them at a later time.
When process()
is called,
or when indexing listeners are enabled
and a Hibernate ORM Session flush()
happens,
the entities will be processed and index documents will be built
and stored in an internal buffer.
When execute()
is called,
or when indexing listeners are enabled
and a Hibernate ORM transaction is committed or a Hibernate ORM Session flush()
happens outside of any transaction,
the operations will be actually sent to the index.
Note that execute()
will implicitly trigger processing of documents that weren't processed yet,
if any, so calling process()
is not necessary if you call execute()
just next.
process()
and execute()
are mostly useful when listener-triggered indexing is disabled,
to control the indexing process explicitly.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addOrUpdate
(Object entity) Add or update a document in the index if the entity type is mapped to an index (Indexed
), and re-index documents that embed this entity (throughIndexedEmbedded
for example).void
Delete the entity from the index if the entity type is mapped to an index (Indexed
), and re-index documents that embed this entity (throughIndexedEmbedded
for example).void
execute()
Write all pending changes to the index now, without waiting for a Hibernate ORM flush event or transaction commit.void
process()
Extract all data from objects passed to the indexing plan so far, creates documents to be indexed and put them into an internal buffer, without writing them to the indexes.void
Delete the entity from the index.void
Delete the entity from the index.
-
Method Details
-
addOrUpdate
Add or update a document in the index if the entity type is mapped to an index (Indexed
), and re-index documents that embed this entity (throughIndexedEmbedded
for example).- Parameters:
entity
- The entity to add or update in the index.- Throws:
SearchException
- If the entity type is not indexed, neither directly (Indexed
) nor through another indexed type that embeds it (IndexedEmbedded
for example).
-
delete
Delete the entity from the index if the entity type is mapped to an index (Indexed
), and re-index documents that embed this entity (throughIndexedEmbedded
for example).- Parameters:
entity
- The entity to delete from the index.- Throws:
SearchException
- If the entity type is not indexed, neither directly (Indexed
) nor through another indexed type that embeds it (IndexedEmbedded
for example).
-
purge
Delete the entity from the index.On contrary to
delete(Object)
, if documents embed this entity (throughIndexedEmbedded
for example), these documents will not be re-indexed, leaving the indexes in an inconsistent state until they are re-indexed manually.- Parameters:
entityClass
- The class of the entity to delete from the index.providedId
- A value to extract the document ID from. Generally the expected value is the entity ID, but a different value may be expected depending on the mapping.providedRoutingKey
- The routing key to route the purge request to the appropriate index shard. Leavenull
if sharding is disabled or does not rely on custom routing keys.- Throws:
SearchException
- If the entity type is not indexed directly (Indexed
).
-
purge
Delete the entity from the index.On contrary to
delete(Object)
, if documents embed this entity (throughIndexedEmbedded
for example), these documents will not be re-indexed, leaving the indexes in an inconsistent state until they are re-indexed manually.- Parameters:
entityName
- An entity name. SeeEntity.name()
.providedId
- A value to extract the document ID from. Generally the expected value is the entity ID, but a different value may be expected depending on the mapping.providedRoutingKey
- The routing key to route the purge request to the appropriate index shard. Leavenull
if sharding is disabled or does not rely on custom routing keys.- Throws:
SearchException
- If the entity type is not indexed directly (Indexed
).
-
process
void process()Extract all data from objects passed to the indexing plan so far, creates documents to be indexed and put them into an internal buffer, without writing them to the indexes.Calling this method is optional: the
execute()
method or the automatic write on transaction commit will perform the extraction as necessary.However, calling this method can be useful before a session is cleared if
indexing listeners
are disabled: it will make sure the data lost when clearing the session will no longer be necessary for indexing.Caution: calling this method repeatedly without a call to
execute()
will add more and more data to an internal document buffer, which may lead to anOutOfMemoryError
. Use with caution in batch processes. -
execute
void execute()Write all pending changes to the index now, without waiting for a Hibernate ORM flush event or transaction commit.If a transaction is active and is ultimately rolled back, the written changes will not be rolled back, causing indexes to become out of sync with the database. Thus, calling this method should generally be avoided, and relying on automatic write on transaction commit should be preferred.
-