mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-30 16:52:11 +00:00
Cleanup deprecations from 4.0. (#1671)
Original Pull Request #1671 Closes #1669
This commit is contained in:
parent
4829b07e53
commit
e8edd606fb
@ -9,6 +9,18 @@ This section describes breaking changes from version 4.1.x to 4.2.x and how remo
|
||||
[[elasticsearch-migration-guide-4.1-4.2.removal]]
|
||||
== Removals
|
||||
|
||||
The `@Score` annotation that was used to set the score return value in an entity was deprecated in version 4.0 and has been removed.
|
||||
Scroe values are returned in the `SearchHit` instances that encapsulate the returned entities.
|
||||
|
||||
The `org.springframework.data.elasticsearch.ElasticsearchException` class has been removed.
|
||||
The remaining usages have been replaced with `org.springframework.data.mapping.MappingException` and `org.springframework.dao.InvalidDataAccessApiUsageException`.
|
||||
|
||||
The deprecated `ScoredPage`, `ScrolledPage` `@AggregatedPage` and implementations has been removed.
|
||||
|
||||
The deprecated `GetQuery` and `DeleteQuery` have been removed.
|
||||
|
||||
The deprecated `find` methods from `ReactiveSearchOperations` and `ReactiveDocumentOperations` have been removed.
|
||||
|
||||
[[elasticsearch-migration-guide-4.1-4.2.breaking-changes]]
|
||||
== Breaking Changes
|
||||
|
||||
@ -16,17 +28,22 @@ This section describes breaking changes from version 4.1.x to 4.2.x and how remo
|
||||
|
||||
==== Enum package changed
|
||||
|
||||
It was possible in 4.1 to configure the refresh policy for the `ReactiveElasticsearchTemplate` by overriding the method `AbstractReactiveElasticsearchConfiguration.refreshPolicy()` in a custom configuration class. The return value of this method was an instance of the class `org.elasticsearch.action.support.WriteRequest.RefreshPolicy`.
|
||||
It was possible in 4.1 to configure the refresh policy for the `ReactiveElasticsearchTemplate` by overriding the method `AbstractReactiveElasticsearchConfiguration.refreshPolicy()` in a custom configuration class.
|
||||
The return value of this method was an instance of the class `org.elasticsearch.action.support.WriteRequest.RefreshPolicy`.
|
||||
|
||||
Now the configuration must return `org.springframework.data.elasticsearch.core.RefreshPolicy`. This enum has the same values and triggers the same behaviour as before, so only the `import` statement has to be adjusted.
|
||||
Now the configuration must return `org.springframework.data.elasticsearch.core.RefreshPolicy`.
|
||||
This enum has the same values and triggers the same behaviour as before, so only the `import` statement has to be adjusted.
|
||||
|
||||
==== Refresh behaviour
|
||||
|
||||
`ElasticsearchOperations` and `ReactiveElasticsearchOperations` now explicitly use the `RefreshPolicy` set on the template for write requests if not null. If the refresh policy is null, then nothing special is done, so the cluster defaults are used. `ElasticsearchOperations` was always using the cluster default before this version.
|
||||
`ElasticsearchOperations` and `ReactiveElasticsearchOperations` now explicitly use the `RefreshPolicy` set on the template for write requests if not null.
|
||||
If the refresh policy is null, then nothing special is done, so the cluster defaults are used. `ElasticsearchOperations` was always using the cluster default before this version.
|
||||
|
||||
The provided implementations for `ElasticsearchRepository` and `ReactiveElasticsearchRepository` will do an explicit refresh when the refresh policy is null. This is the same behaviour as in previous versions. If a refresh policy is set, then it will be used by the repositories as well.
|
||||
The provided implementations for `ElasticsearchRepository` and `ReactiveElasticsearchRepository` will do an explicit refresh when the refresh policy is null.
|
||||
This is the same behaviour as in previous versions.
|
||||
If a refresh policy is set, then it will be used by the repositories as well.
|
||||
|
||||
==== Refresh configuration
|
||||
|
||||
When configuring Spring Data Elasticsearch like described in <<elasticsearch.clients>> by using `ElasticsearchConfigurationSupport`, `AbstractElasticsearchConfiguration` or `AbstractReactiveElasticsearchConfiguration` the refresh policy will be initialized to `null`. Previously the reactive code initialized this to `IMMEDIATE`, now reactive and
|
||||
non-reactive code show the same behaviour.
|
||||
When configuring Spring Data Elasticsearch like described in <<elasticsearch.clients>> by using `ElasticsearchConfigurationSupport`, `AbstractElasticsearchConfiguration` or `AbstractReactiveElasticsearchConfiguration` the refresh policy will be initialized to `null`.
|
||||
Previously the reactive code initialized this to `IMMEDIATE`, now reactive and non-reactive code show the same behaviour.
|
||||
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* ElasticsearchException
|
||||
*
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Peter-Josef Meisch
|
||||
* @deprecated since 4.0, use {@link UncategorizedElasticsearchException}
|
||||
*/
|
||||
@Deprecated
|
||||
public class ElasticsearchException extends RuntimeException {
|
||||
|
||||
@Nullable private Map<String, String> failedDocuments;
|
||||
|
||||
public ElasticsearchException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ElasticsearchException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ElasticsearchException(String message, Throwable cause, Map<String, String> failedDocuments) {
|
||||
super(message, cause);
|
||||
this.failedDocuments = failedDocuments;
|
||||
}
|
||||
|
||||
public ElasticsearchException(String message, Map<String, String> failedDocuments) {
|
||||
super(message);
|
||||
this.failedDocuments = failedDocuments;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Map<String, String> getFailedDocuments() {
|
||||
return failedDocuments;
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package org.springframework.data.elasticsearch.annotations;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.data.annotation.ReadOnlyProperty;
|
||||
import org.springframework.data.elasticsearch.core.SearchHit;
|
||||
|
||||
/**
|
||||
* Specifies that this field is used for storing the document score.
|
||||
*
|
||||
* @author Sascha Woo
|
||||
* @author Peter-Josef Meisch
|
||||
* @since 3.1
|
||||
* @deprecated since 4.0, use {@link SearchHit#getScore()} instead
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
@Documented
|
||||
@Inherited
|
||||
@ReadOnlyProperty
|
||||
@Deprecated
|
||||
public @interface Score {
|
||||
}
|
@ -53,7 +53,6 @@ import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersiste
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||
import org.springframework.data.elasticsearch.core.query.BulkOptions;
|
||||
import org.springframework.data.elasticsearch.core.query.GetQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery;
|
||||
@ -249,23 +248,11 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper
|
||||
return get(id, clazz, getIndexCoordinatesFor(clazz));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T get(GetQuery query, Class<T> clazz, IndexCoordinates index) {
|
||||
return get(query.getId(), clazz, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> multiGet(Query query, Class<T> clazz) {
|
||||
return multiGet(query, clazz, getIndexCoordinatesFor(clazz));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T queryForObject(GetQuery query, Class<T> clazz) {
|
||||
return get(query.getId(), clazz, getIndexCoordinatesFor(clazz));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(String id, Class<?> clazz) {
|
||||
return exists(id, getIndexCoordinatesFor(clazz));
|
||||
@ -400,11 +387,6 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper
|
||||
return count(query, clazz, getIndexCoordinatesFor(clazz));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> CloseableIterator<T> stream(Query query, Class<T> clazz, IndexCoordinates index) {
|
||||
return (CloseableIterator<T>) SearchHitSupport.unwrapSearchHits(searchForStream(query, clazz, index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> SearchHitsIterator<T> searchForStream(Query query, Class<T> clazz) {
|
||||
return searchForStream(query, clazz, getIndexCoordinatesFor(clazz));
|
||||
|
@ -19,8 +19,6 @@ import java.util.List;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.BulkOptions;
|
||||
import org.springframework.data.elasticsearch.core.query.DeleteQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.GetQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.Query;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateByQueryResponse;
|
||||
@ -310,41 +308,4 @@ public interface DocumentOperations {
|
||||
* @since 4.2
|
||||
*/
|
||||
UpdateByQueryResponse updateByQuery(UpdateQuery updateQuery, IndexCoordinates index);
|
||||
|
||||
// region deprecated
|
||||
/**
|
||||
* Delete all records matching the query.
|
||||
*
|
||||
* @param query query defining the objects
|
||||
* @param index the index where to delete the records
|
||||
* @deprecated since 4.0, use {@link #delete(Query, Class, IndexCoordinates)}
|
||||
*/
|
||||
@Deprecated
|
||||
void delete(DeleteQuery query, IndexCoordinates index);
|
||||
|
||||
/**
|
||||
* Retrieves an object from an index.
|
||||
*
|
||||
* @param query the query defining the id of the object to get
|
||||
* @param clazz the type of the object to be returned
|
||||
* @param index the index from which the object is read.
|
||||
* @return the found object
|
||||
* @deprecated since 4.0, use {@link #get(String, Class, IndexCoordinates)}
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
<T> T get(GetQuery query, Class<T> clazz, IndexCoordinates index);
|
||||
|
||||
/**
|
||||
* Retrieves an object from an index.
|
||||
*
|
||||
* @param query the query defining the id of the object to get
|
||||
* @param clazz the type of the object to be returned
|
||||
* @return the found object
|
||||
* @deprecated since 4.0, use {@link #get(String, Class, IndexCoordinates)}
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
<T> T queryForObject(GetQuery query, Class<T> clazz);
|
||||
// endregion
|
||||
}
|
||||
|
@ -15,15 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.elasticsearch.cluster.metadata.AliasMetadata;
|
||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
||||
import org.springframework.data.elasticsearch.core.document.Document;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.AliasQuery;
|
||||
import org.springframework.data.elasticsearch.core.routing.RoutingResolver;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@ -70,340 +65,6 @@ public interface ElasticsearchOperations extends DocumentOperations, SearchOpera
|
||||
@Nullable
|
||||
String getEntityRouting(Object entity);
|
||||
|
||||
// region IndexOperations
|
||||
/**
|
||||
* Create an index for given indexName .
|
||||
*
|
||||
* @param indexName the name of the index
|
||||
* @return {@literal true} if the index was created
|
||||
* @deprecated since 4.0, use {@link IndexOperations#create()}
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean createIndex(String indexName) {
|
||||
return indexOps(IndexCoordinates.of(indexName)).create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an index for given indexName and Settings.
|
||||
*
|
||||
* @param indexName the name of the index
|
||||
* @param settings the index settings
|
||||
* @return {@literal true} if the index was created
|
||||
* @deprecated since 4.0, use {@link IndexOperations#create(Document)}
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean createIndex(String indexName, Object settings) {
|
||||
return indexOps(IndexCoordinates.of(indexName)).create(getDocument(settings));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an index for a class if it does not already exist.
|
||||
*
|
||||
* @param clazz The entity class, must be annotated with
|
||||
* {@link org.springframework.data.elasticsearch.annotations.Document}
|
||||
* @return {@literal true} if the index was created
|
||||
* @deprecated since 4.0, use {@link IndexOperations#create()}
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean createIndex(Class<?> clazz) {
|
||||
return indexOps(clazz).create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an index for given class and Settings.
|
||||
*
|
||||
* @param clazz The entity class, must be annotated with
|
||||
* {@link org.springframework.data.elasticsearch.annotations.Document}
|
||||
* @param settings the index settings
|
||||
* @return {@literal true} if the index was created
|
||||
* @deprecated since 4.0, use {@link IndexOperations#create(Document)}
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean createIndex(Class<?> clazz, Object settings) {
|
||||
return indexOps(clazz).create(getDocument(settings));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an index for given entity.
|
||||
*
|
||||
* @param clazz The entity class, must be annotated with
|
||||
* {@link org.springframework.data.elasticsearch.annotations.Document}
|
||||
* @return {@literal true} if the index was deleted
|
||||
* @deprecated since 4.0, use {@link IndexOperations#delete()}
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean deleteIndex(Class<?> clazz) {
|
||||
return indexOps(clazz).delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an index.
|
||||
*
|
||||
* @param indexName the name of the index to delete
|
||||
* @return {@literal true} if the index was deleted
|
||||
* @deprecated since 4.0, use {@link IndexOperations#delete()}
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean deleteIndex(String indexName) {
|
||||
return indexOps(IndexCoordinates.of(indexName)).delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an index for an IndexCoordinate
|
||||
*
|
||||
* @param index the index to delete
|
||||
* @return {@literal true} if the index was deleted
|
||||
* @deprecated since 4.0 use {@link #indexOps(IndexCoordinates)} and {@link IndexOperations#delete()}
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean deleteIndex(IndexCoordinates index) {
|
||||
return indexOps(index).delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* check if index exists.
|
||||
*
|
||||
* @param indexName the name of the index
|
||||
* @return {@literal true} if the index exists
|
||||
* @deprecated since 4.0, use {@link #indexOps(IndexCoordinates)} and {@link IndexOperations#exists()}
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean indexExists(String indexName) {
|
||||
return indexOps(IndexCoordinates.of(indexName)).exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* check if index is exists.
|
||||
*
|
||||
* @param clazz The entity class, must be annotated with
|
||||
* {@link org.springframework.data.elasticsearch.annotations.Document}
|
||||
* @return {@literal true} if the index exists
|
||||
* @deprecated since 4.0, use {@link #indexOps(Class)} and {@link IndexOperations#exists()}
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean indexExists(Class<?> clazz) {
|
||||
return indexOps(clazz).exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create mapping for a class and store it to the index.
|
||||
*
|
||||
* @param clazz The entity class, must be annotated with
|
||||
* {@link org.springframework.data.elasticsearch.annotations.Document}
|
||||
* @return {@literal true} if the mapping could be stored
|
||||
* @deprecated since 4.0, use {@link #indexOps(Class)}, {@link IndexOperations#createMapping(Class)} and
|
||||
* {@link IndexOperations#putMapping(Document)}
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean putMapping(Class<?> clazz) {
|
||||
IndexOperations indexOps = indexOps(clazz);
|
||||
return indexOps.putMapping(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create mapping for the given class and put the mapping to the given index.
|
||||
*
|
||||
* @param index the index to store the mapping to
|
||||
* @param clazz The entity class, must be annotated with
|
||||
* {@link org.springframework.data.elasticsearch.annotations.Document}
|
||||
* @return {@literal true} if the mapping could be stored
|
||||
* @deprecated since 4.0, use {@link #indexOps(IndexCoordinates)}, {@link IndexOperations#createMapping(Class)} and
|
||||
* {@link IndexOperations#putMapping(Document)}
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean putMapping(IndexCoordinates index, Class<?> clazz) {
|
||||
IndexOperations indexOps = indexOps(index);
|
||||
return indexOps.putMapping(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a mapping to an index.
|
||||
*
|
||||
* @param index the index to store the mapping to
|
||||
* @param mappings can be a JSON String or a {@link Map}
|
||||
* @return {@literal true} if the mapping could be stored
|
||||
* @deprecated since 4.0, use {@link #indexOps(IndexCoordinates)} and {@link IndexOperations#putMapping(Document)}
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean putMapping(IndexCoordinates index, Object mappings) {
|
||||
return indexOps(index).putMapping(getDocument(mappings));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create mapping for a class Stores a mapping to an index.
|
||||
*
|
||||
* @param clazz The entity class, must be annotated with
|
||||
* {@link org.springframework.data.elasticsearch.annotations.Document}
|
||||
* @param mappings can be a JSON String or a {@link Map}
|
||||
* @return {@literal true} if the mapping could be stored
|
||||
* @deprecated since 4.0, use {@link #indexOps(Class)} and {@link IndexOperations#putMapping(Document)}
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean putMapping(Class<?> clazz, Object mappings) {
|
||||
return indexOps(clazz).putMapping(getDocument(mappings));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mapping for an index defined by a class.
|
||||
*
|
||||
* @param clazz The entity class, must be annotated with
|
||||
* {@link org.springframework.data.elasticsearch.annotations.Document}.
|
||||
* @return the mapping
|
||||
* @deprecated since 4.0, use {@link #indexOps(Class)} and {@link IndexOperations#getMapping()}
|
||||
*/
|
||||
@Deprecated
|
||||
default Map<String, Object> getMapping(Class<?> clazz) {
|
||||
return indexOps(clazz).getMapping();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mapping for a given index.
|
||||
*
|
||||
* @param index the index to read the mapping from
|
||||
* @return the mapping
|
||||
* @deprecated since 4.0, use {@link #indexOps(IndexCoordinates)} and {@link IndexOperations#getMapping()}
|
||||
*/
|
||||
@Deprecated
|
||||
default Map<String, Object> getMapping(IndexCoordinates index) {
|
||||
return indexOps(index).getMapping();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an alias.
|
||||
*
|
||||
* @param query query defining the alias
|
||||
* @param index the index for which to add an alias
|
||||
* @return true if the alias was created
|
||||
* @deprecated since 4.0, use {@link #indexOps(IndexCoordinates)} and {@link IndexOperations#addAlias(AliasQuery)}
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean addAlias(AliasQuery query, IndexCoordinates index) {
|
||||
return indexOps(index).addAlias(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an alias.
|
||||
*
|
||||
* @param query query defining the alias
|
||||
* @param index the index for which to remove an alias
|
||||
* @return true if the alias was removed
|
||||
* @deprecated since 4.0, use {@link #indexOps(IndexCoordinates)} {@link IndexOperations#removeAlias(AliasQuery)}
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean removeAlias(AliasQuery query, IndexCoordinates index) {
|
||||
return indexOps(index).removeAlias(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the alias informations for a specified index.
|
||||
*
|
||||
* @param indexName the name of the index
|
||||
* @return alias information
|
||||
* @deprecated since 4.0, use {@link #indexOps(IndexCoordinates)} and {@link IndexOperations#queryForAlias()}
|
||||
*/
|
||||
@Deprecated
|
||||
default List<AliasMetadata> queryForAlias(String indexName) {
|
||||
return indexOps(IndexCoordinates.of(indexName)).queryForAlias();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings for a given indexName.
|
||||
*
|
||||
* @param indexName the name of the index
|
||||
* @return the settings
|
||||
* @deprecated since 4.0, use {@link #indexOps(IndexCoordinates)} and {@link IndexOperations#getSettings()} )}
|
||||
*/
|
||||
@Deprecated
|
||||
default Map<String, Object> getSetting(String indexName) {
|
||||
return indexOps(IndexCoordinates.of(indexName)).getSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings for a given class.
|
||||
*
|
||||
* @param clazz The entity class, must be annotated with
|
||||
* {@link org.springframework.data.elasticsearch.annotations.Document}
|
||||
* @return the settings
|
||||
* @deprecated since 4.0, use {@link #indexOps(Class)} and {@link IndexOperations#getSettings()}
|
||||
*/
|
||||
@Deprecated
|
||||
default Map<String, Object> getSetting(Class<?> clazz) {
|
||||
return indexOps(clazz).getSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings for a given indexName.
|
||||
*
|
||||
* @param indexName the name of the index
|
||||
* @param includeDefaults whether or not to include all the default settings
|
||||
* @deprecated since 4.0 use {@link #indexOps(IndexCoordinates)} and {@link IndexOperations#getSettings(boolean)} ()}
|
||||
* @return the settings
|
||||
*/
|
||||
@Deprecated
|
||||
default Map<String, Object> getSettings(String indexName, boolean includeDefaults) {
|
||||
return indexOps(IndexCoordinates.of(indexName)).getSettings(includeDefaults);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings for a given class.
|
||||
*
|
||||
* @param clazz The entity class, must be annotated with
|
||||
* {@link org.springframework.data.elasticsearch.annotations.Document}
|
||||
* @param includeDefaults whether or not to include all the default settings
|
||||
* @return the settings
|
||||
* @deprecated since 4.0 use {@link #indexOps(Class)} and {@link IndexOperations#getSettings(boolean)} ()}
|
||||
*/
|
||||
default Map<String, Object> getSettings(Class<?> clazz, boolean includeDefaults) {
|
||||
return indexOps(clazz).getSettings(includeDefaults);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the index(es).
|
||||
*
|
||||
* @param index the index to refresh
|
||||
* @deprecated since 4.0, use {@link #indexOps(IndexCoordinates)} and {@link IndexOperations#refresh()} instead}
|
||||
*/
|
||||
@Deprecated
|
||||
default void refresh(IndexCoordinates index) {
|
||||
indexOps(index).refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the index.
|
||||
*
|
||||
* @param clazz The entity class, must be annotated with
|
||||
* {@link org.springframework.data.elasticsearch.annotations.Document}
|
||||
* @deprecated since 4.0, use {@link #indexOps(Class)} and {@link IndexOperations#refresh()} instead}
|
||||
*/
|
||||
@Deprecated
|
||||
default void refresh(Class<?> clazz) {
|
||||
indexOps(clazz).refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* converts an object to a Document
|
||||
*
|
||||
* @param object
|
||||
* @return
|
||||
* @deprecated since 4.0, helper method for deprecated functions
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
default Document getDocument(Object object) {
|
||||
Document document = null;
|
||||
|
||||
try {
|
||||
if (object instanceof String) {
|
||||
document = Document.parse((String) object);
|
||||
} else if (object instanceof Map) {
|
||||
document = Document.from((Map<String, Object>) object);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("object cannot be converted to Document", e);
|
||||
}
|
||||
return document;
|
||||
} // endregion
|
||||
|
||||
// region helper
|
||||
/**
|
||||
* gets the String representation for an id.
|
||||
@ -418,7 +79,7 @@ public interface ElasticsearchOperations extends DocumentOperations, SearchOpera
|
||||
}
|
||||
// endregion
|
||||
|
||||
//region routing
|
||||
// region routing
|
||||
/**
|
||||
* Returns a copy of this instance with the same configuration, but that uses a different {@link RoutingResolver} to
|
||||
* obtain routing information.
|
||||
@ -428,5 +89,5 @@ public interface ElasticsearchOperations extends DocumentOperations, SearchOpera
|
||||
* @since 4.2
|
||||
*/
|
||||
ElasticsearchOperations withRouting(RoutingResolver routingResolver);
|
||||
//endregion
|
||||
// endregion
|
||||
}
|
||||
|
@ -49,7 +49,6 @@ import org.springframework.data.elasticsearch.core.document.DocumentAdapters;
|
||||
import org.springframework.data.elasticsearch.core.document.SearchDocumentResponse;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.BulkOptions;
|
||||
import org.springframework.data.elasticsearch.core.query.DeleteQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.Query;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateByQueryResponse;
|
||||
@ -215,26 +214,19 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate {
|
||||
execute(client -> client.deleteByQuery(deleteByQueryRequest, RequestOptions.DEFAULT));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void delete(DeleteQuery deleteQuery, IndexCoordinates index) {
|
||||
DeleteByQueryRequest deleteByQueryRequest = requestFactory.deleteByQueryRequest(deleteQuery, index);
|
||||
execute(client -> client.deleteByQuery(deleteByQueryRequest, RequestOptions.DEFAULT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateResponse update(UpdateQuery query, IndexCoordinates index) {
|
||||
UpdateRequest request = requestFactory.updateRequest(query, index);
|
||||
|
||||
if (query.getRefreshPolicy() == null && getRefreshPolicy() != null) {
|
||||
request.setRefreshPolicy(RequestFactory.toElasticsearchRefreshPolicy(getRefreshPolicy()));
|
||||
}
|
||||
if (query.getRefreshPolicy() == null && getRefreshPolicy() != null) {
|
||||
request.setRefreshPolicy(RequestFactory.toElasticsearchRefreshPolicy(getRefreshPolicy()));
|
||||
}
|
||||
|
||||
if (query.getRouting() == null && routingResolver.getRouting() != null) {
|
||||
request.routing(routingResolver.getRouting());
|
||||
}
|
||||
if (query.getRouting() == null && routingResolver.getRouting() != null) {
|
||||
request.routing(routingResolver.getRouting());
|
||||
}
|
||||
|
||||
UpdateResponse.Result result = UpdateResponse.Result
|
||||
UpdateResponse.Result result = UpdateResponse.Result
|
||||
.valueOf(execute(client -> client.update(request, RequestOptions.DEFAULT)).getResult().name());
|
||||
return new UpdateResponse(result);
|
||||
}
|
||||
@ -247,14 +239,13 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate {
|
||||
|
||||
final UpdateByQueryRequest updateByQueryRequest = requestFactory.updateByQueryRequest(query, index);
|
||||
|
||||
if (query.getRefreshPolicy() == null && getRefreshPolicy() != null) {
|
||||
updateByQueryRequest.setRefresh(getRefreshPolicy() == RefreshPolicy.IMMEDIATE);
|
||||
}
|
||||
if (query.getRefreshPolicy() == null && getRefreshPolicy() != null) {
|
||||
updateByQueryRequest.setRefresh(getRefreshPolicy() == RefreshPolicy.IMMEDIATE);
|
||||
}
|
||||
|
||||
|
||||
if (query.getRouting() == null && routingResolver.getRouting() != null) {
|
||||
updateByQueryRequest.setRouting(routingResolver.getRouting());
|
||||
}
|
||||
if (query.getRouting() == null && routingResolver.getRouting() != null) {
|
||||
updateByQueryRequest.setRouting(routingResolver.getRouting());
|
||||
}
|
||||
|
||||
final BulkByScrollResponse bulkByScrollResponse = execute(
|
||||
client -> client.updateByQuery(updateByQueryRequest, RequestOptions.DEFAULT));
|
||||
|
@ -46,11 +46,10 @@ import org.springframework.data.elasticsearch.core.document.Document;
|
||||
import org.springframework.data.elasticsearch.core.document.DocumentAdapters;
|
||||
import org.springframework.data.elasticsearch.core.document.SearchDocumentResponse;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateByQueryResponse;
|
||||
import org.springframework.data.elasticsearch.core.query.BulkOptions;
|
||||
import org.springframework.data.elasticsearch.core.query.DeleteQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.Query;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateByQueryResponse;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateResponse;
|
||||
import org.springframework.data.elasticsearch.support.SearchHitsUtil;
|
||||
@ -183,7 +182,8 @@ public class ElasticsearchTemplate extends AbstractElasticsearchTemplate {
|
||||
@Nullable
|
||||
public <T> T get(String id, Class<T> clazz, IndexCoordinates index) {
|
||||
|
||||
GetRequestBuilder getRequestBuilder = requestFactory.getRequestBuilder(client, id, routingResolver.getRouting(), index);
|
||||
GetRequestBuilder getRequestBuilder = requestFactory.getRequestBuilder(client, id, routingResolver.getRouting(),
|
||||
index);
|
||||
GetResponse response = getRequestBuilder.execute().actionGet();
|
||||
|
||||
DocumentCallback<T> callback = new ReadDocumentCallback<>(elasticsearchConverter, clazz, index);
|
||||
@ -206,7 +206,8 @@ public class ElasticsearchTemplate extends AbstractElasticsearchTemplate {
|
||||
@Override
|
||||
protected boolean doExists(String id, IndexCoordinates index) {
|
||||
|
||||
GetRequestBuilder getRequestBuilder = requestFactory.getRequestBuilder(client, id, routingResolver.getRouting(), index);
|
||||
GetRequestBuilder getRequestBuilder = requestFactory.getRequestBuilder(client, id, routingResolver.getRouting(),
|
||||
index);
|
||||
getRequestBuilder.setFetchSource(false);
|
||||
return getRequestBuilder.execute().actionGet().isExists();
|
||||
}
|
||||
@ -231,12 +232,6 @@ public class ElasticsearchTemplate extends AbstractElasticsearchTemplate {
|
||||
return deleteRequestBuilder.execute().actionGet().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void delete(DeleteQuery deleteQuery, IndexCoordinates index) {
|
||||
requestFactory.deleteByQueryRequestBuilder(client, deleteQuery, index).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Query query, Class<?> clazz, IndexCoordinates index) {
|
||||
requestFactory.deleteByQueryRequestBuilder(client, query, clazz, index).get();
|
||||
@ -252,15 +247,15 @@ public class ElasticsearchTemplate extends AbstractElasticsearchTemplate {
|
||||
|
||||
UpdateRequestBuilder updateRequestBuilder = requestFactory.updateRequestBuilderFor(client, query, index);
|
||||
|
||||
if (query.getRefreshPolicy() == null && getRefreshPolicy() != null) {
|
||||
updateRequestBuilder.setRefreshPolicy(RequestFactory.toElasticsearchRefreshPolicy(getRefreshPolicy()));
|
||||
}
|
||||
if (query.getRefreshPolicy() == null && getRefreshPolicy() != null) {
|
||||
updateRequestBuilder.setRefreshPolicy(RequestFactory.toElasticsearchRefreshPolicy(getRefreshPolicy()));
|
||||
}
|
||||
|
||||
if (query.getRouting() == null && routingResolver.getRouting() != null) {
|
||||
updateRequestBuilder.setRouting(routingResolver.getRouting());
|
||||
}
|
||||
if (query.getRouting() == null && routingResolver.getRouting() != null) {
|
||||
updateRequestBuilder.setRouting(routingResolver.getRouting());
|
||||
}
|
||||
|
||||
org.elasticsearch.action.update.UpdateResponse updateResponse = updateRequestBuilder.execute().actionGet();
|
||||
org.elasticsearch.action.update.UpdateResponse updateResponse = updateRequestBuilder.execute().actionGet();
|
||||
UpdateResponse.Result result = UpdateResponse.Result.valueOf(updateResponse.getResult().name());
|
||||
return new UpdateResponse(result);
|
||||
}
|
||||
@ -268,18 +263,19 @@ public class ElasticsearchTemplate extends AbstractElasticsearchTemplate {
|
||||
@Override
|
||||
public UpdateByQueryResponse updateByQuery(UpdateQuery query, IndexCoordinates index) {
|
||||
|
||||
Assert.notNull(query, "query must not be null");
|
||||
Assert.notNull(index, "index must not be null");
|
||||
Assert.notNull(query, "query must not be null");
|
||||
Assert.notNull(index, "index must not be null");
|
||||
|
||||
final UpdateByQueryRequestBuilder updateByQueryRequestBuilder = requestFactory.updateByQueryRequestBuilder(client, query, index);
|
||||
final UpdateByQueryRequestBuilder updateByQueryRequestBuilder = requestFactory.updateByQueryRequestBuilder(client,
|
||||
query, index);
|
||||
|
||||
if (query.getRefreshPolicy() == null && getRefreshPolicy() != null) {
|
||||
updateByQueryRequestBuilder.refresh(getRefreshPolicy() == RefreshPolicy.IMMEDIATE);
|
||||
}
|
||||
if (query.getRefreshPolicy() == null && getRefreshPolicy() != null) {
|
||||
updateByQueryRequestBuilder.refresh(getRefreshPolicy() == RefreshPolicy.IMMEDIATE);
|
||||
}
|
||||
|
||||
// UpdateByQueryRequestBuilder has not parameters to set a routing value
|
||||
// UpdateByQueryRequestBuilder has not parameters to set a routing value
|
||||
|
||||
final BulkByScrollResponse bulkByScrollResponse = updateByQueryRequestBuilder.execute().actionGet();
|
||||
final BulkByScrollResponse bulkByScrollResponse = updateByQueryRequestBuilder.execute().actionGet();
|
||||
return UpdateByQueryResponse.of(bulkByScrollResponse);
|
||||
}
|
||||
|
||||
|
@ -182,34 +182,6 @@ public interface ReactiveDocumentOperations {
|
||||
*/
|
||||
Mono<Void> bulkUpdate(List<UpdateQuery> queries, BulkOptions bulkOptions, IndexCoordinates index);
|
||||
|
||||
/**
|
||||
* Find the document with the given {@literal id} mapped onto the given {@literal entityType}.
|
||||
*
|
||||
* @param id the {@literal _id} of the document to fetch.
|
||||
* @param entityType the domain type used for mapping the document.
|
||||
* @param <T>
|
||||
* @return {@link Mono#empty()} if not found.
|
||||
* @deprecated since 4.0 use {@link #get(String, Class)}
|
||||
*/
|
||||
@Deprecated
|
||||
default <T> Mono<T> findById(String id, Class<T> entityType) {
|
||||
return get(id, entityType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the entity with given {@literal id}.
|
||||
*
|
||||
* @param id must not be {@literal null}.
|
||||
* @param index the target index, must not be {@literal null}
|
||||
* @param <T>
|
||||
* @return the {@link Mono} emitting the entity or signalling completion if none found.
|
||||
* @deprecated since 4.0, use {@link #get(String, Class, IndexCoordinates)}
|
||||
*/
|
||||
@Deprecated
|
||||
default <T> Mono<T> findById(String id, Class<T> entityType, IndexCoordinates index) {
|
||||
return get(id, entityType, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the document with the given {@literal id} mapped onto the given {@literal entityType}.
|
||||
*
|
||||
@ -249,17 +221,6 @@ public interface ReactiveDocumentOperations {
|
||||
*/
|
||||
Mono<Boolean> exists(String id, IndexCoordinates index);
|
||||
|
||||
/**
|
||||
* Check if an entity with given {@literal id} exists.
|
||||
*
|
||||
* @param id the {@literal _id} of the document to look for.
|
||||
* @param index the target index, must not be {@literal null}
|
||||
* @return a {@link Mono} emitting {@literal true} if a matching document exists, {@literal false} otherwise.
|
||||
* @deprecated since 4.0, use {@link #exists(String, Class)} or {@link #exists(String, IndexCoordinates)}
|
||||
*/
|
||||
@Deprecated
|
||||
Mono<Boolean> exists(String id, Class<?> entityType, IndexCoordinates index);
|
||||
|
||||
/**
|
||||
* Delete the given entity extracting index from entity metadata.
|
||||
*
|
||||
@ -296,20 +257,6 @@ public interface ReactiveDocumentOperations {
|
||||
*/
|
||||
Mono<String> delete(String id, Class<?> entityType);
|
||||
|
||||
/**
|
||||
* Delete the entity with given {@literal id} extracting index from entity metadata.
|
||||
*
|
||||
* @param id must not be {@literal null}.
|
||||
* @param entityType must not be {@literal null}.
|
||||
* @param index the target index, must not be {@literal null}
|
||||
* @return a {@link Mono} emitting the {@literal id} of the removed document.
|
||||
* @deprecated since 4.0, use {@link #delete(String, Class)} or {@link #delete(String, IndexCoordinates)}
|
||||
*/
|
||||
@Deprecated
|
||||
default Mono<String> delete(String id, Class<?> entityType, IndexCoordinates index) {
|
||||
return delete(id, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the documents matching the given {@link Query} extracting index from entity metadata.
|
||||
*
|
||||
|
@ -379,18 +379,6 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
||||
return doExists(id, index);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#exists(String, Class, IndexCoordinates)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Boolean> exists(String id, Class<?> entityType, IndexCoordinates index) {
|
||||
|
||||
Assert.notNull(id, "Id must not be null!");
|
||||
|
||||
return doExists(id, index);
|
||||
}
|
||||
|
||||
private Mono<Boolean> doExists(String id, IndexCoordinates index) {
|
||||
return Mono.defer(() -> doExists(requestFactory.getRequest(id, routingResolver.getRouting(), index)));
|
||||
}
|
||||
|
@ -38,73 +38,6 @@ import org.springframework.data.elasticsearch.core.query.StringQuery;
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface ReactiveSearchOperations {
|
||||
/**
|
||||
* Search the index for entities matching the given {@link Query query}. <br />
|
||||
* {@link Pageable#isUnpaged() Unpaged} queries may overrule elasticsearch server defaults for page size by either
|
||||
* delegating to the scroll API or using a max {@link org.elasticsearch.search.builder.SearchSourceBuilder#size(int)
|
||||
* size}.
|
||||
*
|
||||
* @param query must not be {@literal null}.
|
||||
* @param entityType must not be {@literal null}.
|
||||
* @param <T>
|
||||
* @return a {@link Flux} emitting matching entities one by one wrapped in a {@link SearchHit}.
|
||||
* @deprecated since 4.0, use {@link #search(Query, Class)}.
|
||||
*/
|
||||
@Deprecated
|
||||
default <T> Flux<T> find(Query query, Class<T> entityType) {
|
||||
return find(query, entityType, entityType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search the index for entities matching the given {@link Query query}. <br />
|
||||
* {@link Pageable#isUnpaged() Unpaged} queries may overrule elasticsearch server defaults for page size by either *
|
||||
* delegating to the scroll API or using a max {@link org.elasticsearch.search.builder.SearchSourceBuilder#size(int) *
|
||||
* size}.
|
||||
*
|
||||
* @param query must not be {@literal null}.
|
||||
* @param entityType The entity type for mapping the query. Must not be {@literal null}.
|
||||
* @param returnType The mapping target type. Must not be {@literal null}. Th
|
||||
* @param <T>
|
||||
* @return a {@link Flux} emitting matching entities one by one wrapped in a {@link SearchHit}.
|
||||
* @deprecated since 4.0, use {@link #search(Query, Class, Class)}.
|
||||
*/
|
||||
@Deprecated
|
||||
default <T> Flux<T> find(Query query, Class<?> entityType, Class<T> returnType) {
|
||||
return search(query, entityType, returnType).map(SearchHit::getContent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search the index for entities matching the given {@link Query query}.
|
||||
*
|
||||
* @param query must not be {@literal null}.
|
||||
* @param entityType must not be {@literal null}.
|
||||
* @param index the target index, must not be {@literal null}
|
||||
* @param <T>
|
||||
* @return a {@link Flux} emitting matching entities one by one wrapped in a {@link SearchHit}.
|
||||
* @deprecated since 4.0, use {@link #search(Query, Class, IndexCoordinates)}
|
||||
*/
|
||||
@Deprecated
|
||||
default <T> Flux<T> find(Query query, Class<T> entityType, IndexCoordinates index) {
|
||||
return find(query, entityType, entityType, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search the index for entities matching the given {@link Query query}.
|
||||
*
|
||||
* @param <T>
|
||||
* @param query must not be {@literal null}.
|
||||
* @param entityType must not be {@literal null}.
|
||||
* @param resultType the projection result type.
|
||||
* @param index the target index, must not be {@literal null}
|
||||
* @param <T>
|
||||
* @return a {@link Flux} emitting matching entities one by one wrapped in a {@link SearchHit}.
|
||||
* @deprecated since 4.0, use {@link #search(Query, Class, Class, IndexCoordinates)}.
|
||||
*/
|
||||
@Deprecated
|
||||
default <T> Flux<T> find(Query query, Class<?> entityType, Class<T> resultType, IndexCoordinates index) {
|
||||
return search(query, entityType, resultType, index).map(SearchHit::getContent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of documents matching the given {@link Query}.
|
||||
*
|
||||
|
@ -90,8 +90,8 @@ import org.elasticsearch.search.sort.SortBuilders;
|
||||
import org.elasticsearch.search.sort.SortMode;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.elasticsearch.search.suggest.SuggestBuilder;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
||||
import org.springframework.data.elasticsearch.core.document.Document;
|
||||
import org.springframework.data.elasticsearch.core.index.AliasAction;
|
||||
@ -709,26 +709,6 @@ class RequestFactory {
|
||||
// endregion
|
||||
|
||||
// region delete
|
||||
@Deprecated
|
||||
public DeleteByQueryRequest deleteByQueryRequest(DeleteQuery deleteQuery, IndexCoordinates index) {
|
||||
|
||||
String[] indexNames = index.getIndexNames();
|
||||
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(indexNames) //
|
||||
.setQuery(deleteQuery.getQuery()) //
|
||||
.setAbortOnVersionConflict(false) //
|
||||
.setRefresh(true);
|
||||
|
||||
if (deleteQuery.getPageSize() != null) {
|
||||
deleteByQueryRequest.setBatchSize(deleteQuery.getPageSize());
|
||||
}
|
||||
|
||||
if (deleteQuery.getScrollTimeInMillis() != null) {
|
||||
deleteByQueryRequest.setScroll(TimeValue.timeValueMillis(deleteQuery.getScrollTimeInMillis()));
|
||||
}
|
||||
|
||||
return deleteByQueryRequest;
|
||||
}
|
||||
|
||||
public DeleteByQueryRequest deleteByQueryRequest(Query query, Class<?> clazz, IndexCoordinates index) {
|
||||
SearchRequest searchRequest = searchRequest(query, clazz, index);
|
||||
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(index.getIndexNames()) //
|
||||
@ -778,27 +758,6 @@ class RequestFactory {
|
||||
return deleteRequestBuilder;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public DeleteByQueryRequestBuilder deleteByQueryRequestBuilder(Client client, DeleteQuery deleteQuery,
|
||||
IndexCoordinates index) {
|
||||
|
||||
String[] indexNames = index.getIndexNames();
|
||||
|
||||
DeleteByQueryRequestBuilder requestBuilder = new DeleteByQueryRequestBuilder(client, DeleteByQueryAction.INSTANCE) //
|
||||
.source(indexNames) //
|
||||
.filter(deleteQuery.getQuery()) //
|
||||
.abortOnVersionConflict(false) //
|
||||
.refresh(true);
|
||||
|
||||
SearchRequestBuilder source = requestBuilder.source();
|
||||
|
||||
if (deleteQuery.getScrollTimeInMillis() != null) {
|
||||
source.setScroll(TimeValue.timeValueMillis(deleteQuery.getScrollTimeInMillis()));
|
||||
}
|
||||
|
||||
return requestBuilder;
|
||||
}
|
||||
|
||||
public DeleteByQueryRequestBuilder deleteByQueryRequestBuilder(Client client, Query query, Class<?> clazz,
|
||||
IndexCoordinates index) {
|
||||
SearchRequest searchRequest = searchRequest(query, clazz, index);
|
||||
@ -904,7 +863,7 @@ class RequestFactory {
|
||||
indexRequest = new IndexRequest(indexName).id(query.getId()).source(query.getSource(),
|
||||
Requests.INDEX_CONTENT_TYPE);
|
||||
} else {
|
||||
throw new ElasticsearchException(
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
"object or source is null, failed to index the document [id: " + query.getId() + ']');
|
||||
}
|
||||
|
||||
@ -959,7 +918,7 @@ class RequestFactory {
|
||||
indexRequestBuilder = client.prepareIndex(indexName, type, query.getId()).setSource(query.getSource(),
|
||||
Requests.INDEX_CONTENT_TYPE);
|
||||
} else {
|
||||
throw new ElasticsearchException(
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
"object or source is null, failed to index the document [id: " + query.getId() + ']');
|
||||
}
|
||||
|
||||
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
/**
|
||||
* A score-aware page gaining information about max score.
|
||||
*
|
||||
* @param <T>
|
||||
* @author Sascha Woo
|
||||
* @deprecated since 4.0, use {@link org.springframework.data.elasticsearch.core.SearchHits} to return values.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ScoredPage<T> extends Page<T> {
|
||||
|
||||
float getMaxScore();
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
* @author Peter-Josef Meisch
|
||||
* @author Sascha Woo
|
||||
* @deprecated since 4.0, will be removed in a future version.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ScrolledPage<T> extends Page<T> {
|
||||
|
||||
String getScrollId();
|
||||
}
|
@ -23,8 +23,6 @@ import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
|
||||
import org.springframework.data.repository.util.ReactiveWrappers;
|
||||
import org.springframework.data.util.CloseableIterator;
|
||||
import org.springframework.lang.Nullable;
|
||||
@ -65,14 +63,6 @@ public final class SearchHitSupport {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if (result instanceof AggregatedPage<?>) {
|
||||
AggregatedPage<?> page = (AggregatedPage<?>) result;
|
||||
List<?> list = page.getContent().stream().map(SearchHitSupport::unwrapSearchHits).collect(Collectors.toList());
|
||||
return new AggregatedPageImpl<>(list, page.getPageable(), page.getTotalElements(), page.getAggregations(),
|
||||
page.getScrollId(), page.getMaxScore());
|
||||
|
||||
}
|
||||
|
||||
if (result instanceof Stream<?>) {
|
||||
return ((Stream<?>) result).map(SearchHitSupport::unwrapSearchHits);
|
||||
}
|
||||
@ -86,6 +76,12 @@ public final class SearchHitSupport {
|
||||
return unwrapSearchHitsIterator((SearchHitsIterator<?>) result);
|
||||
}
|
||||
|
||||
if (result instanceof SearchPage<?>) {
|
||||
SearchPage<?> searchPage = (SearchPage<?>) result;
|
||||
List<?> content = (List<?>) SearchHitSupport.unwrapSearchHits(searchPage.getSearchHits());
|
||||
return new PageImpl<>(content, searchPage.getPageable(), searchPage.getTotalElements());
|
||||
}
|
||||
|
||||
if (ReactiveWrappers.isAvailable(ReactiveWrappers.ReactiveLibrary.PROJECT_REACTOR)) {
|
||||
|
||||
if (result instanceof Flux) {
|
||||
@ -117,25 +113,6 @@ public final class SearchHitSupport {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an {@link AggregatedPage} with the {@link SearchHit} objects from a {@link SearchHits} object.
|
||||
*
|
||||
* @param searchHits, must not be {@literal null}.
|
||||
* @param pageable, must not be {@literal null}.
|
||||
* @return the created Page
|
||||
* @deprecated since 4.0, will be removed in a future version.
|
||||
*/
|
||||
@Deprecated
|
||||
public static <T> AggregatedPage<SearchHit<T>> page(SearchHits<T> searchHits, Pageable pageable) {
|
||||
return new AggregatedPageImpl<>( //
|
||||
searchHits.getSearchHits(), //
|
||||
pageable, //
|
||||
searchHits.getTotalHits(), //
|
||||
searchHits.getAggregations(), //
|
||||
null, //
|
||||
searchHits.getMaxScore());
|
||||
}
|
||||
|
||||
public static <T> SearchPage<T> searchPageFor(SearchHits<T> searchHits, @Nullable Pageable pageable) {
|
||||
return new SearchPageImpl<>(searchHits, (pageable != null) ? pageable : Pageable.unpaged());
|
||||
}
|
||||
|
@ -15,19 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.search.suggest.SuggestBuilder;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.Query;
|
||||
import org.springframework.data.util.CloseableIterator;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
@ -70,177 +64,6 @@ public interface SearchOperations {
|
||||
*/
|
||||
long count(Query query, @Nullable Class<?> clazz, IndexCoordinates index);
|
||||
|
||||
// region deprecated
|
||||
/**
|
||||
* Execute the query against elasticsearch and return the first returned object.
|
||||
*
|
||||
* @param query the query to execute
|
||||
* @param clazz the entity clazz used for property mapping
|
||||
* @param index the index to run the query against
|
||||
* @return the first matching object
|
||||
* @deprecated since 4.0, use {@link #searchOne(Query, Class, IndexCoordinates)}.
|
||||
*/
|
||||
@Deprecated
|
||||
default <T> T queryForObject(Query query, Class<T> clazz, IndexCoordinates index) {
|
||||
return (T) SearchHitSupport.unwrapSearchHits(searchOne(query, clazz, index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the query against elasticsearch and return result as {@link Page}.
|
||||
*
|
||||
* @param query the query to execute
|
||||
* @param clazz the entity clazz used for property mapping
|
||||
* @param index the index to run the query against
|
||||
* @return a page with aggregations
|
||||
* @deprecated since 4.0, use {@link #search(Query, Class, IndexCoordinates)}.
|
||||
*/
|
||||
@Deprecated
|
||||
default <T> AggregatedPage<T> queryForPage(Query query, Class<T> clazz, IndexCoordinates index) {
|
||||
SearchHits<T> searchHits = search(query, clazz, index);
|
||||
AggregatedPage<SearchHit<T>> aggregatedPage = SearchHitSupport.page(searchHits, query.getPageable());
|
||||
return (AggregatedPage<T>) SearchHitSupport.unwrapSearchHits(aggregatedPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the multi-search against elasticsearch and return result as {@link List} of {@link Page}
|
||||
*
|
||||
* @param queries the queries
|
||||
* @param clazz the entity clazz used for property mapping
|
||||
* @param index the index to run the query against
|
||||
* @return list of pages with the results
|
||||
* @deprecated since 4.0, use {@link #multiSearch(List, Class, IndexCoordinates)}.
|
||||
*/
|
||||
@Deprecated
|
||||
default <T> List<Page<T>> queryForPage(List<? extends Query> queries, Class<T> clazz, IndexCoordinates index) {
|
||||
List<Page<T>> pageList = new ArrayList<>();
|
||||
List<SearchHits<T>> searchHitsList = multiSearch(queries, clazz, index);
|
||||
Iterator<? extends Query> qit = queries.iterator();
|
||||
searchHitsList.forEach(searchHits -> {
|
||||
AggregatedPage<SearchHit<T>> aggregatedPage = SearchHitSupport.page(searchHits, qit.next().getPageable());
|
||||
Page<T> page = (Page<T>) SearchHitSupport.unwrapSearchHits(aggregatedPage);
|
||||
pageList.add(page);
|
||||
});
|
||||
return pageList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the multi-search against elasticsearch and return result as {@link List} of {@link Page}
|
||||
*
|
||||
* @param queries the queries
|
||||
* @param classes the entity classes used for the queries
|
||||
* @param index the index to run the query against
|
||||
* @return list of pages with the results
|
||||
* @deprecated since 4.0, use {@link #multiSearch(List, List, IndexCoordinates)}.
|
||||
*/
|
||||
@Deprecated
|
||||
default List<AggregatedPage<?>> queryForPage(List<? extends Query> queries, List<Class<?>> classes,
|
||||
IndexCoordinates index) {
|
||||
List<AggregatedPage<?>> pageList = new ArrayList<>();
|
||||
List<SearchHits<?>> searchHitsList = multiSearch(queries, classes, index);
|
||||
Iterator<? extends Query> qit = queries.iterator();
|
||||
searchHitsList.forEach(searchHits -> {
|
||||
AggregatedPage<? extends SearchHit<?>> aggregatedPage = SearchHitSupport.page(searchHits,
|
||||
qit.next().getPageable());
|
||||
AggregatedPage<?> page = (AggregatedPage<?>) SearchHitSupport.unwrapSearchHits(aggregatedPage);
|
||||
pageList.add(page);
|
||||
});
|
||||
|
||||
return pageList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the given {@link Query} against elasticsearch and return result as {@link CloseableIterator}.
|
||||
* <p>
|
||||
*
|
||||
* @param <T> element return type
|
||||
* @param query the query to execute
|
||||
* @param clazz the entity clazz used for property mapping
|
||||
* @param index the index to run the query against
|
||||
* @return a {@link CloseableIterator} 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.
|
||||
* @deprecated since 4.0, use {@link #searchForStream(Query, Class, IndexCoordinates)}.
|
||||
*/
|
||||
@Deprecated
|
||||
<T> CloseableIterator<T> stream(Query query, Class<T> clazz, IndexCoordinates index);
|
||||
|
||||
/**
|
||||
* Execute the criteria query against elasticsearch and return result as {@link List}
|
||||
*
|
||||
* @param <T> element return type
|
||||
* @param query the query to execute
|
||||
* @param clazz the entity clazz used for property mapping
|
||||
* @param index the index to run the query against
|
||||
* @return list of found objects
|
||||
* @deprecated since 4.0, use {@link #search(Query, Class, IndexCoordinates)}.
|
||||
*/
|
||||
@Deprecated
|
||||
default <T> List<T> queryForList(Query query, Class<T> clazz, IndexCoordinates index) {
|
||||
return (List<T>) SearchHitSupport.unwrapSearchHits(search(query, clazz, index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the multi search query against elasticsearch and return result as {@link List}
|
||||
*
|
||||
* @param queries the queries to execute
|
||||
* @param clazz the entity clazz used for property mapping
|
||||
* @param index the index to run the query against
|
||||
* @param <T> element return type
|
||||
* @return list of found objects
|
||||
* @deprecated since 4.0, use {@link #multiSearch(List, Class, IndexCoordinates)}.
|
||||
*/
|
||||
@Deprecated
|
||||
default <T> List<List<T>> queryForList(List<Query> queries, Class<T> clazz, IndexCoordinates index) {
|
||||
return queryForPage(queries, clazz, index).stream().map(Page::getContent).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the multi search query against elasticsearch and return result as {@link List}
|
||||
*
|
||||
* @param queries the queries to execute
|
||||
* @param classes the entity classes used for property mapping
|
||||
* @param index the index to run the query against
|
||||
* @return list of list of found objects
|
||||
* @deprecated since 4.0, use {@link #multiSearch(List, List, IndexCoordinates)}.
|
||||
*/
|
||||
@Deprecated
|
||||
default List<List<?>> queryForList(List<Query> queries, List<Class<?>> classes, IndexCoordinates index) {
|
||||
return queryForPage(queries, classes, index).stream().map(Page::getContent).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the query against elasticsearch and return ids
|
||||
*
|
||||
* @param query the query to execute
|
||||
* @param clazz the entity clazz used for property mapping
|
||||
* @param index the index to run the query against
|
||||
* @return list of found object ids
|
||||
* @deprecated since 4.0 use {@link #search(Query, Class, IndexCoordinates)} and map the results.
|
||||
*/
|
||||
@Deprecated
|
||||
default List<String> queryForIds(Query query, Class<?> clazz, IndexCoordinates index) {
|
||||
return search(query, clazz, index).map(SearchHit::getId).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* more like this query to search for documents that are "like" a specific document.
|
||||
*
|
||||
* @param <T> element return type
|
||||
* @param query the query to execute
|
||||
* @param clazz the entity clazz used for property mapping
|
||||
* @param index the index to run the query against
|
||||
* @return page with the results
|
||||
* @deprecated since 4.0, use {@link #search(MoreLikeThisQuery, Class, IndexCoordinates)}.
|
||||
*/
|
||||
@Deprecated
|
||||
default <T> AggregatedPage<T> moreLikeThis(MoreLikeThisQuery query, Class<T> clazz, IndexCoordinates index) {
|
||||
SearchHits<T> searchHits = search(query, clazz, index);
|
||||
AggregatedPage<SearchHit<T>> aggregatedPage = SearchHitSupport.page(searchHits, query.getPageable());
|
||||
return (AggregatedPage<T>) SearchHitSupport.unwrapSearchHits(aggregatedPage);
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
/**
|
||||
* Does a suggest query
|
||||
*
|
||||
|
@ -1,23 +0,0 @@
|
||||
package org.springframework.data.elasticsearch.core.aggregation;
|
||||
|
||||
import org.elasticsearch.search.aggregations.Aggregation;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
import org.springframework.data.elasticsearch.core.ScoredPage;
|
||||
import org.springframework.data.elasticsearch.core.ScrolledPage;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* @author Petar Tahchiev
|
||||
* @author Sascha Woo
|
||||
* @author Peter-Josef Meisch
|
||||
* @deprecated since 4.0, use {@link org.springframework.data.elasticsearch.core.SearchHits} to return values.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface AggregatedPage<T> extends ScrolledPage<T>, ScoredPage<T> {
|
||||
|
||||
boolean hasAggregations();
|
||||
|
||||
@Nullable Aggregations getAggregations();
|
||||
|
||||
@Nullable Aggregation getAggregation(String name);
|
||||
}
|
@ -1,140 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.aggregation.impl;
|
||||
|
||||
import static java.util.Optional.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.elasticsearch.search.aggregations.Aggregation;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.document.SearchDocumentResponse;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* @author Petar Tahchiev
|
||||
* @author Artur Konczak
|
||||
* @author Mohsin Husen
|
||||
* @author Sascha Woo
|
||||
* @author Peter-Josef Meisch
|
||||
*/
|
||||
public class AggregatedPageImpl<T> extends PageImpl<T> implements AggregatedPage<T> {
|
||||
|
||||
@Nullable private Aggregations aggregations;
|
||||
@Nullable private String scrollId;
|
||||
private float maxScore;
|
||||
|
||||
private static Pageable pageableOrUnpaged(@Nullable Pageable pageable) {
|
||||
return ofNullable(pageable).orElse(Pageable.unpaged());
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content) {
|
||||
super(content);
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, float maxScore) {
|
||||
super(content);
|
||||
this.maxScore = maxScore;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, String scrollId) {
|
||||
super(content);
|
||||
this.scrollId = scrollId;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, String scrollId, float maxScore) {
|
||||
this(content, scrollId);
|
||||
this.maxScore = maxScore;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total) {
|
||||
super(content, pageableOrUnpaged(pageable), total);
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, float maxScore) {
|
||||
super(content, pageableOrUnpaged(pageable), total);
|
||||
this.maxScore = maxScore;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, String scrollId) {
|
||||
super(content, pageableOrUnpaged(pageable), total);
|
||||
this.scrollId = scrollId;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, String scrollId, float maxScore) {
|
||||
this(content, pageableOrUnpaged(pageable), total, scrollId);
|
||||
this.maxScore = maxScore;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, @Nullable Aggregations aggregations) {
|
||||
super(content, pageableOrUnpaged(pageable), total);
|
||||
this.aggregations = aggregations;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, @Nullable Aggregations aggregations,
|
||||
float maxScore) {
|
||||
this(content, pageableOrUnpaged(pageable), total, aggregations);
|
||||
this.maxScore = maxScore;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, @Nullable Aggregations aggregations,
|
||||
String scrollId) {
|
||||
this(content, pageableOrUnpaged(pageable), total, aggregations);
|
||||
this.scrollId = scrollId;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, long total, @Nullable Aggregations aggregations,
|
||||
String scrollId, float maxScore) {
|
||||
this(content, pageableOrUnpaged(pageable), total, aggregations, scrollId);
|
||||
this.maxScore = maxScore;
|
||||
}
|
||||
|
||||
public AggregatedPageImpl(List<T> content, Pageable pageable, SearchDocumentResponse response) {
|
||||
this(content, pageableOrUnpaged(pageable), response.getTotalHits(), response.getAggregations(),
|
||||
response.getScrollId(), response.getMaxScore());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAggregations() {
|
||||
return aggregations != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Aggregations getAggregations() {
|
||||
return aggregations;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Aggregation getAggregation(String name) {
|
||||
return aggregations == null ? null : aggregations.get(name);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getScrollId() {
|
||||
return scrollId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxScore() {
|
||||
return maxScore;
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
@org.springframework.lang.NonNullApi
|
||||
@org.springframework.lang.NonNullFields
|
||||
package org.springframework.data.elasticsearch.core.aggregation.impl;
|
@ -1,3 +0,0 @@
|
||||
@org.springframework.lang.NonNullApi
|
||||
@org.springframework.lang.NonNullFields
|
||||
package org.springframework.data.elasticsearch.core.aggregation;
|
@ -32,7 +32,6 @@ import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.data.convert.CustomConversions;
|
||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
||||
import org.springframework.data.elasticsearch.core.document.Document;
|
||||
import org.springframework.data.elasticsearch.core.document.SearchDocument;
|
||||
@ -44,6 +43,7 @@ import org.springframework.data.elasticsearch.core.query.Criteria;
|
||||
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.Field;
|
||||
import org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
|
||||
@ -231,11 +231,6 @@ public class MappingElasticsearchConverter
|
||||
|
||||
if (source instanceof SearchDocument) {
|
||||
SearchDocument searchDocument = (SearchDocument) source;
|
||||
if (targetEntity.hasScoreProperty()) {
|
||||
//noinspection ConstantConditions
|
||||
targetEntity.getPropertyAccessor(result) //
|
||||
.setProperty(targetEntity.getScoreProperty(), searchDocument.getScore());
|
||||
}
|
||||
populateScriptFields(result, searchDocument);
|
||||
}
|
||||
|
||||
@ -259,7 +254,7 @@ public class MappingElasticsearchConverter
|
||||
|
||||
for (ElasticsearchPersistentProperty prop : entity) {
|
||||
|
||||
if (entity.isConstructorArgument(prop) || prop.isScoreProperty() || !prop.isReadable()) {
|
||||
if (entity.isConstructorArgument(prop) || !prop.isReadable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -455,9 +450,9 @@ public class MappingElasticsearchConverter
|
||||
try {
|
||||
field.set(result, value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new ElasticsearchException("failed to set scripted field: " + name + " with value: " + value, e);
|
||||
throw new MappingException("failed to set scripted field: " + name + " with value: " + value, e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new ElasticsearchException("failed to access scripted field: " + name, e);
|
||||
throw new MappingException("failed to access scripted field: " + name, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -891,10 +886,6 @@ public class MappingElasticsearchConverter
|
||||
|
||||
}
|
||||
|
||||
if (target instanceof SearchDocument && property.isScoreProperty()) {
|
||||
return ((SearchDocument) target).getScore();
|
||||
}
|
||||
|
||||
if (!fieldName.contains(".")) {
|
||||
return target.get(fieldName);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ import org.elasticsearch.common.text.Text;
|
||||
import org.elasticsearch.index.get.GetResult;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
@ -422,7 +422,7 @@ public class DocumentAdapters {
|
||||
generator.flush();
|
||||
return new String(stream.toByteArray(), StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchException("Cannot render JSON", e);
|
||||
throw new MappingException("Cannot render JSON", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
@ -344,7 +344,7 @@ class MapDocument implements Document {
|
||||
try {
|
||||
return OBJECT_MAPPER.writeValueAsString(this);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new ElasticsearchException("Cannot render document to JSON", e);
|
||||
throw new MappingException("Cannot render document to JSON", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,30 +77,6 @@ public interface ElasticsearchPersistentEntity<T> extends PersistentEntity<T, El
|
||||
|
||||
boolean isCreateIndexAndMapping();
|
||||
|
||||
/**
|
||||
* Returns whether the {@link ElasticsearchPersistentEntity} has a score property. If this call returns
|
||||
* {@literal true}, {@link #getScoreProperty()} will return a non-{@literal null} value.
|
||||
*
|
||||
* @return false when {@link ElasticsearchPersistentEntity} does not define a score property.
|
||||
* @since 3.1
|
||||
* @deprecated since 4.0
|
||||
*/
|
||||
@Deprecated
|
||||
boolean hasScoreProperty();
|
||||
|
||||
/**
|
||||
* Returns the score property of the {@link ElasticsearchPersistentEntity}. Can be {@literal null} in case no score
|
||||
* property is available on the entity.
|
||||
*
|
||||
* @return the score {@link ElasticsearchPersistentProperty} of the {@link PersistentEntity} or {@literal null} if not
|
||||
* defined.
|
||||
* @since 3.1
|
||||
* @deprecated since 4.0
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
ElasticsearchPersistentProperty getScoreProperty();
|
||||
|
||||
/**
|
||||
* returns the {@link ElasticsearchPersistentProperty} with the given fieldName (may be set by the {@link Field}
|
||||
* annotation.
|
||||
|
@ -16,7 +16,6 @@
|
||||
package org.springframework.data.elasticsearch.core.mapping;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.elasticsearch.core.SearchHit;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@ -39,20 +38,6 @@ public interface ElasticsearchPersistentProperty extends PersistentProperty<Elas
|
||||
*/
|
||||
String getFieldName();
|
||||
|
||||
/**
|
||||
* Returns whether the current property is a <em>potential</em> score property of the owning
|
||||
* {@link ElasticsearchPersistentEntity}. This method is mainly used by {@link ElasticsearchPersistentEntity}
|
||||
* implementation to discover score property candidates on {@link ElasticsearchPersistentEntity} creation you should
|
||||
* rather call {@link ElasticsearchPersistentEntity#getScoreProperty()} to determine whether the current property is
|
||||
* the score property of that {@link ElasticsearchPersistentEntity} under consideration.
|
||||
*
|
||||
* @return
|
||||
* @since 3.1
|
||||
* @deprecated since 4.0, use {@link SearchHit#getScore()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
boolean isScoreProperty();
|
||||
|
||||
/**
|
||||
* Returns whether the current property is a <em>potential</em> parent property of the owning
|
||||
* {@link ElasticsearchPersistentEntity}. This method is mainly used by {@link ElasticsearchPersistentEntity}
|
||||
|
@ -73,7 +73,6 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
|
||||
private @Nullable String indexStoreType;
|
||||
@Deprecated private @Nullable String parentType;
|
||||
@Deprecated private @Nullable ElasticsearchPersistentProperty parentIdProperty;
|
||||
private @Nullable ElasticsearchPersistentProperty scoreProperty;
|
||||
private @Nullable ElasticsearchPersistentProperty seqNoPrimaryTermProperty;
|
||||
private @Nullable ElasticsearchPersistentProperty joinFieldProperty;
|
||||
private @Nullable String settingPath;
|
||||
@ -190,17 +189,6 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
|
||||
return createIndexAndMapping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScoreProperty() {
|
||||
return scoreProperty != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ElasticsearchPersistentProperty getScoreProperty() {
|
||||
return scoreProperty;
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
@Override
|
||||
@ -222,20 +210,6 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
|
||||
this.parentType = parentAnnotation.type();
|
||||
}
|
||||
|
||||
if (property.isScoreProperty()) {
|
||||
|
||||
ElasticsearchPersistentProperty scoreProperty = this.scoreProperty;
|
||||
|
||||
if (scoreProperty != null) {
|
||||
throw new MappingException(String.format(
|
||||
"Attempt to add score property %s but already have property %s registered "
|
||||
+ "as score property. Check your mapping configuration!",
|
||||
property.getField(), scoreProperty.getField()));
|
||||
}
|
||||
|
||||
this.scoreProperty = property;
|
||||
}
|
||||
|
||||
if (property.isSeqNoPrimaryTermProperty()) {
|
||||
|
||||
ElasticsearchPersistentProperty seqNoPrimaryTermProperty = this.seqNoPrimaryTermProperty;
|
||||
|
@ -31,7 +31,6 @@ import org.springframework.data.elasticsearch.annotations.GeoPointField;
|
||||
import org.springframework.data.elasticsearch.annotations.GeoShapeField;
|
||||
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||
import org.springframework.data.elasticsearch.annotations.Parent;
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.elasticsearch.core.completion.Completion;
|
||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchDateConverter;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoJson;
|
||||
@ -67,7 +66,6 @@ public class SimpleElasticsearchPersistentProperty extends
|
||||
|
||||
private static final List<String> SUPPORTED_ID_PROPERTY_NAMES = Arrays.asList("id", "document");
|
||||
|
||||
private final boolean isScore;
|
||||
private final boolean isParent;
|
||||
private final boolean isId;
|
||||
private final boolean isSeqNoPrimaryTerm;
|
||||
@ -95,7 +93,6 @@ public class SimpleElasticsearchPersistentProperty extends
|
||||
+ " Please annotate the id property with '@Id'", owner.getName() + "." + getName());
|
||||
}
|
||||
|
||||
this.isScore = isAnnotationPresent(Score.class);
|
||||
this.isParent = isAnnotationPresent(Parent.class);
|
||||
this.isSeqNoPrimaryTerm = SeqNoPrimaryTerm.class.isAssignableFrom(getRawType());
|
||||
|
||||
@ -105,11 +102,6 @@ public class SimpleElasticsearchPersistentProperty extends
|
||||
throw new MappingException(String.format("Version property %s must be of type Long!", property.getName()));
|
||||
}
|
||||
|
||||
if (isScore && !getType().equals(Float.TYPE) && !getType().equals(Float.class)) {
|
||||
throw new MappingException(
|
||||
String.format("Score property %s must be either of type float or Float!", property.getName()));
|
||||
}
|
||||
|
||||
if (isParent && !getType().equals(String.class)) {
|
||||
throw new MappingException(String.format("Parent property %s must be of type String!", property.getName()));
|
||||
}
|
||||
@ -278,11 +270,6 @@ public class SimpleElasticsearchPersistentProperty extends
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isScoreProperty() {
|
||||
return isScore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isImmutable() {
|
||||
return false;
|
||||
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.query;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* DeleteQuery
|
||||
*
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Peter-Josef Meisch
|
||||
* @deprecated since 4.0, use {@link Query} implementations and set {@link Query#setScrollTime(Duration)} and
|
||||
* {@link Query#getMaxResults()}
|
||||
*/
|
||||
@Deprecated
|
||||
public class DeleteQuery {
|
||||
|
||||
@Nullable private QueryBuilder query;
|
||||
@Nullable private Integer pageSize;
|
||||
@Nullable private Long scrollTimeInMillis;
|
||||
|
||||
@Nullable
|
||||
public QueryBuilder getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public void setQuery(QueryBuilder query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Long getScrollTimeInMillis() {
|
||||
return scrollTimeInMillis;
|
||||
}
|
||||
|
||||
public void setScrollTimeInMillis(Long scrollTimeInMillis) {
|
||||
this.scrollTimeInMillis = scrollTimeInMillis;
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.query;
|
||||
|
||||
/**
|
||||
* GetQuery
|
||||
*
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Peter-Josef Meisch
|
||||
* @deprecated since 4.0
|
||||
*/
|
||||
@Deprecated
|
||||
public class GetQuery {
|
||||
|
||||
public GetQuery(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
private String id;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static GetQuery getById(String id) {
|
||||
return new GetQuery(id);
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.repository;
|
||||
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
|
||||
/**
|
||||
* @param <T>
|
||||
* @param <ID>
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Oliver Gierke
|
||||
* @author Sascha Woo
|
||||
* @author Peter-Josef Meisch
|
||||
* @deprecated since 4.0, use {@link ElasticsearchRepository} instead
|
||||
*/
|
||||
@Deprecated
|
||||
@NoRepositoryBean
|
||||
public interface ElasticsearchCrudRepository<T, ID> extends PagingAndSortingRepository<T, ID> {}
|
@ -15,12 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.repository;
|
||||
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.core.IndexOperations;
|
||||
import org.springframework.data.elasticsearch.core.SearchPage;
|
||||
import org.springframework.data.elasticsearch.core.query.Query;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.lang.Nullable;
|
||||
@ -37,44 +33,6 @@ import org.springframework.lang.Nullable;
|
||||
@NoRepositoryBean
|
||||
public interface ElasticsearchRepository<T, ID> extends PagingAndSortingRepository<T, ID> {
|
||||
|
||||
/**
|
||||
* @deprecated since 4.0, use {@link #save(Object)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
default <S extends T> S index(S entity) {
|
||||
return save(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is intended to be used when many single inserts must be made that cannot be aggregated to be inserted
|
||||
* with {@link #saveAll(Iterable)}. This might lead to a temporary inconsistent state until {@link #refresh()} is
|
||||
* called.
|
||||
*
|
||||
* @deprecated since 4.0, use a custom repository implementation instead
|
||||
*/
|
||||
@Deprecated
|
||||
<S extends T> S indexWithoutRefresh(S entity);
|
||||
|
||||
/**
|
||||
* @deprecated since 4.0, use standard repository method naming or @{@link Query}
|
||||
* annotated methods, or {@link org.springframework.data.elasticsearch.core.ElasticsearchOperations}.
|
||||
*/
|
||||
@Deprecated
|
||||
Iterable<T> search(QueryBuilder query);
|
||||
|
||||
/**
|
||||
* @deprecated since 4.0, use standard repository method naming or @{@link Query}
|
||||
* annotated methods, or {@link org.springframework.data.elasticsearch.core.ElasticsearchOperations}.
|
||||
*/
|
||||
@Deprecated
|
||||
Page<T> search(QueryBuilder query, Pageable pageable);
|
||||
|
||||
/**
|
||||
* @deprecated since 4.0, use standard repository method naming or @{@link Query}
|
||||
* annotated methods, or {@link org.springframework.data.elasticsearch.core.ElasticsearchOperations}.
|
||||
*/
|
||||
Page<T> search(Query searchQuery);
|
||||
|
||||
/**
|
||||
* Search for similar entities using a morelikethis query
|
||||
*
|
||||
@ -84,11 +42,4 @@ public interface ElasticsearchRepository<T, ID> extends PagingAndSortingReposito
|
||||
* @return
|
||||
*/
|
||||
Page<T> searchSimilar(T entity, @Nullable String[] fields, Pageable pageable);
|
||||
|
||||
/**
|
||||
* @deprecated since 4.0, use {@link IndexOperations#refresh()} instead. Repository methods should call refresh
|
||||
* in their implementation.
|
||||
*/
|
||||
@Deprecated
|
||||
void refresh();
|
||||
}
|
||||
|
@ -25,11 +25,4 @@ import org.springframework.data.repository.core.EntityMetadata;
|
||||
public interface ElasticsearchEntityMetadata<T> extends EntityMetadata<T> {
|
||||
|
||||
String getIndexName();
|
||||
|
||||
/**
|
||||
* @return the type for the index
|
||||
* @deprecated since 4.0
|
||||
*/
|
||||
@Deprecated
|
||||
String getIndexTypeName();
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public class ElasticsearchPartQuery extends AbstractElasticsearchRepositoryQuery
|
||||
if (queryMethod.isSearchPageMethod()) {
|
||||
result = SearchHitSupport.searchPageFor(searchHits, query.getPageable());
|
||||
} else {
|
||||
result = SearchHitSupport.page(searchHits, query.getPageable());
|
||||
result = SearchHitSupport.unwrapSearchHits(SearchHitSupport.searchPageFor(searchHits, query.getPageable()));
|
||||
}
|
||||
} else if (queryMethod.isStreamQuery()) {
|
||||
if (accessor.getPageable().isUnpaged()) {
|
||||
@ -126,7 +126,9 @@ public class ElasticsearchPartQuery extends AbstractElasticsearchRepositoryQuery
|
||||
result = elasticsearchOperations.searchOne(query, clazz, index);
|
||||
}
|
||||
|
||||
return queryMethod.isNotSearchHitMethod() ? SearchHitSupport.unwrapSearchHits(result) : result;
|
||||
return (queryMethod.isNotSearchHitMethod() && queryMethod.isNotSearchPageMethod())
|
||||
? SearchHitSupport.unwrapSearchHits(result)
|
||||
: result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -182,7 +182,7 @@ public class ElasticsearchQueryMethod extends QueryMethod {
|
||||
}
|
||||
|
||||
/**
|
||||
* retusn the declared return type for this method.
|
||||
* returns the declared return type for this method.
|
||||
*
|
||||
* @return the return type
|
||||
* @since 4.0
|
||||
@ -197,8 +197,8 @@ public class ElasticsearchQueryMethod extends QueryMethod {
|
||||
}
|
||||
|
||||
/**
|
||||
* checks whether the return type of the underlying method is a
|
||||
* {@link org.springframework.data.elasticsearch.core.SearchHits} or a collection of
|
||||
* checks whether the return type of the underlying method nether a
|
||||
* {@link org.springframework.data.elasticsearch.core.SearchHits} nor a collection of
|
||||
* {@link org.springframework.data.elasticsearch.core.SearchHit}.
|
||||
*
|
||||
* @return true if the method has not a {@link org.springframework.data.elasticsearch.core.SearchHit}t related return
|
||||
@ -208,4 +208,13 @@ public class ElasticsearchQueryMethod extends QueryMethod {
|
||||
public boolean isNotSearchHitMethod() {
|
||||
return !isSearchHitMethod();
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the return type is not {@link SearchPage}.
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
public boolean isNotSearchPageMethod() {
|
||||
return !isSearchPageMethod();
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public class ElasticsearchStringQuery extends AbstractElasticsearchRepositoryQue
|
||||
if (queryMethod.isPageQuery()) {
|
||||
stringQuery.setPageable(accessor.getPageable());
|
||||
SearchHits<?> searchHits = elasticsearchOperations.search(stringQuery, clazz, index);
|
||||
result = SearchHitSupport.page(searchHits, stringQuery.getPageable());
|
||||
result = SearchHitSupport.searchPageFor(searchHits, stringQuery.getPageable());
|
||||
} else if (queryMethod.isStreamQuery()) {
|
||||
if (accessor.getPageable().isUnpaged()) {
|
||||
stringQuery.setPageable(PageRequest.of(0, DEFAULT_STREAM_BATCH_SIZE));
|
||||
|
@ -16,7 +16,6 @@
|
||||
package org.springframework.data.elasticsearch.repository.query;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@ -43,11 +42,6 @@ public class SimpleElasticsearchEntityMetadata<T> implements ElasticsearchEntity
|
||||
return entity.getIndexCoordinates().getIndexName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIndexTypeName() {
|
||||
return IndexCoordinates.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<T> getJavaType() {
|
||||
return type;
|
||||
|
@ -24,7 +24,6 @@ import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.elasticsearch.index.query.IdsQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
@ -39,7 +38,7 @@ import org.springframework.data.elasticsearch.core.RefreshPolicy;
|
||||
import org.springframework.data.elasticsearch.core.SearchHit;
|
||||
import org.springframework.data.elasticsearch.core.SearchHitSupport;
|
||||
import org.springframework.data.elasticsearch.core.SearchHits;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.SearchPage;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery;
|
||||
@ -124,7 +123,8 @@ public class SimpleElasticsearchRepository<T, ID> implements ElasticsearchReposi
|
||||
public Page<T> findAll(Pageable pageable) {
|
||||
NativeSearchQuery query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withPageable(pageable).build();
|
||||
SearchHits<T> searchHits = execute(operations -> operations.search(query, entityClass, getIndexCoordinates()));
|
||||
AggregatedPage<SearchHit<T>> page = SearchHitSupport.page(searchHits, query.getPageable());
|
||||
// noinspection ConstantConditions
|
||||
SearchPage<T> page = SearchHitSupport.searchPageFor(searchHits, query.getPageable());
|
||||
return (Page<T>) SearchHitSupport.unwrapSearchHits(page);
|
||||
}
|
||||
|
||||
@ -191,14 +191,6 @@ public class SimpleElasticsearchRepository<T, ID> implements ElasticsearchReposi
|
||||
return Streamable.of(saveAll(entities)).stream().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public <S extends T> S indexWithoutRefresh(S entity) {
|
||||
Assert.notNull(entity, "Cannot save 'null' entity.");
|
||||
// noinspection ConstantConditions
|
||||
return execute(operations -> operations.save(entity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S extends T> Iterable<S> saveAll(Iterable<S> entities) {
|
||||
|
||||
@ -216,40 +208,6 @@ public class SimpleElasticsearchRepository<T, ID> implements ElasticsearchReposi
|
||||
return execute(operations -> operations.exists(stringIdRepresentation(id), getIndexCoordinates()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Iterable<T> search(QueryBuilder query) {
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(query).build();
|
||||
long count = execute(operations -> operations.count(searchQuery, entityClass, getIndexCoordinates()));
|
||||
|
||||
if (count == 0) {
|
||||
return new PageImpl<>(Collections.emptyList());
|
||||
}
|
||||
searchQuery.setPageable(PageRequest.of(0, (int) count));
|
||||
SearchHits<T> searchHits = execute(
|
||||
operations -> operations.search(searchQuery, entityClass, getIndexCoordinates()));
|
||||
AggregatedPage<SearchHit<T>> page = SearchHitSupport.page(searchHits, searchQuery.getPageable());
|
||||
return (Page<T>) SearchHitSupport.unwrapSearchHits(page);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Page<T> search(QueryBuilder query, Pageable pageable) {
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(query).withPageable(pageable).build();
|
||||
SearchHits<T> searchHits = execute(
|
||||
operations -> operations.search(searchQuery, entityClass, getIndexCoordinates()));
|
||||
AggregatedPage<SearchHit<T>> page = SearchHitSupport.page(searchHits, searchQuery.getPageable());
|
||||
return (Page<T>) SearchHitSupport.unwrapSearchHits(page);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Page<T> search(Query query) {
|
||||
SearchHits<T> searchHits = execute(operations -> operations.search(query, entityClass, getIndexCoordinates()));
|
||||
AggregatedPage<SearchHit<T>> page = SearchHitSupport.page(searchHits, query.getPageable());
|
||||
return (Page<T>) SearchHitSupport.unwrapSearchHits(page);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Page<T> searchSimilar(T entity, @Nullable String[] fields, Pageable pageable) {
|
||||
@ -266,8 +224,8 @@ public class SimpleElasticsearchRepository<T, ID> implements ElasticsearchReposi
|
||||
}
|
||||
|
||||
SearchHits<T> searchHits = execute(operations -> operations.search(query, entityClass, getIndexCoordinates()));
|
||||
AggregatedPage<SearchHit<T>> page = SearchHitSupport.page(searchHits, pageable);
|
||||
return (Page<T>) SearchHitSupport.unwrapSearchHits(page);
|
||||
SearchPage<T> searchPage = SearchHitSupport.searchPageFor(searchHits, pageable);
|
||||
return (Page<T>) SearchHitSupport.unwrapSearchHits(searchPage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -342,12 +300,6 @@ public class SimpleElasticsearchRepository<T, ID> implements ElasticsearchReposi
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void refresh() {
|
||||
indexOperations.refresh();
|
||||
}
|
||||
|
||||
private void doRefresh() {
|
||||
RefreshPolicy refreshPolicy = null;
|
||||
|
||||
|
@ -34,7 +34,6 @@ import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
@ -90,9 +89,6 @@ public class EnableNestedElasticsearchRepositoriesTests {
|
||||
private String highlightedMessage;
|
||||
private GeoPoint location;
|
||||
@Version private Long version;
|
||||
|
||||
@Score private float score;
|
||||
|
||||
}
|
||||
|
||||
interface SampleRepository extends Repository<SampleEntity, Long> {}
|
||||
|
@ -38,7 +38,6 @@ import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.IndexOperations;
|
||||
@ -136,7 +135,6 @@ public class EnableElasticsearchRepositoriesTests implements ApplicationContextA
|
||||
private String highlightedMessage;
|
||||
private GeoPoint location;
|
||||
@Version private Long version;
|
||||
@Score private float score;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
@ -27,7 +27,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.lucene.search.TotalHits;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
@ -35,15 +34,12 @@ import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.document.Document;
|
||||
import org.springframework.data.elasticsearch.core.event.AfterConvertCallback;
|
||||
import org.springframework.data.elasticsearch.core.event.AfterSaveCallback;
|
||||
import org.springframework.data.elasticsearch.core.event.BeforeConvertCallback;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.BulkOptions;
|
||||
import org.springframework.data.elasticsearch.core.query.GetQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
@ -238,18 +234,6 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
|
||||
assertThat(result.firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void getViaQueryShouldInvokeAfterConvertCallback() {
|
||||
|
||||
template.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
@SuppressWarnings("deprecation") // we know what we test
|
||||
Person result = template.get(new GetQuery("init"), Person.class, index);
|
||||
|
||||
verify(afterConvertCallback).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index));
|
||||
assertThat(result.firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void multiGetShouldInvokeAfterConvertCallback() {
|
||||
|
||||
@ -267,158 +251,26 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
|
||||
return new NativeSearchQueryBuilder().withIds(Arrays.asList("init1", "init2")).build();
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void queryForObjectShouldInvokeAfterConvertCallback() {
|
||||
|
||||
template.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
doReturn(nSearchHits(1)).when(searchResponse).getHits();
|
||||
|
||||
@SuppressWarnings("deprecation") // we know what we test
|
||||
Person result = template.queryForObject(queryForOne(), Person.class, index);
|
||||
|
||||
verify(afterConvertCallback).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index));
|
||||
assertThat(result.firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
private Query queryForOne() {
|
||||
return new NativeSearchQueryBuilder().withIds(singletonList("init")).build();
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void queryForPageShouldInvokeAfterConvertCallback() {
|
||||
|
||||
template.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
@SuppressWarnings("deprecation") // we know what we test
|
||||
AggregatedPage<Person> results = template.queryForPage(queryForTwo(), Person.class, index);
|
||||
|
||||
verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
|
||||
eq(index));
|
||||
assertThat(results.getContent().get(0).firstname).isEqualTo("after-convert");
|
||||
assertThat(results.getContent().get(1).firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void queryForPageWithMultipleQueriesAndSameEntityClassShouldInvokeAfterConvertCallback() {
|
||||
|
||||
template.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
@SuppressWarnings("deprecation") // we know what we test
|
||||
List<Page<Person>> results = template.queryForPage(singletonList(queryForTwo()), Person.class, index);
|
||||
|
||||
verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
|
||||
eq(index));
|
||||
List<Person> persons = results.get(0).getContent();
|
||||
assertThat(persons.get(0).firstname).isEqualTo("after-convert");
|
||||
assertThat(persons.get(1).firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void queryForPageWithMultipleQueriesAndEntityClassesShouldInvokeAfterConvertCallback() {
|
||||
|
||||
template.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
@SuppressWarnings("deprecation") // we know what we test
|
||||
List<AggregatedPage<?>> results = template.queryForPage(singletonList(queryForTwo()), singletonList(Person.class),
|
||||
index);
|
||||
|
||||
verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
|
||||
eq(index));
|
||||
List<Person> persons = results.get(0).getContent().stream().map(Person.class::cast).collect(Collectors.toList());
|
||||
assertThat(persons.get(0).firstname).isEqualTo("after-convert");
|
||||
assertThat(persons.get(1).firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void streamShouldInvokeAfterConvertCallback() {
|
||||
|
||||
template.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
CloseableIterator<Person> results = template.stream(queryForTwo(), Person.class, index);
|
||||
|
||||
verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
|
||||
eq(index));
|
||||
assertThat(results.next().firstname).isEqualTo("after-convert");
|
||||
assertThat(results.next().firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void searchScrollContinueShouldInvokeAfterConvertCallback() {
|
||||
|
||||
template.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
CloseableIterator<Person> results = template.stream(queryForTwo(), Person.class, index);
|
||||
|
||||
skipItemsFromScrollStart(results);
|
||||
assertThat(results.next().firstname).isEqualTo("after-convert");
|
||||
assertThat(results.next().firstname).isEqualTo("after-convert");
|
||||
|
||||
verify(afterConvertCallback, times(4)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
|
||||
eq(index));
|
||||
}
|
||||
|
||||
private void skipItemsFromScrollStart(CloseableIterator<Person> results) {
|
||||
results.next();
|
||||
results.next();
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void queryForListShouldInvokeAfterConvertCallback() {
|
||||
|
||||
template.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
@SuppressWarnings("deprecation") // we know what we test
|
||||
List<Person> results = template.queryForList(queryForTwo(), Person.class, index);
|
||||
|
||||
verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
|
||||
eq(index));
|
||||
assertThat(results.get(0).firstname).isEqualTo("after-convert");
|
||||
assertThat(results.get(1).firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void queryForListWithMultipleQueriesAndSameEntityClassShouldInvokeAfterConvertCallback() {
|
||||
|
||||
template.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
@SuppressWarnings("deprecation") // we know what we test
|
||||
List<List<Person>> results = template.queryForList(singletonList(queryForTwo()), Person.class, index);
|
||||
|
||||
verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
|
||||
eq(index));
|
||||
List<Person> persons = results.get(0);
|
||||
assertThat(persons.get(0).firstname).isEqualTo("after-convert");
|
||||
assertThat(persons.get(1).firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void queryForListWithMultipleQueriesAndEntityClassesShouldInvokeAfterConvertCallback() {
|
||||
|
||||
template.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
@SuppressWarnings("deprecation") // we know what we test
|
||||
List<List<?>> results = template.queryForList(singletonList(queryForTwo()), singletonList(Person.class), index);
|
||||
|
||||
verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
|
||||
eq(index));
|
||||
List<Person> persons = results.get(0).stream().map(Person.class::cast).collect(Collectors.toList());
|
||||
assertThat(persons.get(0).firstname).isEqualTo("after-convert");
|
||||
assertThat(persons.get(1).firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void moreLikeThisShouldInvokeAfterConvertCallback() {
|
||||
|
||||
template.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
@SuppressWarnings("deprecation") // we know what we test
|
||||
AggregatedPage<Person> results = template.moreLikeThis(moreLikeThisQuery(), Person.class, index);
|
||||
SearchHits<Person> results = template.search(moreLikeThisQuery(), Person.class, index);
|
||||
|
||||
verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
|
||||
eq(index));
|
||||
assertThat(results.getContent().get(0).firstname).isEqualTo("after-convert");
|
||||
assertThat(results.getContent().get(1).firstname).isEqualTo("after-convert");
|
||||
assertThat(results.getSearchHit(0).getContent().firstname).isEqualTo("after-convert");
|
||||
assertThat(results.getSearchHit(1).getContent().firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
private MoreLikeThisQuery moreLikeThisQuery() {
|
||||
|
@ -58,6 +58,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Version;
|
||||
@ -65,7 +66,6 @@ import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
@ -73,7 +73,6 @@ import org.springframework.data.elasticsearch.annotations.InnerField;
|
||||
import org.springframework.data.elasticsearch.annotations.JoinTypeRelation;
|
||||
import org.springframework.data.elasticsearch.annotations.JoinTypeRelations;
|
||||
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
import org.springframework.data.elasticsearch.core.index.AliasAction;
|
||||
@ -1784,21 +1783,7 @@ public abstract class ElasticsearchTemplateTests {
|
||||
|
||||
// when
|
||||
assertThatThrownBy(() -> operations.index(indexQuery, IndexCoordinates.of(INDEX_NAME_SAMPLE_ENTITY)))
|
||||
.isInstanceOf(ElasticsearchException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnIds() {
|
||||
// given
|
||||
List<IndexQuery> entities = createSampleEntitiesWithMessage("Test message", 30);
|
||||
// when
|
||||
operations.bulkIndex(entities, index);
|
||||
indexOperations.refresh();
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("message", "message"))
|
||||
.withPageable(PageRequest.of(0, 100)).build();
|
||||
// then
|
||||
List<String> ids = operations.queryForIds(searchQuery, SampleEntity.class, index);
|
||||
assertThat(ids).hasSize(30);
|
||||
.isInstanceOf(InvalidDataAccessApiUsageException.class);
|
||||
}
|
||||
|
||||
@Test // DATAES-848
|
||||
@ -3269,7 +3254,7 @@ public abstract class ElasticsearchTemplateTests {
|
||||
OptimisticEntity original = new OptimisticEntity();
|
||||
original.setMessage("It's fine");
|
||||
OptimisticEntity saved = operations.save(original);
|
||||
operations.refresh(OptimisticEntity.class);
|
||||
operations.indexOps(OptimisticEntity.class).refresh();
|
||||
|
||||
List<OptimisticEntity> retrievedList = operations.multiGet(queryForOne(saved.getId()), OptimisticEntity.class,
|
||||
operations.getIndexCoordinatesFor(OptimisticEntity.class));
|
||||
@ -3287,7 +3272,7 @@ public abstract class ElasticsearchTemplateTests {
|
||||
OptimisticEntity original = new OptimisticEntity();
|
||||
original.setMessage("It's fine");
|
||||
OptimisticEntity saved = operations.save(original);
|
||||
operations.refresh(OptimisticEntity.class);
|
||||
operations.indexOps(OptimisticEntity.class).refresh();
|
||||
|
||||
SearchHits<OptimisticEntity> retrievedHits = operations.search(queryForOne(saved.getId()), OptimisticEntity.class);
|
||||
OptimisticEntity retrieved = retrievedHits.getSearchHit(0).getContent();
|
||||
@ -3300,7 +3285,7 @@ public abstract class ElasticsearchTemplateTests {
|
||||
OptimisticEntity original = new OptimisticEntity();
|
||||
original.setMessage("It's fine");
|
||||
OptimisticEntity saved = operations.save(original);
|
||||
operations.refresh(OptimisticEntity.class);
|
||||
operations.indexOps(OptimisticEntity.class).refresh();
|
||||
|
||||
List<Query> queries = singletonList(queryForOne(saved.getId()));
|
||||
List<SearchHits<OptimisticEntity>> retrievedHits = operations.multiSearch(queries, OptimisticEntity.class,
|
||||
@ -3315,7 +3300,7 @@ public abstract class ElasticsearchTemplateTests {
|
||||
OptimisticEntity original = new OptimisticEntity();
|
||||
original.setMessage("It's fine");
|
||||
OptimisticEntity saved = operations.save(original);
|
||||
operations.refresh(OptimisticEntity.class);
|
||||
operations.indexOps(OptimisticEntity.class).refresh();
|
||||
|
||||
SearchHitsIterator<OptimisticEntity> retrievedHits = operations.searchForStream(queryForOne(saved.getId()),
|
||||
OptimisticEntity.class);
|
||||
@ -3673,7 +3658,6 @@ public abstract class ElasticsearchTemplateTests {
|
||||
private boolean available;
|
||||
private GeoPoint location;
|
||||
@Version private Long version;
|
||||
@Score private float score;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -238,30 +238,6 @@ public class ReactiveElasticsearchTemplateCallbackTests {
|
||||
assertThat(results.get(1).firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void findByIdShouldInvokeAfterConvertCallbacks() {
|
||||
|
||||
template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
@SuppressWarnings("deprecation") // we know what we test
|
||||
Person result = template.findById("init", Person.class).block(Duration.ofSeconds(1));
|
||||
|
||||
verify(afterConvertCallback).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
|
||||
assertThat(result.firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void findByIdWithIndexCoordinatesShouldInvokeAfterConvertCallbacks() {
|
||||
|
||||
template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
@SuppressWarnings("deprecation") // we know what we test
|
||||
Person result = template.findById("init", Person.class, index).block(Duration.ofSeconds(1));
|
||||
|
||||
verify(afterConvertCallback).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index));
|
||||
assertThat(result.firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void getShouldInvokeAfterConvertCallbacks() {
|
||||
|
||||
@ -284,20 +260,6 @@ public class ReactiveElasticsearchTemplateCallbackTests {
|
||||
assertThat(result.firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void findUsingPageableShouldInvokeAfterConvertCallbacks() {
|
||||
|
||||
template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
@SuppressWarnings("deprecation") // we know what we test
|
||||
List<Person> results = template.find(pagedQueryForTwo(), Person.class).timeout(Duration.ofSeconds(1)).toStream()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
|
||||
assertThat(results.get(0).firstname).isEqualTo("after-convert");
|
||||
assertThat(results.get(1).firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
private Query pagedQueryForTwo() {
|
||||
return new NativeSearchQueryBuilder().withIds(Arrays.asList("init1", "init2")).withPageable(PageRequest.of(0, 10))
|
||||
.build();
|
||||
@ -307,68 +269,6 @@ public class ReactiveElasticsearchTemplateCallbackTests {
|
||||
return Document.create().append("id", "init").append("firstname", "luke");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void findUsingScrollShouldInvokeAfterConvertCallbacks() {
|
||||
|
||||
template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
@SuppressWarnings("deprecation") // we know what we test
|
||||
List<Person> results = template.find(scrollingQueryForTwo(), Person.class).timeout(Duration.ofSeconds(1)).toStream()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
|
||||
assertThat(results.get(0).firstname).isEqualTo("after-convert");
|
||||
assertThat(results.get(1).firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
private Query scrollingQueryForTwo() {
|
||||
return new NativeSearchQueryBuilder().withIds(Arrays.asList("init1", "init2")).build();
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void findWithIndexCoordinatesShouldInvokeAfterConvertCallbacks() {
|
||||
|
||||
template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
@SuppressWarnings("deprecation") // we know what we test
|
||||
List<Person> results = template.find(pagedQueryForTwo(), Person.class, index).timeout(Duration.ofSeconds(1))
|
||||
.toStream().collect(Collectors.toList());
|
||||
|
||||
verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
|
||||
eq(index));
|
||||
assertThat(results.get(0).firstname).isEqualTo("after-convert");
|
||||
assertThat(results.get(1).firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void findWithReturnTypeShouldInvokeAfterConvertCallbacks() {
|
||||
|
||||
template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
@SuppressWarnings("deprecation") // we know what we test
|
||||
List<Person> results = template.find(pagedQueryForTwo(), Person.class, Person.class).timeout(Duration.ofSeconds(1))
|
||||
.toStream().collect(Collectors.toList());
|
||||
|
||||
verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
|
||||
assertThat(results.get(0).firstname).isEqualTo("after-convert");
|
||||
assertThat(results.get(1).firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void findWithReturnTypeAndIndexCoordinatesShouldInvokeAfterConvertCallbacks() {
|
||||
|
||||
template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback));
|
||||
|
||||
@SuppressWarnings("deprecation") // we know what we test
|
||||
List<Person> results = template.find(pagedQueryForTwo(), Person.class, Person.class, index)
|
||||
.timeout(Duration.ofSeconds(1)).toStream().collect(Collectors.toList());
|
||||
|
||||
verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
|
||||
eq(index));
|
||||
assertThat(results.get(0).firstname).isEqualTo("after-convert");
|
||||
assertThat(results.get(1).firstname).isEqualTo("after-convert");
|
||||
}
|
||||
|
||||
@Test // DATAES-772
|
||||
void searchShouldInvokeAfterConvertCallbacks() {
|
||||
|
||||
|
@ -67,7 +67,6 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.elasticsearch.UncategorizedElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.*;
|
||||
@ -302,7 +301,7 @@ public class ReactiveElasticsearchTemplateIntegrationTests {
|
||||
@Test // DATAES-519
|
||||
public void existsShouldReturnFalseWhenIndexDoesNotExist() {
|
||||
|
||||
template.exists("foo", SampleEntity.class, IndexCoordinates.of("no-such-index")) //
|
||||
template.exists("foo", IndexCoordinates.of("no-such-index")) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(false) //
|
||||
.verifyComplete();
|
||||
@ -1130,7 +1129,6 @@ public class ReactiveElasticsearchTemplateIntegrationTests {
|
||||
@Field(type = Text, store = true, fielddata = true) private String message;
|
||||
private int rate;
|
||||
@Version private Long version;
|
||||
@Score private float score;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.aggregation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
|
||||
|
||||
/**
|
||||
* @author Remco Zigterman
|
||||
*/
|
||||
public class AggregatedPageImplTest {
|
||||
|
||||
@Test
|
||||
public void constructFacetedPageWithPageable() {
|
||||
Page<String> page = new AggregatedPageImpl<>(Arrays.asList("Test", "Test 2"), PageRequest.of(0, 2), 10);
|
||||
|
||||
assertThat(page.getTotalElements()).isEqualTo(10);
|
||||
assertThat(page.getNumberOfElements()).isEqualTo(2);
|
||||
assertThat(page.getSize()).isEqualTo(2);
|
||||
assertThat(page.getTotalPages()).isEqualTo(5);
|
||||
}
|
||||
}
|
@ -214,11 +214,12 @@ public class MappingBuilderIntegrationTests extends MappingContextBaseTests {
|
||||
public void shouldUseKeywordNormalizer() {
|
||||
|
||||
// given
|
||||
operations.createIndex(NormalizerEntity.class);
|
||||
operations.putMapping(NormalizerEntity.class);
|
||||
IndexOperations indexOps = operations.indexOps(NormalizerEntity.class);
|
||||
indexOps.create();
|
||||
indexOps.putMapping();
|
||||
|
||||
// when
|
||||
Map mapping = operations.getMapping(NormalizerEntity.class);
|
||||
Map mapping = indexOps.getMapping();
|
||||
Map properties = (Map) mapping.get("properties");
|
||||
Map fieldName = (Map) properties.get("name");
|
||||
Map fieldDescriptionLowerCase = (Map) ((Map) ((Map) properties.get("description")).get("fields")).get("lower_case");
|
||||
|
@ -11,7 +11,6 @@ import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
import org.springframework.data.elasticsearch.annotations.InnerField;
|
||||
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@ -42,13 +41,6 @@ public class MappingParametersTest extends MappingContextBaseTests {
|
||||
assertThat(mappingParameters).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAES-621
|
||||
public void shouldNotCreateParametersForUnknownAnnotation() {
|
||||
Annotation annotation = entity.getRequiredPersistentProperty("score").findAnnotation(Score.class);
|
||||
|
||||
assertThatThrownBy(() -> MappingParameters.from(annotation)).isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test // DATAES-621
|
||||
public void shouldNotAllowDocValueFalseOnFieldTypeText() {
|
||||
Annotation annotation = entity.getRequiredPersistentProperty("docValuesText").findAnnotation(Field.class);
|
||||
@ -77,7 +69,6 @@ public class MappingParametersTest extends MappingContextBaseTests {
|
||||
@Nullable @Field private String field;
|
||||
@Nullable @MultiField(mainField = @Field,
|
||||
otherFields = { @InnerField(suffix = "test", type = FieldType.Text) }) private String mainField;
|
||||
@Score private float score;
|
||||
@Nullable @Field(type = FieldType.Text, docValues = false) private String docValuesText;
|
||||
@Nullable @Field(type = FieldType.Nested, docValues = false) private String docValuesNested;
|
||||
@Nullable @Field(type = Object, enabled = true) private String enabledObject;
|
||||
|
@ -21,7 +21,6 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.model.Property;
|
||||
@ -71,17 +70,6 @@ public class SimpleElasticsearchPersistentEntityTests {
|
||||
}).isInstanceOf(MappingException.class);
|
||||
}
|
||||
|
||||
@Test // DATAES-462
|
||||
public void rejectsMultipleScoreProperties() {
|
||||
|
||||
SimpleElasticsearchMappingContext context = new SimpleElasticsearchMappingContext();
|
||||
|
||||
assertThatExceptionOfType(MappingException.class) //
|
||||
.isThrownBy(() -> context.getRequiredPersistentEntity(TwoScoreProperties.class)) //
|
||||
.withMessageContaining("first") //
|
||||
.withMessageContaining("second");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFindPropertiesByMappedName() {
|
||||
|
||||
@ -194,13 +182,6 @@ public class SimpleElasticsearchPersistentEntityTests {
|
||||
}
|
||||
}
|
||||
|
||||
// DATAES-462
|
||||
static class TwoScoreProperties {
|
||||
|
||||
@Score float first;
|
||||
@Score float second;
|
||||
}
|
||||
|
||||
private static class FieldNameEntity {
|
||||
@Nullable @Id private String id;
|
||||
@Nullable @Field(name = "renamed-field") private String renamedField;
|
||||
|
@ -34,7 +34,6 @@ import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
import org.springframework.data.elasticsearch.annotations.InnerField;
|
||||
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.model.FieldNamingStrategy;
|
||||
@ -56,14 +55,6 @@ public class SimpleElasticsearchPersistentPropertyUnitTests {
|
||||
|
||||
private final SimpleElasticsearchMappingContext context = new SimpleElasticsearchMappingContext();
|
||||
|
||||
@Test // DATAES-462
|
||||
public void rejectsScorePropertyOfTypeOtherthanFloat() {
|
||||
|
||||
assertThatExceptionOfType(MappingException.class) //
|
||||
.isThrownBy(() -> context.getRequiredPersistentEntity(InvalidScoreProperty.class)) //
|
||||
.withMessageContaining("scoreProperty");
|
||||
}
|
||||
|
||||
@Test // DATAES-562
|
||||
public void fieldAnnotationWithNameSetsFieldname() {
|
||||
|
||||
@ -252,10 +243,6 @@ public class SimpleElasticsearchPersistentPropertyUnitTests {
|
||||
assertThat(property.getFieldName()).isEqualTo("CUStomFIEldnAME");
|
||||
}
|
||||
|
||||
static class InvalidScoreProperty {
|
||||
@Nullable @Score String scoreProperty;
|
||||
}
|
||||
|
||||
static class FieldNameProperty {
|
||||
@Nullable @Field(name = "by-name") String fieldProperty;
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.IndexOperations;
|
||||
import org.springframework.data.elasticsearch.core.SearchHit;
|
||||
@ -821,6 +820,5 @@ public class CriteriaQueryIntegrationTests {
|
||||
@Field(type = Text, store = true, fielddata = true) private String message;
|
||||
private int rate;
|
||||
@Version private Long version;
|
||||
@Score private float score;
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ public class FieldDynamicMappingEntityRepositoryTests {
|
||||
// given
|
||||
|
||||
// then
|
||||
Map<String, Object> mapping = operations.getMapping(FieldDynamicMappingEntity.class);
|
||||
Map<String, Object> mapping = operations.indexOps(FieldDynamicMappingEntity.class).getMapping();
|
||||
assertThat(mapping).isNotNull();
|
||||
|
||||
Map<String, Object> properties = (Map<String, Object>) mapping.get("properties");
|
||||
|
@ -202,45 +202,6 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
assertThat(entityFromElasticSearch).isNotPresent();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSearchDocumentsGivenSearchQuery() {
|
||||
|
||||
// given
|
||||
UUID documentId = UUID.randomUUID();
|
||||
SampleEntityUUIDKeyed sampleEntityUUIDKeyed = new SampleEntityUUIDKeyed();
|
||||
sampleEntityUUIDKeyed.setId(documentId);
|
||||
sampleEntityUUIDKeyed.setMessage("some test message");
|
||||
sampleEntityUUIDKeyed.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntityUUIDKeyed);
|
||||
|
||||
NativeSearchQuery query = new NativeSearchQueryBuilder().withQuery(termQuery("message", "test")).build();
|
||||
// when
|
||||
Page<SampleEntityUUIDKeyed> page = repository.search(query);
|
||||
|
||||
// then
|
||||
assertThat(page).isNotNull();
|
||||
assertThat(page.getNumberOfElements()).isGreaterThanOrEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSearchDocumentsGivenElasticsearchQuery() {
|
||||
|
||||
// given
|
||||
UUID documentId = UUID.randomUUID();
|
||||
SampleEntityUUIDKeyed sampleEntityUUIDKeyed = new SampleEntityUUIDKeyed();
|
||||
sampleEntityUUIDKeyed.setId(documentId);
|
||||
sampleEntityUUIDKeyed.setMessage("hello world.");
|
||||
sampleEntityUUIDKeyed.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntityUUIDKeyed);
|
||||
|
||||
// when
|
||||
Page<SampleEntityUUIDKeyed> page = repository.search(termQuery("message", "world"), PageRequest.of(0, 50));
|
||||
|
||||
// then
|
||||
assertThat(page).isNotNull();
|
||||
assertThat(page.getNumberOfElements()).isGreaterThanOrEqualTo(1);
|
||||
}
|
||||
|
||||
@Test // DATAES-82
|
||||
public void shouldFindAllByIdQuery() {
|
||||
|
||||
@ -291,9 +252,8 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
repository.saveAll(sampleEntities);
|
||||
|
||||
// then
|
||||
Page<SampleEntityUUIDKeyed> entities = repository.search(termQuery("id", documentId.toString()),
|
||||
PageRequest.of(0, 50));
|
||||
assertThat(entities).isNotNull();
|
||||
Iterable<SampleEntityUUIDKeyed> entities = repository.findAll();
|
||||
assertThat(entities).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -335,8 +295,8 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
|
||||
// then
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||
Page<SampleEntityUUIDKeyed> sampleEntities = repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements()).isEqualTo(0L);
|
||||
Iterable<SampleEntityUUIDKeyed> sampleEntities = repository.findAll();
|
||||
assertThat(sampleEntities).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -356,8 +316,8 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
// then
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("id", documentId.toString()))
|
||||
.build();
|
||||
Page<SampleEntityUUIDKeyed> sampleEntities = repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements()).isGreaterThanOrEqualTo(0);
|
||||
Iterable<SampleEntityUUIDKeyed> sampleEntities = repository.findAll();
|
||||
assertThat(sampleEntities).isEmpty();
|
||||
assertThat(result).isEqualTo(1L);
|
||||
}
|
||||
|
||||
@ -393,8 +353,8 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
// then
|
||||
assertThat(result).hasSize(2);
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||
Page<SampleEntityUUIDKeyed> sampleEntities = repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements()).isEqualTo(1);
|
||||
Iterable<SampleEntityUUIDKeyed> sampleEntities = repository.findAll();
|
||||
assertThat(sampleEntities).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -425,9 +385,8 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
|
||||
// then
|
||||
assertThat(result).hasSize(1);
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||
Page<SampleEntityUUIDKeyed> sampleEntities = repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements()).isEqualTo(2);
|
||||
Iterable<SampleEntityUUIDKeyed> sampleEntities = repository.findAll();
|
||||
assertThat(sampleEntities).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -457,9 +416,8 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
repository.deleteByType("article");
|
||||
|
||||
// then
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||
Page<SampleEntityUUIDKeyed> sampleEntities = repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements()).isEqualTo(2);
|
||||
Iterable<SampleEntityUUIDKeyed> sampleEntities = repository.findAll();
|
||||
assertThat(sampleEntities).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -477,10 +435,8 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
repository.delete(sampleEntityUUIDKeyed);
|
||||
|
||||
// then
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("id", documentId.toString()))
|
||||
.build();
|
||||
Page<SampleEntityUUIDKeyed> sampleEntities = repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements()).isEqualTo(0);
|
||||
Optional<SampleEntityUUIDKeyed> sampleEntities = repository.findById(documentId);
|
||||
assertThat(sampleEntities).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -502,7 +458,7 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
repository.save(sampleEntityUUIDKeyed2);
|
||||
|
||||
// when
|
||||
Iterable<SampleEntityUUIDKeyed> sampleEntities = repository.search(termQuery("id", documentId1.toString()));
|
||||
Iterable<SampleEntityUUIDKeyed> sampleEntities = repository.searchById(documentId1);
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities).isNotNull();
|
||||
@ -619,6 +575,8 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
*/
|
||||
interface SampleUUIDKeyedElasticsearchRepository extends ElasticsearchRepository<SampleEntityUUIDKeyed, UUID> {
|
||||
|
||||
List<SampleEntityUUIDKeyed> searchById(UUID uuid);
|
||||
|
||||
long deleteSampleEntityUUIDKeyedById(UUID id);
|
||||
|
||||
List<SampleEntityUUIDKeyed> deleteByAvailable(boolean available);
|
||||
|
@ -36,7 +36,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -50,13 +49,8 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.IndexOperations;
|
||||
import org.springframework.data.elasticsearch.core.RefreshPolicy;
|
||||
import org.springframework.data.elasticsearch.core.SearchPage;
|
||||
import org.springframework.data.elasticsearch.core.query.Criteria;
|
||||
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||
@ -226,46 +220,6 @@ class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
assertThat(entityFromElasticSearch).isNotPresent();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSearchDocumentsGivenSearchQuery() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("some test message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
|
||||
NativeSearchQuery query = new NativeSearchQueryBuilder().withQuery(termQuery("message", "test")).build();
|
||||
|
||||
// when
|
||||
Page<SampleEntity> page = repository.search(query);
|
||||
|
||||
// then
|
||||
assertThat(page).isNotNull();
|
||||
assertThat(page.getNumberOfElements()).isGreaterThanOrEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSearchDocumentsGivenElasticsearchQuery() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("hello world.");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
|
||||
// when
|
||||
Page<SampleEntity> page = repository.search(termQuery("message", "world"), PageRequest.of(0, 50));
|
||||
|
||||
// then
|
||||
assertThat(page).isNotNull();
|
||||
assertThat(page.getNumberOfElements()).isGreaterThanOrEqualTo(1);
|
||||
}
|
||||
|
||||
@Test // DATAES-82
|
||||
void shouldFindAllByIdQuery() {
|
||||
|
||||
@ -313,8 +267,8 @@ class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
repository.saveAll(sampleEntities);
|
||||
|
||||
// then
|
||||
Page<SampleEntity> entities = repository.search(termQuery("id", documentId), PageRequest.of(0, 50));
|
||||
assertThat(entities).isNotNull();
|
||||
Iterable<SampleEntity> entities = repository.findAll();
|
||||
assertThat(entities).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -348,25 +302,6 @@ class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
assertThat(exist).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnResultsForGivenSearchQuery() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("hello world.");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
|
||||
// when
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("id", documentId)).build();
|
||||
Page<SampleEntity> sampleEntities = repository.search(searchQuery);
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities.getTotalElements()).isEqualTo(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldDeleteAll() {
|
||||
|
||||
@ -383,8 +318,8 @@ class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
|
||||
// then
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||
Page<SampleEntity> sampleEntities = repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements()).isEqualTo(0L);
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll();
|
||||
assertThat(sampleEntities).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -402,13 +337,12 @@ class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
long result = repository.deleteSampleEntityById(documentId);
|
||||
|
||||
// then
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("id", documentId)).build();
|
||||
Page<SampleEntity> sampleEntities = repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements()).isEqualTo(0L);
|
||||
Iterable<SampleEntity> sampleEntities = repository.searchById(documentId);
|
||||
assertThat(sampleEntities).isEmpty();
|
||||
assertThat(result).isEqualTo(1L);
|
||||
}
|
||||
|
||||
@Test //DATAES-976
|
||||
@Test // DATAES-976
|
||||
void shouldDeleteAllById() {
|
||||
|
||||
// given
|
||||
@ -474,8 +408,8 @@ class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
// then
|
||||
assertThat(result).hasSize(2);
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||
Page<SampleEntity> sampleEntities = repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements()).isEqualTo(1L);
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll();
|
||||
assertThat(sampleEntities).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -507,8 +441,8 @@ class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
// then
|
||||
assertThat(result).hasSize(1);
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||
Page<SampleEntity> sampleEntities = repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements()).isEqualTo(2L);
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll();
|
||||
assertThat(sampleEntities).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -538,9 +472,8 @@ class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
repository.deleteByType("article");
|
||||
|
||||
// then
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||
Page<SampleEntity> sampleEntities = repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements()).isEqualTo(2L);
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll();
|
||||
assertThat(sampleEntities).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -558,9 +491,8 @@ class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
repository.delete(sampleEntity);
|
||||
|
||||
// then
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("id", documentId)).build();
|
||||
Page<SampleEntity> sampleEntities = repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements()).isEqualTo(0L);
|
||||
Iterable<SampleEntity> sampleEntities = repository.searchById(documentId);
|
||||
assertThat(sampleEntities).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -582,7 +514,7 @@ class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
repository.save(sampleEntity2);
|
||||
|
||||
// when
|
||||
Iterable<SampleEntity> sampleEntities = repository.search(termQuery("id", documentId1));
|
||||
Iterable<SampleEntity> sampleEntities = repository.searchById(documentId1);
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities).isNotNull();
|
||||
@ -629,35 +561,8 @@ class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
repository.save(sampleEntity);
|
||||
|
||||
// then
|
||||
Page<SampleEntity> entities = repository.search(termQuery("id", documentId), PageRequest.of(0, 50));
|
||||
assertThat(entities.getTotalElements()).isEqualTo(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldIndexWithoutRefreshEntity() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
sampleEntity.setMessage("some message");
|
||||
|
||||
// when
|
||||
AbstractElasticsearchTemplate abstractElasticsearchTemplate = (AbstractElasticsearchTemplate) this.operations;
|
||||
RefreshPolicy refreshPolicy = abstractElasticsearchTemplate.getRefreshPolicy();
|
||||
abstractElasticsearchTemplate.setRefreshPolicy(RefreshPolicy.NONE);
|
||||
repository.indexWithoutRefresh(sampleEntity);
|
||||
abstractElasticsearchTemplate.setRefreshPolicy(refreshPolicy);
|
||||
|
||||
// then
|
||||
Page<SampleEntity> entities = repository.search(termQuery("id", documentId), PageRequest.of(0, 50));
|
||||
assertThat(entities.getTotalElements()).isEqualTo(0L);
|
||||
|
||||
repository.refresh();
|
||||
|
||||
entities = repository.search(termQuery("id", documentId), PageRequest.of(0, 50));
|
||||
assertThat(entities.getTotalElements()).isEqualTo(1L);
|
||||
Iterable<SampleEntity> entities = repository.findAll();
|
||||
assertThat(entities).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -812,6 +717,7 @@ class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
|
||||
void deleteByType(String type);
|
||||
|
||||
Iterable<SampleEntity> searchById(String id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.utils;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.IndexOperations;
|
||||
|
||||
/**
|
||||
@ -27,18 +26,6 @@ public class IndexInitializer {
|
||||
|
||||
private IndexInitializer() {}
|
||||
|
||||
/**
|
||||
* Initialize a fresh index with mappings for {@link Class}. Drops the index if it exists before creation.
|
||||
*
|
||||
* @param operations
|
||||
* @param clazz
|
||||
* @deprecated since 4.0, use {@link IndexInitializer#init(IndexOperations)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void init(ElasticsearchOperations operations, Class<?> clazz) {
|
||||
init(operations.indexOps(clazz));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a fresh index with mappings for {@link Class}. Drops the index if it exists before creation.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user