public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate
Modifier and Type | Class and Description |
---|---|
static interface |
ElasticsearchRestTemplate.ClientCallback<T>
Callback interface to be used with
execute(ClientCallback) for operating directly on
RestHighLevelClient . |
AbstractElasticsearchTemplate.DocumentCallback<T>, AbstractElasticsearchTemplate.ReadDocumentCallback<T>, AbstractElasticsearchTemplate.ReadSearchDocumentResponseCallback<T>, AbstractElasticsearchTemplate.ReadSearchScrollDocumentResponseCallback<T>, AbstractElasticsearchTemplate.SearchDocumentResponseCallback<T>
Modifier and Type | Field and Description |
---|---|
protected org.springframework.data.elasticsearch.core.RequestFactory |
requestFactory |
elasticsearchConverter, entityCallbacks, entityOperations, refreshPolicy, routingResolver
Constructor and Description |
---|
ElasticsearchRestTemplate(org.elasticsearch.client.RestHighLevelClient client) |
ElasticsearchRestTemplate(org.elasticsearch.client.RestHighLevelClient client,
ElasticsearchConverter elasticsearchConverter) |
Modifier and Type | Method and Description |
---|---|
void |
bulkUpdate(List<UpdateQuery> queries,
BulkOptions bulkOptions,
IndexCoordinates index)
Bulk update all objects.
|
protected List<IndexedObjectInformation> |
checkForBulkOperationFailure(org.elasticsearch.action.bulk.BulkResponse bulkResponse)
extract the list of
IndexedObjectInformation from a BulkResponse . |
ClusterOperations |
cluster()
return a
ClusterOperations instance that uses the same client communication setup as this
ElasticsearchOperations instance. |
long |
count(Query query,
Class<?> clazz,
IndexCoordinates index)
return number of elements found by given query
|
ByQueryResponse |
delete(Query query,
Class<?> clazz,
IndexCoordinates index)
Delete all records matching the query.
|
List<IndexedObjectInformation> |
doBulkOperation(List<?> queries,
BulkOptions bulkOptions,
IndexCoordinates index) |
protected 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 String |
doDelete(String id,
String routing,
IndexCoordinates index) |
protected boolean |
doExists(String id,
IndexCoordinates index) |
String |
doIndex(IndexQuery query,
IndexCoordinates index) |
protected <T> SearchHits<T> |
doSearch(MoreLikeThisQuery query,
Class<T> clazz,
IndexCoordinates index) |
<T> T |
execute(ElasticsearchRestTemplate.ClientCallback<T> callback)
Execute a callback with the
RestHighLevelClient |
<T> T |
get(String id,
Class<T> clazz,
IndexCoordinates index)
Retrieves an object from the index specified in the entity's Document annotation.
|
protected String |
getClusterVersion()
tries to extract the version of the Elasticsearch cluster
|
protected org.elasticsearch.action.search.MultiSearchResponse.Item[] |
getMultiSearchResult(org.elasticsearch.action.search.MultiSearchRequest request) |
org.springframework.data.elasticsearch.core.RequestFactory |
getRequestFactory() |
protected String |
getRuntimeLibraryVersion() |
protected String |
getVendor() |
Query |
idsQuery(List<String> ids)
Creates a
Query to find get all documents with given ids. |
IndexOperations |
indexOps(Class<?> clazz)
get an
IndexOperations that is bound to the given class |
IndexOperations |
indexOps(IndexCoordinates index)
get an
IndexOperations that is bound to the given index |
Query |
matchAllQuery()
Creates a
Query to 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 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)
Preprocess the write request before it is sent to the server, e.g. by setting the
refresh policy if applicable. |
ReindexResponse |
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 as
SearchHits |
void |
searchScrollClear(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) |
String |
submitReindex(ReindexRequest reindexRequest)
Submits a reindex task.
|
org.elasticsearch.action.search.SearchResponse |
suggest(org.elasticsearch.search.suggest.SuggestBuilder suggestion,
Class<?> clazz)
Deprecated.
|
org.elasticsearch.action.search.SearchResponse |
suggest(org.elasticsearch.search.suggest.SuggestBuilder suggestion,
IndexCoordinates index)
Does a suggest query
|
UpdateResponse |
update(UpdateQuery query,
IndexCoordinates index)
Partial update of the document.
|
ByQueryResponse |
updateByQuery(UpdateQuery query,
IndexCoordinates index)
Update document(s) by query
|
bulkIndex, bulkIndex, bulkIndex, bulkOperation, bulkUpdate, count, delete, 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, updateIndexedObject, updateIndexedObjectsWithQueries, withRouting
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
stringIdRepresentation
bulkIndex, bulkUpdate
count, searchOne, searchOne
protected org.springframework.data.elasticsearch.core.RequestFactory requestFactory
public ElasticsearchRestTemplate(org.elasticsearch.client.RestHighLevelClient client)
public ElasticsearchRestTemplate(org.elasticsearch.client.RestHighLevelClient client, ElasticsearchConverter elasticsearchConverter)
protected AbstractElasticsearchTemplate doCopy()
AbstractElasticsearchTemplate
doCopy
in class AbstractElasticsearchTemplate
public org.springframework.data.elasticsearch.core.RequestFactory getRequestFactory()
public IndexOperations indexOps(Class<?> clazz)
ElasticsearchOperations
IndexOperations
that is bound to the given classpublic IndexOperations indexOps(IndexCoordinates index)
ElasticsearchOperations
IndexOperations
that is bound to the given indexpublic ClusterOperations cluster()
ElasticsearchOperations
ClusterOperations
instance that uses the same client communication setup as this
ElasticsearchOperations instance.public String doIndex(IndexQuery query, IndexCoordinates index)
doIndex
in class AbstractElasticsearchTemplate
@Nullable public <T> T get(String id, Class<T> clazz, IndexCoordinates index)
DocumentOperations
id
- the id of the objectclazz
- the entity class,index
- the index from which the object is read.public <T> List<MultiGetItem<T>> multiGet(Query query, Class<T> clazz, IndexCoordinates index)
DocumentOperations
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.MultiGetItem
sQuery.multiGetQuery(Collection)
,
Query.multiGetQueryWithRouting(List)
protected boolean doExists(String id, IndexCoordinates index)
doExists
in class AbstractElasticsearchTemplate
public void bulkUpdate(List<UpdateQuery> queries, BulkOptions bulkOptions, IndexCoordinates index)
DocumentOperations
queries
- the queries to execute in bulkbulkOptions
- options to be added to the bulk requestprotected String doDelete(String id, @Nullable String routing, IndexCoordinates index)
doDelete
in class AbstractElasticsearchTemplate
public ByQueryResponse delete(Query query, Class<?> clazz, IndexCoordinates index)
DocumentOperations
query
- query defining the objectsclazz
- The entity class, must be annotated with
Document
index
- the index from which to deletepublic UpdateResponse update(UpdateQuery query, IndexCoordinates index)
DocumentOperations
query
- query defining the updateindex
- the index where to update the recordspublic ByQueryResponse updateByQuery(UpdateQuery query, IndexCoordinates index)
DocumentOperations
query
- query defining the update, must not be nullindex
- the index where to update the records , must not be nullpublic ReindexResponse reindex(ReindexRequest reindexRequest)
DocumentOperations
reindexRequest
- reindex request parameterspublic String submitReindex(ReindexRequest reindexRequest)
DocumentOperations
reindexRequest
- reindex request parameterspublic List<IndexedObjectInformation> doBulkOperation(List<?> queries, BulkOptions bulkOptions, IndexCoordinates index)
doBulkOperation
in class AbstractElasticsearchTemplate
protected <R extends org.elasticsearch.action.support.WriteRequest<R>> R prepareWriteRequest(R request)
refresh policy
if applicable.R
- the request typerequest
- must not be null.WriteRequest
.protected List<IndexedObjectInformation> checkForBulkOperationFailure(org.elasticsearch.action.bulk.BulkResponse bulkResponse)
IndexedObjectInformation
from a BulkResponse
.bulkResponse
- the response to evaluateIndexedObjectInformation
spublic long count(Query query, @Nullable Class<?> clazz, IndexCoordinates index)
SearchOperations
query
- the query to executeclazz
- the entity clazz used for property mappingindex
- the index to run the query againstpublic <T> SearchHits<T> search(Query query, Class<T> clazz, IndexCoordinates index)
SearchOperations
SearchHits
T
- element return typequery
- the query to executeclazz
- the entity clazz used for property mappingindex
- the index to run the query againstprotected <T> SearchHits<T> doSearch(MoreLikeThisQuery query, Class<T> clazz, IndexCoordinates index)
doSearch
in class AbstractElasticsearchTemplate
public <T> SearchScrollHits<T> searchScrollStart(long scrollTimeInMillis, Query query, Class<T> clazz, IndexCoordinates index)
searchScrollStart
in class AbstractElasticsearchTemplate
public <T> SearchScrollHits<T> searchScrollContinue(String scrollId, long scrollTimeInMillis, Class<T> clazz, IndexCoordinates index)
searchScrollContinue
in class AbstractElasticsearchTemplate
public void searchScrollClear(List<String> scrollIds)
searchScrollClear
in class AbstractElasticsearchTemplate
public org.elasticsearch.action.search.SearchResponse suggest(org.elasticsearch.search.suggest.SuggestBuilder suggestion, IndexCoordinates index)
SearchOperations
suggestion
- the queryindex
- the index to run the query againstpublic <T> List<SearchHits<T>> multiSearch(List<? extends Query> queries, Class<T> clazz, IndexCoordinates index)
SearchOperations
List
of SearchHits
.T
- 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)
SearchOperations
List
of SearchHits
.queries
- the queries to executeclasses
- the entity classespublic List<SearchHits<?>> multiSearch(List<? extends Query> queries, List<Class<?>> classes, IndexCoordinates index)
SearchOperations
List
of SearchHits
.queries
- the queries to executeclasses
- the entity classes used for property mappingindex
- the index to run the query againstprotected org.elasticsearch.action.search.MultiSearchResponse.Item[] getMultiSearchResult(org.elasticsearch.action.search.MultiSearchRequest request)
public <T> T execute(ElasticsearchRestTemplate.ClientCallback<T> callback)
RestHighLevelClient
T
- the type returned from the callbackcallback
- the callback to execute, must not be nullprotected String getClusterVersion()
AbstractElasticsearchTemplate
getClusterVersion
in class AbstractElasticsearchTemplate
public Query matchAllQuery()
SearchOperations
Query
to get all documents. Must be implemented by the concrete implementations to provide an
appropriate query using the respective client.public Query idsQuery(List<String> ids)
SearchOperations
Query
to find get all documents with given ids. Must be implemented by the concrete
implementations to provide an appropriate query using the respective client.ids
- the list of ids must not be nullprotected String getVendor()
getVendor
in class AbstractElasticsearchTemplate
protected String getRuntimeLibraryVersion()
getRuntimeLibraryVersion
in class AbstractElasticsearchTemplate
@Deprecated public org.elasticsearch.action.search.SearchResponse suggest(org.elasticsearch.search.suggest.SuggestBuilder suggestion, Class<?> clazz)
SearchOperations
suggestion
- the queryclazz
- the entity classCopyright © 2011–2022 Pivotal Software, Inc.. All rights reserved.