public abstract class AbstractElasticsearchTemplate extends Object implements ElasticsearchOperations, ApplicationContextAware
| 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 org.springframework.data.elasticsearch.core.RequestFactory |
requestFactory |
protected RoutingResolver |
routingResolver |
| Constructor and Description |
|---|
AbstractElasticsearchTemplate() |
| 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.
|
protected List<IndexedObjectInformation> |
checkForBulkOperationFailure(org.elasticsearch.action.bulk.BulkResponse bulkResponse) |
long |
count(Query query,
Class<?> clazz)
return number of elements found by given query
|
protected ElasticsearchConverter |
createElasticsearchConverter() |
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() |
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) |
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() |
String |
getEntityRouting(Object entity)
gets the routing for an entity which might be defined by a join-type relation
|
IndexCoordinates |
getIndexCoordinatesFor(Class<?> clazz) |
protected abstract org.elasticsearch.action.search.MultiSearchResponse.Item[] |
getMultiSearchResult(org.elasticsearch.action.search.MultiSearchRequest request) |
RefreshPolicy |
getRefreshPolicy() |
org.springframework.data.elasticsearch.core.RequestFactory |
getRequestFactory() |
String |
index(IndexQuery query,
IndexCoordinates index)
Index an object.
|
protected void |
initialize(ElasticsearchConverter elasticsearchConverter) |
protected <T> T |
maybeCallbackAfterConvert(T entity,
Document document,
IndexCoordinates index) |
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> List<SearchHits<T>> |
multiSearch(List<? extends Query> queries,
Class<T> clazz,
IndexCoordinates index)
Execute the multi search query against elasticsearch and return result as
List of SearchHits. |
List<SearchHits<?>> |
multiSearch(List<? extends Query> queries,
List<Class<?>> classes)
Execute the multi search query against elasticsearch and return result as
List of SearchHits. |
List<SearchHits<?>> |
multiSearch(List<? extends Query> queries,
List<Class<?>> classes,
IndexCoordinates index)
Execute the multi search query against elasticsearch and return result as
List of SearchHits. |
protected <R extends org.elasticsearch.action.support.WriteRequest<R>> |
prepareWriteRequest(R request)
Pre process the write request before it is sent to the server, eg. by setting the
refresh policy if applicable. |
protected <R extends org.elasticsearch.action.support.WriteRequestBuilder<R>> |
prepareWriteRequestBuilder(R requestBuilder)
Pre process the write request before it is sent to the server, eg. by setting the
refresh policy if applicable. |
<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) |
org.elasticsearch.action.search.SearchResponse |
suggest(org.elasticsearch.search.suggest.SuggestBuilder suggestion,
Class<?> clazz)
Does a suggest query
|
protected static String[] |
toArray(List<String> values) |
protected void |
updateIndexedObject(Object entity,
IndexedObjectInformation indexedObjectInformation) |
protected void |
updateIndexedObjectsWithQueries(List<?> queries,
List<IndexedObjectInformation> indexedObjectInformations) |
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, update, updateByQuery@Nullable protected ElasticsearchConverter elasticsearchConverter
@Nullable protected org.springframework.data.elasticsearch.core.RequestFactory requestFactory
@Nullable protected RoutingResolver routingResolver
protected void initialize(ElasticsearchConverter elasticsearchConverter)
protected abstract AbstractElasticsearchTemplate doCopy()
protected ElasticsearchConverter createElasticsearchConverter()
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 <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 nullpublic <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 returnedMultiGetItemspublic 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)
protected <R extends org.elasticsearch.action.support.WriteRequest<R>> R prepareWriteRequest(R request)
refresh policy if applicable.R - request - must not be null.WriteRequest.protected <R extends org.elasticsearch.action.support.WriteRequestBuilder<R>> R prepareWriteRequestBuilder(R requestBuilder)
refresh policy if applicable.R - requestBuilder - must not be null.WriteRequest.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 againstpublic <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> List<SearchHits<T>> multiSearch(List<? extends Query> queries, Class<T> clazz, IndexCoordinates index)
SearchOperationsList of SearchHits.multiSearch in interface SearchOperationsT - element return typequeries - the queries to executeclazz - the entity clazz used for property mappingindex - the index to run the query againstpublic List<SearchHits<?>> multiSearch(List<? extends Query> queries, List<Class<?>> classes)
SearchOperationsList of SearchHits.multiSearch in interface SearchOperationsqueries - the queries to executeclasses - the entity classespublic List<SearchHits<?>> multiSearch(List<? extends Query> queries, List<Class<?>> classes, IndexCoordinates index)
SearchOperationsList of SearchHits.multiSearch in interface SearchOperationsqueries - the queries to executeclasses - the entity classes used for property mappingindex - the index to run the query againstpublic <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(@Nullable String scrollId, long scrollTimeInMillis, Class<T> clazz, IndexCoordinates index)
protected void searchScrollClear(String scrollId)
protected abstract org.elasticsearch.action.search.MultiSearchResponse.Item[] getMultiSearchResult(org.elasticsearch.action.search.MultiSearchRequest request)
public org.elasticsearch.action.search.SearchResponse suggest(org.elasticsearch.search.suggest.SuggestBuilder suggestion,
Class<?> clazz)
SearchOperationssuggest in interface SearchOperationssuggestion - the queryclazz - the entity classpublic ElasticsearchConverter getElasticsearchConverter()
getElasticsearchConverter in interface ElasticsearchOperationspublic org.springframework.data.elasticsearch.core.RequestFactory getRequestFactory()
public IndexCoordinates getIndexCoordinatesFor(Class<?> clazz)
getIndexCoordinatesFor in interface ElasticsearchOperationsclazz - the entity classprotected List<IndexedObjectInformation> checkForBulkOperationFailure(org.elasticsearch.action.bulk.BulkResponse bulkResponse)
bulkResponse - protected void updateIndexedObject(Object entity, IndexedObjectInformation indexedObjectInformation)
@Nullable public String getEntityRouting(Object entity)
ElasticsearchOperationsgetEntityRouting in interface ElasticsearchOperationsentity - the entity@Nullable protected abstract String getClusterVersion()
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 void updateIndexedObjectsWithQueries(List<?> queries, List<IndexedObjectInformation> indexedObjectInformations)
public ElasticsearchOperations withRouting(RoutingResolver routingResolver)
ElasticsearchOperationsRoutingResolver to
obtain routing information.withRouting in interface ElasticsearchOperationsroutingResolver - the RoutingResolver value, must not be null.Copyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.