Interface SearchOperations
- All Known Subinterfaces:
ElasticsearchOperations
- All Known Implementing Classes:
AbstractElasticsearchTemplate
,ElasticsearchRestTemplate
,ElasticsearchTemplate
public interface SearchOperations
The operations for the
Elasticsearch Document
APIs.
- Since:
- 4.0
- Author:
- Peter-Josef Meisch, Sascha Woo
-
Method Summary
Modifier and TypeMethodDescriptionlong
return number of elements found by given querylong
count
(Query query, Class<?> clazz, IndexCoordinates index) return number of elements found by given querydefault long
count
(Query query, IndexCoordinates index) Return number of elements found by given query.Creates aQuery
to find get all documents with given ids.Creates aQuery
to get all documents.<T> List<SearchHits<T>>
multiSearch
(List<? extends Query> queries, Class<T> clazz) Execute the multi search query against elasticsearch and return result asList
ofSearchHits
.<T> List<SearchHits<T>>
multiSearch
(List<? extends Query> queries, Class<T> clazz, IndexCoordinates index) Execute the multi search query against elasticsearch and return result asList
ofSearchHits
.List<SearchHits<?>>
multiSearch
(List<? extends Query> queries, List<Class<?>> classes) Execute the multi search query against elasticsearch and return result asList
ofSearchHits
.List<SearchHits<?>>
multiSearch
(List<? extends Query> queries, List<Class<?>> classes, IndexCoordinates index) Execute the multi search query against elasticsearch and return result asList
ofSearchHits
.<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>
Execute the criteria query against elasticsearch and return result asSearchHits
<T> SearchHits<T>
search
(Query query, Class<T> clazz, IndexCoordinates index) Execute the criteria query against elasticsearch and return result asSearchHits
<T> SearchHitsIterator<T>
searchForStream
(Query query, Class<T> clazz) Executes the givenQuery
against elasticsearch and return result asSearchHitsIterator
.<T> SearchHitsIterator<T>
searchForStream
(Query query, Class<T> clazz, IndexCoordinates index) Executes the givenQuery
against elasticsearch and return result asSearchHitsIterator
.default <T> SearchHit<T>
Execute the query against elasticsearch and return the first returned object.default <T> SearchHit<T>
searchOne
(Query query, Class<T> clazz, IndexCoordinates index) Execute the query against elasticsearch and return the first returned object.default org.elasticsearch.action.search.SearchResponse
Deprecated.default org.elasticsearch.action.search.SearchResponse
suggest
(org.elasticsearch.search.suggest.SuggestBuilder suggestion, IndexCoordinates index) Deprecated.since 4.3 use aNativeSearchQueryBuilder
withNativeSearchQueryBuilder.withSuggestBuilder(SuggestBuilder)
, callsearch(Query, Class)
and get the suggest fromSearchHits.getSuggest()
-
Method Details
-
count
Return number of elements found by given query.- Parameters:
query
- the query to executeindex
- the index to run the query against- Returns:
- count
-
count
return number of elements found by given query- Parameters:
query
- the query to executeclazz
- the entity clazz used for property mapping and index name extraction- Returns:
- count
-
count
return 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
-
suggest
@Deprecated default org.elasticsearch.action.search.SearchResponse suggest(org.elasticsearch.search.suggest.SuggestBuilder suggestion, Class<?> clazz) Deprecated.since 4.3 use aNativeSearchQueryBuilder
withNativeSearchQueryBuilder.withSuggestBuilder(SuggestBuilder)
, callsearch(Query, Class)
and get the suggest fromSearchHits.getSuggest()
Does a suggest query- Parameters:
suggestion
- the queryclazz
- the entity class- Returns:
- the suggest response
- Since:
- 4.1
-
suggest
@Deprecated default org.elasticsearch.action.search.SearchResponse suggest(org.elasticsearch.search.suggest.SuggestBuilder suggestion, IndexCoordinates index) Deprecated.since 4.3 use aNativeSearchQueryBuilder
withNativeSearchQueryBuilder.withSuggestBuilder(SuggestBuilder)
, callsearch(Query, Class)
and get the suggest fromSearchHits.getSuggest()
Does a suggest query- Parameters:
suggestion
- the queryindex
- the index to run the query against- Returns:
- the suggest response
-
searchOne
Execute the query against elasticsearch and return the first returned object.- Parameters:
query
- the query to executeclazz
- the entity clazz used for property mapping and indexname extraction- Returns:
- the first found object
-
searchOne
Execute the query against elasticsearch and return the first returned object.- Parameters:
query
- the query to executeclazz
- the entity clazz used for property mappingindex
- the index to run the query against- Returns:
- the first found object
-
multiSearch
Execute the multi search query against elasticsearch and return result asList
ofSearchHits
.- Type Parameters:
T
- element return type- Parameters:
queries
- the queries to executeclazz
- the entity clazz- Returns:
- list of SearchHits
- Since:
- 4.1
-
multiSearch
<T> List<SearchHits<T>> multiSearch(List<? extends Query> queries, Class<T> clazz, IndexCoordinates index) Execute the multi search query against elasticsearch and return result asList
ofSearchHits
.- 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
Execute the multi search query against elasticsearch and return result asList
ofSearchHits
.- Parameters:
queries
- the queries to executeclasses
- the entity classes- Returns:
- list of SearchHits
- Since:
- 4.1
-
multiSearch
List<SearchHits<?>> multiSearch(List<? extends Query> queries, List<Class<?>> classes, IndexCoordinates index) Execute the multi search query against elasticsearch and return result asList
ofSearchHits
.- Parameters:
queries
- the queries to executeclasses
- the entity classes used for property mappingindex
- the index to run the query against- Returns:
- list of SearchHits
-
search
Execute 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 mapping and index name extraction- Returns:
- SearchHits containing the list of found objects
-
search
Execute 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
-
search
more like this query to search for documents that are "like" a specific document.- Type Parameters:
T
- element return type- Parameters:
query
- the query to executeclazz
- the entity clazz used for property mapping and index name extraction- Returns:
- SearchHits containing the list of found objects
-
search
more like this query to search for documents that are "like" a specific document.- 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
-
searchForStream
Executes the givenQuery
against elasticsearch and return result asSearchHitsIterator
.- Type Parameters:
T
- element return type- Parameters:
query
- the query to executeclazz
- the entity clazz used for property mapping and index name extraction- Returns:
- a
SearchHitsIterator
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.
-
searchForStream
Executes the givenQuery
against elasticsearch and return result asSearchHitsIterator
.- 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:
- a
SearchHitsIterator
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.
-
matchAllQuery
Query matchAllQuery()Creates aQuery
to 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
- Since:
- 4.3
-
idsQuery
Creates aQuery
to 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
- Since:
- 4.3
-
NativeSearchQueryBuilder
withNativeSearchQueryBuilder.withSuggestBuilder(SuggestBuilder)
, callsearch(Query, Class)
and get the suggest fromSearchHits.getSuggest()