public abstract class AbstractElasticsearchTemplate extends Object implements ElasticsearchOperations, ApplicationContextAware
ElasticsearchOperations
interface that use different clients, like RestHighLevelClient and the next Java client from Elasticsearch or some
future implementation that might use an Opensearch client. This class must not contain imports or use classes that
are specific to one of these implementations.
Note: Although this class is public, it is not considered to be part of the official Spring Data Elasticsearch API and so might change at any time.
| Modifier and Type | Class and Description |
|---|---|
protected static interface |
AbstractElasticsearchTemplate.DocumentCallback<T> |
protected class |
AbstractElasticsearchTemplate.ReadDocumentCallback<T> |
protected class |
AbstractElasticsearchTemplate.ReadSearchDocumentResponseCallback<T> |
protected class |
AbstractElasticsearchTemplate.ReadSearchScrollDocumentResponseCallback<T> |
protected static interface |
AbstractElasticsearchTemplate.SearchDocumentResponseCallback<T> |
| Modifier and Type | Field and Description |
|---|---|
protected ElasticsearchConverter |
elasticsearchConverter |
protected EntityCallbacks |
entityCallbacks |
protected EntityOperations |
entityOperations |
protected RefreshPolicy |
refreshPolicy |
protected RoutingResolver |
routingResolver |
| Constructor and Description |
|---|
AbstractElasticsearchTemplate() |
AbstractElasticsearchTemplate(ElasticsearchConverter elasticsearchConverter) |
| Modifier and Type | Method and Description |
|---|---|
List<IndexedObjectInformation> |
bulkIndex(List<IndexQuery> queries,
BulkOptions bulkOptions,
Class<?> clazz)
Bulk index all objects.
|
List<IndexedObjectInformation> |
bulkIndex(List<IndexQuery> queries,
BulkOptions bulkOptions,
IndexCoordinates index)
Bulk index all objects.
|
List<IndexedObjectInformation> |
bulkIndex(List<IndexQuery> queries,
Class<?> clazz)
Bulk index all objects.
|
List<IndexedObjectInformation> |
bulkOperation(List<?> queries,
BulkOptions bulkOptions,
IndexCoordinates index) |
void |
bulkUpdate(List<UpdateQuery> queries,
Class<?> clazz)
Bulk update all objects.
|
long |
count(Query query,
Class<?> clazz)
return number of elements found by given query
|
String |
delete(Object entity)
Deletes the given entity
|
String |
delete(Object entity,
IndexCoordinates index)
Deletes the given entity
|
ByQueryResponse |
delete(Query query,
Class<?> clazz)
Delete all records matching the query.
|
String |
delete(String id,
Class<?> entityType)
Delete the one object with provided id.
|
String |
delete(String id,
IndexCoordinates index)
Delete the one object with provided id.
|
String |
delete(String id,
String routing,
IndexCoordinates index)
Deprecated.
|
abstract List<IndexedObjectInformation> |
doBulkOperation(List<?> queries,
BulkOptions bulkOptions,
IndexCoordinates index) |
protected abstract AbstractElasticsearchTemplate |
doCopy()
must return a copy of this instance that will for example be used to set a custom routing resolver without
modifying the original object.
|
protected abstract String |
doDelete(String id,
String routing,
IndexCoordinates index) |
protected abstract boolean |
doExists(String id,
IndexCoordinates index) |
abstract String |
doIndex(IndexQuery query,
IndexCoordinates indexCoordinates) |
protected abstract <T> SearchHits<T> |
doSearch(MoreLikeThisQuery query,
Class<T> clazz,
IndexCoordinates index) |
boolean |
exists(String id,
Class<?> clazz)
Check if an entity with given id exists.
|
boolean |
exists(String id,
IndexCoordinates index)
Check if an entity with given id exists.
|
<T> T |
get(String id,
Class<T> clazz)
Retrieves an object from the index specified in the entity's Document annotation.
|
protected abstract String |
getClusterVersion()
tries to extract the version of the Elasticsearch cluster
|
ElasticsearchConverter |
getElasticsearchConverter() |
protected <T> SearchDocumentResponse.EntityCreator<T> |
getEntityCreator(AbstractElasticsearchTemplate.ReadDocumentCallback<T> documentCallback) |
String |
getEntityRouting(Object entity)
gets the routing for an entity which might be defined by a join-type relation
|
IndexCoordinates |
getIndexCoordinatesFor(Class<?> clazz) |
RefreshPolicy |
getRefreshPolicy() |
protected abstract String |
getRuntimeLibraryVersion() |
protected abstract String |
getVendor() |
String |
index(IndexQuery query,
IndexCoordinates index)
Index an object.
|
void |
logVersions()
logs the versions of the different Elasticsearch components.
|
protected <T> T |
maybeCallbackAfterConvert(T entity,
Document document,
IndexCoordinates index) |
protected <T> Document |
maybeCallbackAfterLoad(Document document,
Class<T> type,
IndexCoordinates indexCoordinates) |
protected <T> T |
maybeCallbackAfterSave(T entity,
IndexCoordinates index) |
protected void |
maybeCallbackAfterSaveWithQueries(List<?> queries,
IndexCoordinates index) |
protected void |
maybeCallbackAfterSaveWithQuery(Object query,
IndexCoordinates index) |
protected <T> T |
maybeCallbackBeforeConvert(T entity,
IndexCoordinates index) |
protected void |
maybeCallbackBeforeConvertWithQueries(List<?> queries,
IndexCoordinates index) |
protected void |
maybeCallbackBeforeConvertWithQuery(Object query,
IndexCoordinates index) |
<T> List<MultiGetItem<T>> |
multiGet(Query query,
Class<T> clazz)
Execute a multiGet against elasticsearch for the given ids.
|
<T> List<SearchHits<T>> |
multiSearch(List<? extends Query> queries,
Class<T> clazz)
Execute the multi search query against elasticsearch and return result as
List of SearchHits. |
<T> Iterable<T> |
save(Iterable<T> entities)
saves the given entities to the index retrieved from the entities' Document annotation
|
<T> Iterable<T> |
save(Iterable<T> entities,
IndexCoordinates index)
saves the given entities to the given index
|
<T> Iterable<T> |
save(T... entities)
saves the given entities to the index retrieved from the entities' Document annotation
|
<T> T |
save(T entity)
Saves an entity to the index specified in the entity's Document annotation
|
<T> T |
save(T entity,
IndexCoordinates index)
Saves an entity to the index specified in the entity's Document annotation
|
<T> SearchHits<T> |
search(MoreLikeThisQuery query,
Class<T> clazz)
more like this query to search for documents that are "like" a specific document.
|
<T> SearchHits<T> |
search(MoreLikeThisQuery query,
Class<T> clazz,
IndexCoordinates index)
more like this query to search for documents that are "like" a specific document.
|
<T> SearchHits<T> |
search(Query query,
Class<T> clazz)
Execute the criteria query against elasticsearch and return result as
SearchHits |
<T> SearchHitsIterator<T> |
searchForStream(Query query,
Class<T> clazz)
Executes the given
Query against elasticsearch and return result as SearchHitsIterator. |
<T> SearchHitsIterator<T> |
searchForStream(Query query,
Class<T> clazz,
IndexCoordinates index)
Executes the given
Query against elasticsearch and return result as SearchHitsIterator. |
protected abstract void |
searchScrollClear(List<String> scrollIds) |
protected void |
searchScrollClear(String scrollId) |
protected abstract <T> SearchScrollHits<T> |
searchScrollContinue(String scrollId,
long scrollTimeInMillis,
Class<T> clazz,
IndexCoordinates index) |
protected abstract <T> SearchScrollHits<T> |
searchScrollStart(long scrollTimeInMillis,
Query query,
Class<T> clazz,
IndexCoordinates index) |
void |
setApplicationContext(ApplicationContext applicationContext) |
void |
setEntityCallbacks(EntityCallbacks entityCallbacks)
|
void |
setRefreshPolicy(RefreshPolicy refreshPolicy) |
protected static String[] |
toArray(List<String> values) |
protected <T> T |
updateIndexedObject(T entity,
IndexedObjectInformation indexedObjectInformation) |
protected void |
updateIndexedObjectsWithQueries(List<?> queries,
List<IndexedObjectInformation> indexedObjectInformationList) |
ElasticsearchOperations |
withRouting(RoutingResolver routingResolver)
Returns a copy of this instance with the same configuration, but that uses a different
RoutingResolver to
obtain routing information. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcluster, indexOps, indexOps, stringIdRepresentationbulkIndex, bulkUpdate, bulkUpdate, delete, get, multiGet, reindex, submitReindex, update, updateByQuerycount, count, idsQuery, matchAllQuery, multiSearch, multiSearch, multiSearch, search, searchOne, searchOne, suggest, suggestprotected ElasticsearchConverter elasticsearchConverter
protected EntityOperations entityOperations
@Nullable protected EntityCallbacks entityCallbacks
@Nullable protected RefreshPolicy refreshPolicy
protected RoutingResolver routingResolver
public AbstractElasticsearchTemplate()
public AbstractElasticsearchTemplate(@Nullable ElasticsearchConverter elasticsearchConverter)
protected abstract AbstractElasticsearchTemplate doCopy()
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
setApplicationContext in interface ApplicationContextAwareBeansExceptionpublic void setEntityCallbacks(EntityCallbacks entityCallbacks)
EntityCallbacks instance to use when invoking callbacks like the
BeforeConvertCallback.
Overrides potentially existing EntityCallbacks.entityCallbacks - must not be null.IllegalArgumentException - if the given instance is null.public void setRefreshPolicy(@Nullable RefreshPolicy refreshPolicy)
@Nullable public RefreshPolicy getRefreshPolicy()
public void logVersions()
public <T> T save(T entity)
DocumentOperationssave in interface DocumentOperationsT - the entity typeentity - the entity to save, must not be nullpublic <T> T save(T entity,
IndexCoordinates index)
DocumentOperationssave in interface DocumentOperationsT - the entity typeentity - the entity to save, must not be nullindex - the index to save the entity in, must not be nullpublic <T> Iterable<T> save(Iterable<T> entities)
DocumentOperationssave in interface DocumentOperationsT - the entity typeentities - must not be nullpublic <T> Iterable<T> save(Iterable<T> entities, IndexCoordinates index)
DocumentOperationssave in interface DocumentOperationsT - the entity typeentities - must not be nullindex - the index to save the entities in, must not be null@SafeVarargs public final <T> Iterable<T> save(T... entities)
DocumentOperationssave in interface DocumentOperationsT - the entity typeentities - must not be nullpublic String index(IndexQuery query, IndexCoordinates index)
DocumentOperationsindex in interface DocumentOperationsquery - the query defining the objectindex - the index where the object is stored.public abstract String doIndex(IndexQuery query, IndexCoordinates indexCoordinates)
@Nullable public <T> T get(String id, Class<T> clazz)
DocumentOperationsget in interface DocumentOperationsT - the entity typeid - the id of the objectclazz - the entity class,public <T> List<MultiGetItem<T>> multiGet(Query query, Class<T> clazz)
DocumentOperationsmultiGet in interface DocumentOperationsquery - the query defining the ids of the objects to getclazz - the type of the object to be returnedMultiGetItemsQuery.multiGetQuery(Collection),
Query.multiGetQueryWithRouting(List)public boolean exists(String id, Class<?> clazz)
DocumentOperationsexists in interface DocumentOperationsid - the _id of the document to look for.clazz - the domain type used.public boolean exists(String id, IndexCoordinates index)
DocumentOperationsexists in interface DocumentOperationsid - the _id of the document to look for.index - the target index, must not be nullprotected abstract boolean doExists(String id, IndexCoordinates index)
public String delete(String id, Class<?> entityType)
DocumentOperationsdelete in interface DocumentOperationsid - the document ot deleteentityType - must not be null.public ByQueryResponse delete(Query query, Class<?> clazz)
DocumentOperationsdelete in interface DocumentOperationsquery - query defining the objectsclazz - The entity class, must be annotated with
Documentpublic String delete(Object entity)
DocumentOperationsdelete in interface DocumentOperationsentity - the entity to deletepublic String delete(Object entity, IndexCoordinates index)
DocumentOperationsdelete in interface DocumentOperationsentity - the entity to deleteindex - the index from which to deletepublic String delete(String id, IndexCoordinates index)
DocumentOperationsdelete in interface DocumentOperationsid - the document to deleteindex - the index from which to delete@Deprecated public final String delete(String id, @Nullable String routing, IndexCoordinates index)
DocumentOperationsdelete in interface DocumentOperationsid - the document to deleterouting - the optional routing for the document to be deletedindex - the index from which to deleteprotected abstract String doDelete(String id, @Nullable String routing, IndexCoordinates index)
public List<IndexedObjectInformation> bulkIndex(List<IndexQuery> queries, Class<?> clazz)
DocumentOperationsbulkIndex in interface DocumentOperationsqueries - the queries to execute in bulkclazz - the entity classpublic List<IndexedObjectInformation> bulkIndex(List<IndexQuery> queries, BulkOptions bulkOptions, Class<?> clazz)
DocumentOperationsbulkIndex in interface DocumentOperationsqueries - the queries to execute in bulkbulkOptions - options to be added to the bulk requestclazz - the entity classpublic final List<IndexedObjectInformation> bulkIndex(List<IndexQuery> queries, BulkOptions bulkOptions, IndexCoordinates index)
DocumentOperationsbulkIndex in interface DocumentOperationsqueries - the queries to execute in bulkbulkOptions - options to be added to the bulk requestpublic void bulkUpdate(List<UpdateQuery> queries, Class<?> clazz)
DocumentOperationsbulkUpdate in interface DocumentOperationsqueries - the queries to execute in bulkclazz - the entity classpublic List<IndexedObjectInformation> bulkOperation(List<?> queries, BulkOptions bulkOptions, IndexCoordinates index)
public abstract List<IndexedObjectInformation> doBulkOperation(List<?> queries, BulkOptions bulkOptions, IndexCoordinates index)
public long count(Query query, Class<?> clazz)
SearchOperationscount in interface SearchOperationsquery - the query to executeclazz - the entity clazz used for property mapping and index name extractionpublic <T> SearchHitsIterator<T> searchForStream(Query query, Class<T> clazz)
SearchOperationsQuery against elasticsearch and return result as SearchHitsIterator.
searchForStream in interface SearchOperationsT - element return typequery - the query to executeclazz - the entity clazz used for property mapping and index name extractionSearchHitsIterator that wraps an Elasticsearch scroll context that needs to be closed. The
try-with-resources construct should be used to ensure that the close method is invoked after the operations
are completed.public <T> SearchHitsIterator<T> searchForStream(Query query, Class<T> clazz, IndexCoordinates index)
SearchOperationsQuery against elasticsearch and return result as SearchHitsIterator.
searchForStream in interface SearchOperationsT - element return typequery - the query to executeclazz - the entity clazz used for property mappingindex - the index to run the query againstSearchHitsIterator that wraps an Elasticsearch scroll context that needs to be closed. The
try-with-resources construct should be used to ensure that the close method is invoked after the operations
are completed.public <T> SearchHits<T> search(MoreLikeThisQuery query, Class<T> clazz)
SearchOperationssearch in interface SearchOperationsT - element return typequery - the query to executeclazz - the entity clazz used for property mapping and index name extractionpublic <T> SearchHits<T> search(MoreLikeThisQuery query, Class<T> clazz, IndexCoordinates index)
SearchOperationssearch in interface SearchOperationsT - element return typequery - the query to executeclazz - the entity clazz used for property mappingindex - the index to run the query againstprotected abstract <T> SearchHits<T> doSearch(MoreLikeThisQuery query, Class<T> clazz, IndexCoordinates index)
public <T> List<SearchHits<T>> multiSearch(List<? extends Query> queries, Class<T> clazz)
SearchOperationsList of SearchHits.multiSearch in interface SearchOperationsT - element return typequeries - the queries to executeclazz - the entity clazzpublic <T> SearchHits<T> search(Query query, Class<T> clazz)
SearchOperationsSearchHitssearch in interface SearchOperationsT - element return typequery - the query to executeclazz - the entity clazz used for property mapping and index name extractionprotected abstract <T> SearchScrollHits<T> searchScrollStart(long scrollTimeInMillis, Query query, Class<T> clazz, IndexCoordinates index)
protected abstract <T> SearchScrollHits<T> searchScrollContinue(String scrollId, long scrollTimeInMillis, Class<T> clazz, IndexCoordinates index)
protected void searchScrollClear(String scrollId)
public ElasticsearchConverter getElasticsearchConverter()
getElasticsearchConverter in interface ElasticsearchOperationspublic IndexCoordinates getIndexCoordinatesFor(Class<?> clazz)
getIndexCoordinatesFor in interface ElasticsearchOperationsclazz - the entity classprotected <T> T updateIndexedObject(T entity,
IndexedObjectInformation indexedObjectInformation)
@Nullable public String getEntityRouting(Object entity)
ElasticsearchOperationsgetEntityRouting in interface ElasticsearchOperationsentity - the entityprotected <T> SearchDocumentResponse.EntityCreator<T> getEntityCreator(AbstractElasticsearchTemplate.ReadDocumentCallback<T> documentCallback)
@Nullable protected abstract String getClusterVersion()
protected abstract String getVendor()
protected abstract String getRuntimeLibraryVersion()
protected <T> T maybeCallbackBeforeConvert(T entity,
IndexCoordinates index)
protected void maybeCallbackBeforeConvertWithQuery(Object query, IndexCoordinates index)
protected void maybeCallbackBeforeConvertWithQueries(List<?> queries, IndexCoordinates index)
protected <T> T maybeCallbackAfterSave(T entity,
IndexCoordinates index)
protected void maybeCallbackAfterSaveWithQuery(Object query, IndexCoordinates index)
protected void maybeCallbackAfterSaveWithQueries(List<?> queries, IndexCoordinates index)
protected <T> T maybeCallbackAfterConvert(T entity,
Document document,
IndexCoordinates index)
protected <T> Document maybeCallbackAfterLoad(Document document, Class<T> type, IndexCoordinates indexCoordinates)
protected void updateIndexedObjectsWithQueries(List<?> queries, List<IndexedObjectInformation> indexedObjectInformationList)
public ElasticsearchOperations withRouting(RoutingResolver routingResolver)
ElasticsearchOperationsRoutingResolver to
obtain routing information.withRouting in interface ElasticsearchOperationsroutingResolver - the RoutingResolver value, must not be null.Copyright © 2011–2022 Pivotal Software, Inc.. All rights reserved.