Class ElasticsearchTemplate
java.lang.Object
org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate
org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate
- All Implemented Interfaces:
Aware,ApplicationContextAware,DocumentOperations,ElasticsearchOperations,SearchOperations
Implementation of
ElasticsearchOperations using the new
Elasticsearch client.- Since:
- 4.4
- Author:
- Peter-Josef Meisch
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback interface to be used withexecute(ElasticsearchTemplate.ClientCallback)for operating directly on theElasticsearchClient.Nested classes/interfaces inherited from class org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate
AbstractElasticsearchTemplate.DocumentCallback<T>, AbstractElasticsearchTemplate.ReadDocumentCallback<T>, AbstractElasticsearchTemplate.ReadSearchDocumentResponseCallback<T>, AbstractElasticsearchTemplate.ReadSearchScrollDocumentResponseCallback<T>, AbstractElasticsearchTemplate.SearchDocumentResponseCallback<T> -
Field Summary
Fields inherited from class org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate
elasticsearchConverter, entityCallbacks, entityOperations, refreshPolicy, routingResolver -
Constructor Summary
ConstructorsConstructorDescriptionElasticsearchTemplate(co.elastic.clients.elasticsearch.ElasticsearchClient client) ElasticsearchTemplate(co.elastic.clients.elasticsearch.ElasticsearchClient client, ElasticsearchConverter elasticsearchConverter) -
Method Summary
Modifier and TypeMethodDescriptionvoidbulkUpdate(List<UpdateQuery> queries, BulkOptions bulkOptions, IndexCoordinates index) Bulk update all objects.protected List<IndexedObjectInformation>checkForBulkOperationFailure(co.elastic.clients.elasticsearch.core.BulkResponse bulkResponse) extract the list ofIndexedObjectInformationfrom aBulkResponse.closePointInTime(String pit) Closes a point in timecluster()return aClusterOperationsinstance that uses the same client communication setup as this ElasticsearchOperations instance.longcount(Query query, Class<?> clazz, IndexCoordinates index) return number of elements found by given querydelete(Query query, Class<?> clazz, IndexCoordinates index) Delete all records matching the query.doBulkOperation(List<?> queries, BulkOptions bulkOptions, IndexCoordinates index) protected AbstractElasticsearchTemplatedoCopy()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 StringdoDelete(String id, String routing, IndexCoordinates index) protected booleandoExists(String id, IndexCoordinates index) doIndex(IndexQuery query, IndexCoordinates indexCoordinates) protected <T> SearchHits<T>doSearch(MoreLikeThisQuery query, Class<T> clazz, IndexCoordinates index) <T> Texecute(ElasticsearchTemplate.ClientCallback<T> callback) Execute a callback with theElasticsearchClientand provide exception translation.<T> Tget(String id, Class<T> clazz, IndexCoordinates index) Retrieves an object from the index specified in the entity's Document annotation.tries to extract the version of the Elasticsearch clusterCreates aQueryto find get all documents with given ids.get anIndexOperationsthat is bound to the given classindexOps(IndexCoordinates index) get anIndexOperationsthat is bound to the given indexCreates aQueryto get all documents.<T> List<MultiGetItem<T>>multiGet(Query query, Class<T> clazz, IndexCoordinates index) Execute a multiGet against elasticsearch for the given ids.<T> List<SearchHits<T>>multiSearch(List<? extends Query> queries, Class<T> clazz, IndexCoordinates index) Execute the multi search query against elasticsearch and return result asListofSearchHits.List<SearchHits<?>>multiSearch(List<? extends Query> queries, List<Class<?>> classes) Execute the multi search query against elasticsearch and return result asListofSearchHits.List<SearchHits<?>>multiSearch(List<? extends Query> queries, List<Class<?>> classes, IndexCoordinates index) Execute the multi search query against elasticsearch and return result asListofSearchHits.openPointInTime(IndexCoordinates index, Duration keepAlive, Boolean ignoreUnavailable) Opens a point in time (pit) in Elasticsearch.reindex(ReindexRequest reindexRequest) Copies documents from a source to a destination.<T> SearchHits<T>search(Query query, Class<T> clazz, IndexCoordinates index) Execute the criteria query against elasticsearch and return result asSearchHitsvoidsearchScrollClear(List<String> scrollIds) <T> SearchScrollHits<T>searchScrollContinue(String scrollId, long scrollTimeInMillis, Class<T> clazz, IndexCoordinates index) <T> SearchScrollHits<T>searchScrollStart(long scrollTimeInMillis, Query query, Class<T> clazz, IndexCoordinates index) submitReindex(ReindexRequest reindexRequest) Submits a reindex task.update(UpdateQuery updateQuery, IndexCoordinates index) Partial update of the document.updateByQuery(UpdateQuery updateQuery, IndexCoordinates index) Update document(s) by queryMethods inherited from class org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate
buildUpdateQueryByEntity, bulkIndex, bulkIndex, bulkIndex, bulkOperation, bulkUpdate, count, delete, delete, delete, delete, delete, exists, exists, get, getElasticsearchConverter, getEntityCreator, getEntityRouting, getIndexCoordinatesFor, getRefreshPolicy, index, logVersions, maybeCallbackAfterConvert, maybeCallbackAfterLoad, maybeCallbackAfterSave, maybeCallbackAfterSaveWithQueries, maybeCallbackAfterSaveWithQuery, maybeCallbackBeforeConvert, maybeCallbackBeforeConvertWithQueries, maybeCallbackBeforeConvertWithQuery, multiGet, multiSearch, save, save, save, save, save, search, search, search, searchForStream, searchForStream, searchScrollClear, setApplicationContext, setEntityCallbacks, setRefreshPolicy, toArray, update, updateIndexedObject, updateIndexedObjectsWithQueries, withRoutingMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.data.elasticsearch.core.DocumentOperations
bulkIndex, bulkUpdateMethods inherited from interface org.springframework.data.elasticsearch.core.ElasticsearchOperations
convertId, stringIdRepresentationMethods inherited from interface org.springframework.data.elasticsearch.core.SearchOperations
count, openPointInTime, searchOne, searchOne
-
Constructor Details
-
ElasticsearchTemplate
public ElasticsearchTemplate(co.elastic.clients.elasticsearch.ElasticsearchClient client) -
ElasticsearchTemplate
public ElasticsearchTemplate(co.elastic.clients.elasticsearch.ElasticsearchClient client, ElasticsearchConverter elasticsearchConverter)
-
-
Method Details
-
doCopy
Description copied from class:AbstractElasticsearchTemplatemust return a copy of this instance that will for example be used to set a custom routing resolver without modifying the original object.- Specified by:
doCopyin classAbstractElasticsearchTemplate
-
indexOps
Description copied from interface:ElasticsearchOperationsget anIndexOperationsthat is bound to the given class- Returns:
- IndexOperations
-
indexOps
Description copied from interface:ElasticsearchOperationsget anIndexOperationsthat is bound to the given index- Returns:
- IndexOperations
-
cluster
Description copied from interface:ElasticsearchOperationsreturn aClusterOperationsinstance that uses the same client communication setup as this ElasticsearchOperations instance.- Returns:
- ClusterOperations implementation
-
get
Description copied from interface:DocumentOperationsRetrieves an object from the index specified in the entity's Document annotation.- Parameters:
id- the id of the objectclazz- the entity class,index- the index from which the object is read.- Returns:
- the entity
-
multiGet
Description copied from interface:DocumentOperationsExecute a multiGet against elasticsearch for the given ids.- Parameters:
query- the query defining the ids of the objects to getclazz- the type of the object to be returnedindex- the index(es) from which the objects are read.- Returns:
- list of
MultiGetItems - See Also:
-
bulkUpdate
Description copied from interface:DocumentOperationsBulk update all objects. Will do update.- Parameters:
queries- the queries to execute in bulkbulkOptions- options to be added to the bulk request
-
delete
Description copied from interface:DocumentOperationsDelete all records matching the query.- Parameters:
query- query defining the objectsclazz- The entity class, must be annotated withDocumentindex- the index from which to delete- Returns:
- response with detailed information
-
update
Description copied from interface:DocumentOperationsPartial update of the document.- Parameters:
updateQuery- query defining the updateindex- the index where to update the records- Returns:
- the update response
-
updateByQuery
Description copied from interface:DocumentOperationsUpdate document(s) by query- Parameters:
updateQuery- query defining the update, must not be nullindex- the index where to update the records , must not be null- Returns:
- the update response
-
doIndex
- Specified by:
doIndexin classAbstractElasticsearchTemplate
-
doExists
- Specified by:
doExistsin classAbstractElasticsearchTemplate
-
doDelete
- Specified by:
doDeletein classAbstractElasticsearchTemplate
-
reindex
Description copied from interface:DocumentOperationsCopies documents from a source to a destination. The source can be any existing index, alias, or data stream. The destination must differ from the source. For example, you cannot reindex a data stream into itself. (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)- Parameters:
reindexRequest- reindex request parameters- Returns:
- the reindex response
-
submitReindex
Description copied from interface:DocumentOperationsSubmits a reindex task. (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)- Parameters:
reindexRequest- reindex request parameters- Returns:
- the task id
-
doBulkOperation
public List<IndexedObjectInformation> doBulkOperation(List<?> queries, BulkOptions bulkOptions, IndexCoordinates index) - Specified by:
doBulkOperationin classAbstractElasticsearchTemplate
-
getClusterVersion
Description copied from class:AbstractElasticsearchTemplatetries to extract the version of the Elasticsearch cluster- Specified by:
getClusterVersionin classAbstractElasticsearchTemplate- Returns:
- the version as string if it can be retrieved
-
getVendor
- Specified by:
getVendorin classAbstractElasticsearchTemplate- Returns:
- the vendor name of the used cluster and client library
-
getRuntimeLibraryVersion
- Specified by:
getRuntimeLibraryVersionin classAbstractElasticsearchTemplate- Returns:
- the version of the used client runtime library.
-
count
Description copied from interface:SearchOperationsreturn number of elements found by given query- Parameters:
query- the query to executeclazz- the entity clazz used for property mappingindex- the index to run the query against- Returns:
- count
-
search
Description copied from interface:SearchOperationsExecute the criteria query against elasticsearch and return result asSearchHits- Type Parameters:
T- element return type- Parameters:
query- the query to executeclazz- the entity clazz used for property mappingindex- the index to run the query against- Returns:
- SearchHits containing the list of found objects
-
doSearch
protected <T> SearchHits<T> doSearch(MoreLikeThisQuery query, Class<T> clazz, IndexCoordinates index) - Specified by:
doSearchin classAbstractElasticsearchTemplate
-
searchScrollStart
public <T> SearchScrollHits<T> searchScrollStart(long scrollTimeInMillis, Query query, Class<T> clazz, IndexCoordinates index) - Specified by:
searchScrollStartin classAbstractElasticsearchTemplate
-
searchScrollContinue
public <T> SearchScrollHits<T> searchScrollContinue(String scrollId, long scrollTimeInMillis, Class<T> clazz, IndexCoordinates index) - Specified by:
searchScrollContinuein classAbstractElasticsearchTemplate
-
searchScrollClear
- Specified by:
searchScrollClearin classAbstractElasticsearchTemplate
-
multiSearch
public <T> List<SearchHits<T>> multiSearch(List<? extends Query> queries, Class<T> clazz, IndexCoordinates index) Description copied from interface:SearchOperationsExecute the multi search query against elasticsearch and return result asListofSearchHits.- Type Parameters:
T- element return type- Parameters:
queries- the queries to executeclazz- the entity clazz used for property mappingindex- the index to run the query against- Returns:
- list of SearchHits
-
multiSearch
Description copied from interface:SearchOperationsExecute the multi search query against elasticsearch and return result asListofSearchHits.- Parameters:
queries- the queries to executeclasses- the entity classes- Returns:
- list of SearchHits
-
multiSearch
public List<SearchHits<?>> multiSearch(List<? extends Query> queries, List<Class<?>> classes, IndexCoordinates index) Description copied from interface:SearchOperationsExecute the multi search query against elasticsearch and return result asListofSearchHits.- Parameters:
queries- the queries to executeclasses- the entity classes used for property mappingindex- the index to run the query against- Returns:
- list of SearchHits
-
openPointInTime
public String openPointInTime(IndexCoordinates index, Duration keepAlive, Boolean ignoreUnavailable) Description copied from interface:SearchOperationsOpens a point in time (pit) in Elasticsearch.- Specified by:
openPointInTimein interfaceSearchOperations- Overrides:
openPointInTimein classAbstractElasticsearchTemplate- Parameters:
index- the index name(s) to usekeepAlive- the duration the pit shoult be kept aliveignoreUnavailable- if {$literal true} the call will fail if any of the indices is missing or closed- Returns:
- the pit identifier
-
closePointInTime
Description copied from interface:SearchOperationsCloses a point in time- Specified by:
closePointInTimein interfaceSearchOperations- Overrides:
closePointInTimein classAbstractElasticsearchTemplate- Parameters:
pit- the pit identifier as returned bySearchOperations.openPointInTime(IndexCoordinates, Duration, Boolean)- Returns:
- true on success
-
execute
Execute a callback with theElasticsearchClientand provide exception translation.- Type Parameters:
T- the type returned from the callback- Parameters:
callback- the callback to execute, must not be null- Returns:
- the callback result
-
matchAllQuery
Description copied from interface:SearchOperationsCreates aQueryto get all documents. Must be implemented by the concrete implementations to provide an appropriate query using the respective client.- Returns:
- a query to find all documents
-
idsQuery
Description copied from interface:SearchOperationsCreates aQueryto find get all documents with given ids. Must be implemented by the concrete implementations to provide an appropriate query using the respective client.- Parameters:
ids- the list of ids must not be null- Returns:
- query returning the documents with the given ids
-
checkForBulkOperationFailure
protected List<IndexedObjectInformation> checkForBulkOperationFailure(co.elastic.clients.elasticsearch.core.BulkResponse bulkResponse) extract the list ofIndexedObjectInformationfrom aBulkResponse.- Parameters:
bulkResponse- the response to evaluate- Returns:
- the list of the
IndexedObjectInformations
-