From e8edd606fb320f1921066fe9f5ef331bea61bc5a Mon Sep 17 00:00:00 2001 From: Peter-Josef Meisch Date: Thu, 28 Jan 2021 08:14:20 +0100 Subject: [PATCH] Cleanup deprecations from 4.0. (#1671) Original Pull Request #1671 Closes #1669 --- ...elasticsearch-migration-guide-4.1-4.2.adoc | 29 +- .../elasticsearch/ElasticsearchException.java | 57 --- .../data/elasticsearch/annotations/Score.java | 28 -- .../core/AbstractElasticsearchTemplate.java | 18 - .../core/DocumentOperations.java | 39 -- .../core/ElasticsearchOperations.java | 343 +----------------- .../core/ElasticsearchRestTemplate.java | 35 +- .../core/ElasticsearchTemplate.java | 46 ++- .../core/ReactiveDocumentOperations.java | 53 --- .../core/ReactiveElasticsearchTemplate.java | 12 - .../core/ReactiveSearchOperations.java | 67 ---- .../elasticsearch/core/RequestFactory.java | 47 +-- .../data/elasticsearch/core/ScoredPage.java | 31 -- .../data/elasticsearch/core/ScrolledPage.java | 16 - .../elasticsearch/core/SearchHitSupport.java | 35 +- .../elasticsearch/core/SearchOperations.java | 177 --------- .../core/aggregation/AggregatedPage.java | 23 -- .../aggregation/impl/AggregatedPageImpl.java | 140 ------- .../core/aggregation/impl/package-info.java | 3 - .../core/aggregation/package-info.java | 3 - .../MappingElasticsearchConverter.java | 17 +- .../core/document/DocumentAdapters.java | 4 +- .../core/document/MapDocument.java | 4 +- .../ElasticsearchPersistentEntity.java | 24 -- .../ElasticsearchPersistentProperty.java | 15 - .../SimpleElasticsearchPersistentEntity.java | 26 -- ...SimpleElasticsearchPersistentProperty.java | 13 - .../elasticsearch/core/query/DeleteQuery.java | 65 ---- .../elasticsearch/core/query/GetQuery.java | 42 --- .../ElasticsearchCrudRepository.java | 33 -- .../repository/ElasticsearchRepository.java | 49 --- .../query/ElasticsearchEntityMetadata.java | 7 - .../query/ElasticsearchPartQuery.java | 6 +- .../query/ElasticsearchQueryMethod.java | 15 +- .../query/ElasticsearchStringQuery.java | 2 +- .../SimpleElasticsearchEntityMetadata.java | 6 - .../SimpleElasticsearchRepository.java | 58 +-- ...eNestedElasticsearchRepositoriesTests.java | 4 - .../EnableElasticsearchRepositoriesTests.java | 2 - ...actElasticsearchTemplateCallbackTests.java | 154 +------- .../core/ElasticsearchTemplateTests.java | 28 +- ...iveElasticsearchTemplateCallbackTests.java | 100 ----- ...ElasticsearchTemplateIntegrationTests.java | 4 +- .../aggregation/AggregatedPageImplTest.java | 41 --- .../index/MappingBuilderIntegrationTests.java | 7 +- .../core/index/MappingParametersTest.java | 9 - ...pleElasticsearchPersistentEntityTests.java | 19 - ...sticsearchPersistentPropertyUnitTests.java | 13 - .../query/CriteriaQueryIntegrationTests.java | 2 - ...ldDynamicMappingEntityRepositoryTests.java | 2 +- .../UUIDElasticsearchRepositoryTests.java | 76 +--- ...asticsearchRepositoryIntegrationTests.java | 132 +------ .../elasticsearch/utils/IndexInitializer.java | 13 - 53 files changed, 149 insertions(+), 2045 deletions(-) delete mode 100644 src/main/java/org/springframework/data/elasticsearch/ElasticsearchException.java delete mode 100644 src/main/java/org/springframework/data/elasticsearch/annotations/Score.java delete mode 100644 src/main/java/org/springframework/data/elasticsearch/core/ScoredPage.java delete mode 100644 src/main/java/org/springframework/data/elasticsearch/core/ScrolledPage.java delete mode 100644 src/main/java/org/springframework/data/elasticsearch/core/aggregation/AggregatedPage.java delete mode 100644 src/main/java/org/springframework/data/elasticsearch/core/aggregation/impl/AggregatedPageImpl.java delete mode 100644 src/main/java/org/springframework/data/elasticsearch/core/aggregation/impl/package-info.java delete mode 100644 src/main/java/org/springframework/data/elasticsearch/core/aggregation/package-info.java delete mode 100644 src/main/java/org/springframework/data/elasticsearch/core/query/DeleteQuery.java delete mode 100644 src/main/java/org/springframework/data/elasticsearch/core/query/GetQuery.java delete mode 100644 src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchCrudRepository.java delete mode 100644 src/test/java/org/springframework/data/elasticsearch/core/aggregation/AggregatedPageImplTest.java diff --git a/src/main/asciidoc/reference/elasticsearch-migration-guide-4.1-4.2.adoc b/src/main/asciidoc/reference/elasticsearch-migration-guide-4.1-4.2.adoc index f3a683dbd..87390069e 100644 --- a/src/main/asciidoc/reference/elasticsearch-migration-guide-4.1-4.2.adoc +++ b/src/main/asciidoc/reference/elasticsearch-migration-guide-4.1-4.2.adoc @@ -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 <> 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 <> 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. diff --git a/src/main/java/org/springframework/data/elasticsearch/ElasticsearchException.java b/src/main/java/org/springframework/data/elasticsearch/ElasticsearchException.java deleted file mode 100644 index 217786af6..000000000 --- a/src/main/java/org/springframework/data/elasticsearch/ElasticsearchException.java +++ /dev/null @@ -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 failedDocuments; - - public ElasticsearchException(String message) { - super(message); - } - - public ElasticsearchException(String message, Throwable cause) { - super(message, cause); - } - - public ElasticsearchException(String message, Throwable cause, Map failedDocuments) { - super(message, cause); - this.failedDocuments = failedDocuments; - } - - public ElasticsearchException(String message, Map failedDocuments) { - super(message); - this.failedDocuments = failedDocuments; - } - - @Nullable - public Map getFailedDocuments() { - return failedDocuments; - } -} diff --git a/src/main/java/org/springframework/data/elasticsearch/annotations/Score.java b/src/main/java/org/springframework/data/elasticsearch/annotations/Score.java deleted file mode 100644 index f5cd57a21..000000000 --- a/src/main/java/org/springframework/data/elasticsearch/annotations/Score.java +++ /dev/null @@ -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 { -} diff --git a/src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java b/src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java index 2c997e13b..a6027bb5b 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java @@ -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 get(GetQuery query, Class clazz, IndexCoordinates index) { - return get(query.getId(), clazz, index); - } - @Override public List multiGet(Query query, Class clazz) { return multiGet(query, clazz, getIndexCoordinatesFor(clazz)); } - @Override - @Nullable - public T queryForObject(GetQuery query, Class 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 CloseableIterator stream(Query query, Class clazz, IndexCoordinates index) { - return (CloseableIterator) SearchHitSupport.unwrapSearchHits(searchForStream(query, clazz, index)); - } - @Override public SearchHitsIterator searchForStream(Query query, Class clazz) { return searchForStream(query, clazz, getIndexCoordinatesFor(clazz)); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/DocumentOperations.java b/src/main/java/org/springframework/data/elasticsearch/core/DocumentOperations.java index b142aad11..5eec5eeff 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/DocumentOperations.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/DocumentOperations.java @@ -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 get(GetQuery query, Class 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 queryForObject(GetQuery query, Class clazz); - // endregion } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchOperations.java b/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchOperations.java index 841a659fc..29a26270e 100755 --- a/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchOperations.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchOperations.java @@ -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 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 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 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 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 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 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 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) 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 } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchRestTemplate.java b/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchRestTemplate.java index e4ff8f251..8107d8a91 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchRestTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchRestTemplate.java @@ -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)); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java b/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java index 8a68f3ccf..1b025b6e9 100755 --- a/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java @@ -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 get(String id, Class 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 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); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/ReactiveDocumentOperations.java b/src/main/java/org/springframework/data/elasticsearch/core/ReactiveDocumentOperations.java index b4214a6a7..3ddef607b 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/ReactiveDocumentOperations.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/ReactiveDocumentOperations.java @@ -182,34 +182,6 @@ public interface ReactiveDocumentOperations { */ Mono bulkUpdate(List 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 - * @return {@link Mono#empty()} if not found. - * @deprecated since 4.0 use {@link #get(String, Class)} - */ - @Deprecated - default Mono findById(String id, Class 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 - * @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 Mono findById(String id, Class 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 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 exists(String id, Class entityType, IndexCoordinates index); - /** * Delete the given entity extracting index from entity metadata. * @@ -296,20 +257,6 @@ public interface ReactiveDocumentOperations { */ Mono 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 delete(String id, Class entityType, IndexCoordinates index) { - return delete(id, index); - } - /** * Delete the documents matching the given {@link Query} extracting index from entity metadata. * diff --git a/src/main/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplate.java b/src/main/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplate.java index 436ceaee0..c1a55c217 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplate.java @@ -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 exists(String id, Class entityType, IndexCoordinates index) { - - Assert.notNull(id, "Id must not be null!"); - - return doExists(id, index); - } - private Mono doExists(String id, IndexCoordinates index) { return Mono.defer(() -> doExists(requestFactory.getRequest(id, routingResolver.getRouting(), index))); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/ReactiveSearchOperations.java b/src/main/java/org/springframework/data/elasticsearch/core/ReactiveSearchOperations.java index b62042c82..f3398f79c 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/ReactiveSearchOperations.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/ReactiveSearchOperations.java @@ -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}.
- * {@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 - * @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 Flux find(Query query, Class entityType) { - return find(query, entityType, entityType); - } - - /** - * Search the index for entities matching the given {@link Query query}.
- * {@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 - * @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 Flux find(Query query, Class entityType, Class 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 - * @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 Flux find(Query query, Class entityType, IndexCoordinates index) { - return find(query, entityType, entityType, index); - } - - /** - * Search the index for entities matching the given {@link Query query}. - * - * @param - * @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 - * @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 Flux find(Query query, Class entityType, Class resultType, IndexCoordinates index) { - return search(query, entityType, resultType, index).map(SearchHit::getContent); - } - /** * Count the number of documents matching the given {@link Query}. * diff --git a/src/main/java/org/springframework/data/elasticsearch/core/RequestFactory.java b/src/main/java/org/springframework/data/elasticsearch/core/RequestFactory.java index 49fafdb1a..9d51e7053 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/RequestFactory.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/RequestFactory.java @@ -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() + ']'); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/ScoredPage.java b/src/main/java/org/springframework/data/elasticsearch/core/ScoredPage.java deleted file mode 100644 index 6333285db..000000000 --- a/src/main/java/org/springframework/data/elasticsearch/core/ScoredPage.java +++ /dev/null @@ -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 - * @author Sascha Woo - * @deprecated since 4.0, use {@link org.springframework.data.elasticsearch.core.SearchHits} to return values. - */ -@Deprecated -public interface ScoredPage extends Page { - - float getMaxScore(); -} diff --git a/src/main/java/org/springframework/data/elasticsearch/core/ScrolledPage.java b/src/main/java/org/springframework/data/elasticsearch/core/ScrolledPage.java deleted file mode 100644 index e62fbf88b..000000000 --- a/src/main/java/org/springframework/data/elasticsearch/core/ScrolledPage.java +++ /dev/null @@ -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 extends Page { - - String getScrollId(); -} diff --git a/src/main/java/org/springframework/data/elasticsearch/core/SearchHitSupport.java b/src/main/java/org/springframework/data/elasticsearch/core/SearchHitSupport.java index c75412f9b..2fb869d6f 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/SearchHitSupport.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/SearchHitSupport.java @@ -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 AggregatedPage> page(SearchHits searchHits, Pageable pageable) { - return new AggregatedPageImpl<>( // - searchHits.getSearchHits(), // - pageable, // - searchHits.getTotalHits(), // - searchHits.getAggregations(), // - null, // - searchHits.getMaxScore()); - } - public static SearchPage searchPageFor(SearchHits searchHits, @Nullable Pageable pageable) { return new SearchPageImpl<>(searchHits, (pageable != null) ? pageable : Pageable.unpaged()); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/SearchOperations.java b/src/main/java/org/springframework/data/elasticsearch/core/SearchOperations.java index 577c5f966..04c9b38d3 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/SearchOperations.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/SearchOperations.java @@ -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 queryForObject(Query query, Class 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 AggregatedPage queryForPage(Query query, Class clazz, IndexCoordinates index) { - SearchHits searchHits = search(query, clazz, index); - AggregatedPage> aggregatedPage = SearchHitSupport.page(searchHits, query.getPageable()); - return (AggregatedPage) 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 List> queryForPage(List queries, Class clazz, IndexCoordinates index) { - List> pageList = new ArrayList<>(); - List> searchHitsList = multiSearch(queries, clazz, index); - Iterator qit = queries.iterator(); - searchHitsList.forEach(searchHits -> { - AggregatedPage> aggregatedPage = SearchHitSupport.page(searchHits, qit.next().getPageable()); - Page page = (Page) 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> queryForPage(List queries, List> classes, - IndexCoordinates index) { - List> pageList = new ArrayList<>(); - List> searchHitsList = multiSearch(queries, classes, index); - Iterator qit = queries.iterator(); - searchHitsList.forEach(searchHits -> { - AggregatedPage> 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}. - *

- * - * @param 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 - CloseableIterator stream(Query query, Class clazz, IndexCoordinates index); - - /** - * Execute the criteria query against elasticsearch and return result as {@link List} - * - * @param 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 List queryForList(Query query, Class clazz, IndexCoordinates index) { - return (List) 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 element return type - * @return list of found objects - * @deprecated since 4.0, use {@link #multiSearch(List, Class, IndexCoordinates)}. - */ - @Deprecated - default List> queryForList(List queries, Class 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> queryForList(List queries, List> 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 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 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 AggregatedPage moreLikeThis(MoreLikeThisQuery query, Class clazz, IndexCoordinates index) { - SearchHits searchHits = search(query, clazz, index); - AggregatedPage> aggregatedPage = SearchHitSupport.page(searchHits, query.getPageable()); - return (AggregatedPage) SearchHitSupport.unwrapSearchHits(aggregatedPage); - } - - // endregion - /** * Does a suggest query * diff --git a/src/main/java/org/springframework/data/elasticsearch/core/aggregation/AggregatedPage.java b/src/main/java/org/springframework/data/elasticsearch/core/aggregation/AggregatedPage.java deleted file mode 100644 index 41014fae0..000000000 --- a/src/main/java/org/springframework/data/elasticsearch/core/aggregation/AggregatedPage.java +++ /dev/null @@ -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 extends ScrolledPage, ScoredPage { - - boolean hasAggregations(); - - @Nullable Aggregations getAggregations(); - - @Nullable Aggregation getAggregation(String name); -} diff --git a/src/main/java/org/springframework/data/elasticsearch/core/aggregation/impl/AggregatedPageImpl.java b/src/main/java/org/springframework/data/elasticsearch/core/aggregation/impl/AggregatedPageImpl.java deleted file mode 100644 index 5e7765551..000000000 --- a/src/main/java/org/springframework/data/elasticsearch/core/aggregation/impl/AggregatedPageImpl.java +++ /dev/null @@ -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 extends PageImpl implements AggregatedPage { - - @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 content) { - super(content); - } - - public AggregatedPageImpl(List content, float maxScore) { - super(content); - this.maxScore = maxScore; - } - - public AggregatedPageImpl(List content, String scrollId) { - super(content); - this.scrollId = scrollId; - } - - public AggregatedPageImpl(List content, String scrollId, float maxScore) { - this(content, scrollId); - this.maxScore = maxScore; - } - - public AggregatedPageImpl(List content, Pageable pageable, long total) { - super(content, pageableOrUnpaged(pageable), total); - } - - public AggregatedPageImpl(List content, Pageable pageable, long total, float maxScore) { - super(content, pageableOrUnpaged(pageable), total); - this.maxScore = maxScore; - } - - public AggregatedPageImpl(List content, Pageable pageable, long total, String scrollId) { - super(content, pageableOrUnpaged(pageable), total); - this.scrollId = scrollId; - } - - public AggregatedPageImpl(List content, Pageable pageable, long total, String scrollId, float maxScore) { - this(content, pageableOrUnpaged(pageable), total, scrollId); - this.maxScore = maxScore; - } - - public AggregatedPageImpl(List content, Pageable pageable, long total, @Nullable Aggregations aggregations) { - super(content, pageableOrUnpaged(pageable), total); - this.aggregations = aggregations; - } - - public AggregatedPageImpl(List content, Pageable pageable, long total, @Nullable Aggregations aggregations, - float maxScore) { - this(content, pageableOrUnpaged(pageable), total, aggregations); - this.maxScore = maxScore; - } - - public AggregatedPageImpl(List content, Pageable pageable, long total, @Nullable Aggregations aggregations, - String scrollId) { - this(content, pageableOrUnpaged(pageable), total, aggregations); - this.scrollId = scrollId; - } - - public AggregatedPageImpl(List 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 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; - } -} diff --git a/src/main/java/org/springframework/data/elasticsearch/core/aggregation/impl/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/aggregation/impl/package-info.java deleted file mode 100644 index c7553ddc6..000000000 --- a/src/main/java/org/springframework/data/elasticsearch/core/aggregation/impl/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -@org.springframework.lang.NonNullApi -@org.springframework.lang.NonNullFields -package org.springframework.data.elasticsearch.core.aggregation.impl; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/aggregation/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/aggregation/package-info.java deleted file mode 100644 index c15f3e1c4..000000000 --- a/src/main/java/org/springframework/data/elasticsearch/core/aggregation/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -@org.springframework.lang.NonNullApi -@org.springframework.lang.NonNullFields -package org.springframework.data.elasticsearch.core.aggregation; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java b/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java index 2822447b6..07c3e861b 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java @@ -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); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/document/DocumentAdapters.java b/src/main/java/org/springframework/data/elasticsearch/core/document/DocumentAdapters.java index 856e76a31..02ab8358e 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/document/DocumentAdapters.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/document/DocumentAdapters.java @@ -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); } } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/document/MapDocument.java b/src/main/java/org/springframework/data/elasticsearch/core/document/MapDocument.java index 4b9443341..12597eb39 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/document/MapDocument.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/document/MapDocument.java @@ -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); } } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/ElasticsearchPersistentEntity.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/ElasticsearchPersistentEntity.java index d581a0e11..6dc85e57c 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/ElasticsearchPersistentEntity.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/ElasticsearchPersistentEntity.java @@ -77,30 +77,6 @@ public interface ElasticsearchPersistentEntity extends PersistentEntitypotential 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 potential parent property of the owning * {@link ElasticsearchPersistentEntity}. This method is mainly used by {@link ElasticsearchPersistentEntity} diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java index fb5feb0cc..bf277e6a9 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java @@ -73,7 +73,6 @@ public class SimpleElasticsearchPersistentEntity 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 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 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; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java index a3bafcc36..e045567ad 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java @@ -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 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; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/DeleteQuery.java b/src/main/java/org/springframework/data/elasticsearch/core/query/DeleteQuery.java deleted file mode 100644 index 796ec3417..000000000 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/DeleteQuery.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/GetQuery.java b/src/main/java/org/springframework/data/elasticsearch/core/query/GetQuery.java deleted file mode 100644 index 7600b8697..000000000 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/GetQuery.java +++ /dev/null @@ -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); - } -} diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchCrudRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchCrudRepository.java deleted file mode 100644 index 07999efc0..000000000 --- a/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchCrudRepository.java +++ /dev/null @@ -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 - * @param - * @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 extends PagingAndSortingRepository {} diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.java index 9546e0ebb..d06045e74 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.java @@ -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 extends PagingAndSortingRepository { - /** - * @deprecated since 4.0, use {@link #save(Object)} instead - */ - @Deprecated - default 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 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 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 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 search(Query searchQuery); - /** * Search for similar entities using a morelikethis query * @@ -84,11 +42,4 @@ public interface ElasticsearchRepository extends PagingAndSortingReposito * @return */ Page 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(); } diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchEntityMetadata.java b/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchEntityMetadata.java index 80dfbde7a..5153ed747 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchEntityMetadata.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchEntityMetadata.java @@ -25,11 +25,4 @@ import org.springframework.data.repository.core.EntityMetadata; public interface ElasticsearchEntityMetadata extends EntityMetadata { String getIndexName(); - - /** - * @return the type for the index - * @deprecated since 4.0 - */ - @Deprecated - String getIndexTypeName(); } diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchPartQuery.java b/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchPartQuery.java index 5c5a18ae7..0c5a86faa 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchPartQuery.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchPartQuery.java @@ -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 diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchQueryMethod.java b/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchQueryMethod.java index cf92d968c..044fc6377 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchQueryMethod.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchQueryMethod.java @@ -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(); + } } diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchStringQuery.java b/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchStringQuery.java index 680e79520..a32f7da8d 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchStringQuery.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchStringQuery.java @@ -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)); diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/query/SimpleElasticsearchEntityMetadata.java b/src/main/java/org/springframework/data/elasticsearch/repository/query/SimpleElasticsearchEntityMetadata.java index e3ff4437a..1ecea9410 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/query/SimpleElasticsearchEntityMetadata.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/query/SimpleElasticsearchEntityMetadata.java @@ -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 implements ElasticsearchEntity return entity.getIndexCoordinates().getIndexName(); } - @Override - public String getIndexTypeName() { - return IndexCoordinates.TYPE; - } - @Override public Class getJavaType() { return type; diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java index f7355058b..80c61a48b 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java @@ -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 implements ElasticsearchReposi public Page findAll(Pageable pageable) { NativeSearchQuery query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withPageable(pageable).build(); SearchHits searchHits = execute(operations -> operations.search(query, entityClass, getIndexCoordinates())); - AggregatedPage> page = SearchHitSupport.page(searchHits, query.getPageable()); + // noinspection ConstantConditions + SearchPage page = SearchHitSupport.searchPageFor(searchHits, query.getPageable()); return (Page) SearchHitSupport.unwrapSearchHits(page); } @@ -191,14 +191,6 @@ public class SimpleElasticsearchRepository implements ElasticsearchReposi return Streamable.of(saveAll(entities)).stream().collect(Collectors.toList()); } - @Override - @Deprecated - public S indexWithoutRefresh(S entity) { - Assert.notNull(entity, "Cannot save 'null' entity."); - // noinspection ConstantConditions - return execute(operations -> operations.save(entity)); - } - @Override public Iterable saveAll(Iterable entities) { @@ -216,40 +208,6 @@ public class SimpleElasticsearchRepository implements ElasticsearchReposi return execute(operations -> operations.exists(stringIdRepresentation(id), getIndexCoordinates())); } - @SuppressWarnings("unchecked") - @Override - public Iterable 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 searchHits = execute( - operations -> operations.search(searchQuery, entityClass, getIndexCoordinates())); - AggregatedPage> page = SearchHitSupport.page(searchHits, searchQuery.getPageable()); - return (Page) SearchHitSupport.unwrapSearchHits(page); - } - - @SuppressWarnings("unchecked") - @Override - public Page search(QueryBuilder query, Pageable pageable) { - NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(query).withPageable(pageable).build(); - SearchHits searchHits = execute( - operations -> operations.search(searchQuery, entityClass, getIndexCoordinates())); - AggregatedPage> page = SearchHitSupport.page(searchHits, searchQuery.getPageable()); - return (Page) SearchHitSupport.unwrapSearchHits(page); - } - - @SuppressWarnings("unchecked") - @Override - public Page search(Query query) { - SearchHits searchHits = execute(operations -> operations.search(query, entityClass, getIndexCoordinates())); - AggregatedPage> page = SearchHitSupport.page(searchHits, query.getPageable()); - return (Page) SearchHitSupport.unwrapSearchHits(page); - } - @SuppressWarnings("unchecked") @Override public Page searchSimilar(T entity, @Nullable String[] fields, Pageable pageable) { @@ -266,8 +224,8 @@ public class SimpleElasticsearchRepository implements ElasticsearchReposi } SearchHits searchHits = execute(operations -> operations.search(query, entityClass, getIndexCoordinates())); - AggregatedPage> page = SearchHitSupport.page(searchHits, pageable); - return (Page) SearchHitSupport.unwrapSearchHits(page); + SearchPage searchPage = SearchHitSupport.searchPageFor(searchHits, pageable); + return (Page) SearchHitSupport.unwrapSearchHits(searchPage); } @Override @@ -342,12 +300,6 @@ public class SimpleElasticsearchRepository implements ElasticsearchReposi }); } - @Override - @Deprecated - public void refresh() { - indexOperations.refresh(); - } - private void doRefresh() { RefreshPolicy refreshPolicy = null; diff --git a/src/test/java/org/springframework/data/elasticsearch/config/nested/EnableNestedElasticsearchRepositoriesTests.java b/src/test/java/org/springframework/data/elasticsearch/config/nested/EnableNestedElasticsearchRepositoriesTests.java index ad4d1bb65..098e9d0d5 100644 --- a/src/test/java/org/springframework/data/elasticsearch/config/nested/EnableNestedElasticsearchRepositoriesTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/config/nested/EnableNestedElasticsearchRepositoriesTests.java @@ -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 {} diff --git a/src/test/java/org/springframework/data/elasticsearch/config/notnested/EnableElasticsearchRepositoriesTests.java b/src/test/java/org/springframework/data/elasticsearch/config/notnested/EnableElasticsearchRepositoriesTests.java index ecd94c697..8e167a6ac 100644 --- a/src/test/java/org/springframework/data/elasticsearch/config/notnested/EnableElasticsearchRepositoriesTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/config/notnested/EnableElasticsearchRepositoriesTests.java @@ -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 diff --git a/src/test/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplateCallbackTests.java b/src/test/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplateCallbackTests.java index a603f7564..9815b30e3 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplateCallbackTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplateCallbackTests.java @@ -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 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> results = template.queryForPage(singletonList(queryForTwo()), Person.class, index); - - verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), - eq(index)); - List 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> results = template.queryForPage(singletonList(queryForTwo()), singletonList(Person.class), - index); - - verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), - eq(index)); - List 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 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 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 results) { results.next(); results.next(); } - @Test // DATAES-772 - void queryForListShouldInvokeAfterConvertCallback() { - - template.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback)); - - @SuppressWarnings("deprecation") // we know what we test - List 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> results = template.queryForList(singletonList(queryForTwo()), Person.class, index); - - verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), - eq(index)); - List 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> results = template.queryForList(singletonList(queryForTwo()), singletonList(Person.class), index); - - verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), - eq(index)); - List 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 results = template.moreLikeThis(moreLikeThisQuery(), Person.class, index); + SearchHits 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() { diff --git a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateTests.java b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateTests.java index cda5f5a8a..2893b0f68 100755 --- a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateTests.java @@ -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 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 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 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 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 queries = singletonList(queryForOne(saved.getId())); List> 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 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; } /** diff --git a/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateCallbackTests.java b/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateCallbackTests.java index afcf5cfc5..d523fe50c 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateCallbackTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateCallbackTests.java @@ -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 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 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 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 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 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() { diff --git a/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateIntegrationTests.java index d77d52a0f..6c18aff2a 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateIntegrationTests.java @@ -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 diff --git a/src/test/java/org/springframework/data/elasticsearch/core/aggregation/AggregatedPageImplTest.java b/src/test/java/org/springframework/data/elasticsearch/core/aggregation/AggregatedPageImplTest.java deleted file mode 100644 index e25baea46..000000000 --- a/src/test/java/org/springframework/data/elasticsearch/core/aggregation/AggregatedPageImplTest.java +++ /dev/null @@ -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 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); - } -} diff --git a/src/test/java/org/springframework/data/elasticsearch/core/index/MappingBuilderIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/index/MappingBuilderIntegrationTests.java index 06e1b5a72..665074c46 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/index/MappingBuilderIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/index/MappingBuilderIntegrationTests.java @@ -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"); diff --git a/src/test/java/org/springframework/data/elasticsearch/core/index/MappingParametersTest.java b/src/test/java/org/springframework/data/elasticsearch/core/index/MappingParametersTest.java index 4ef8e0c07..40abcfb2b 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/index/MappingParametersTest.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/index/MappingParametersTest.java @@ -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; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTests.java b/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTests.java index 90ed02743..d0694a379 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentPropertyUnitTests.java b/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentPropertyUnitTests.java index b3e4a1060..698978da0 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentPropertyUnitTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentPropertyUnitTests.java @@ -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; } diff --git a/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryIntegrationTests.java index 392a7e0b1..19fdf6cb0 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryIntegrationTests.java @@ -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; } } diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/setting/fielddynamic/FieldDynamicMappingEntityRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/setting/fielddynamic/FieldDynamicMappingEntityRepositoryTests.java index 2d6f308fd..9d5f99341 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/setting/fielddynamic/FieldDynamicMappingEntityRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/setting/fielddynamic/FieldDynamicMappingEntityRepositoryTests.java @@ -72,7 +72,7 @@ public class FieldDynamicMappingEntityRepositoryTests { // given // then - Map mapping = operations.getMapping(FieldDynamicMappingEntity.class); + Map mapping = operations.indexOps(FieldDynamicMappingEntity.class).getMapping(); assertThat(mapping).isNotNull(); Map properties = (Map) mapping.get("properties"); diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/UUIDElasticsearchRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/UUIDElasticsearchRepositoryTests.java index eac674089..365203a6f 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/UUIDElasticsearchRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/UUIDElasticsearchRepositoryTests.java @@ -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 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 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 entities = repository.search(termQuery("id", documentId.toString()), - PageRequest.of(0, 50)); - assertThat(entities).isNotNull(); + Iterable entities = repository.findAll(); + assertThat(entities).hasSize(2); } @Test @@ -335,8 +295,8 @@ public class UUIDElasticsearchRepositoryTests { // then NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build(); - Page sampleEntities = repository.search(searchQuery); - assertThat(sampleEntities.getTotalElements()).isEqualTo(0L); + Iterable 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 sampleEntities = repository.search(searchQuery); - assertThat(sampleEntities.getTotalElements()).isGreaterThanOrEqualTo(0); + Iterable 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 sampleEntities = repository.search(searchQuery); - assertThat(sampleEntities.getTotalElements()).isEqualTo(1); + Iterable 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 sampleEntities = repository.search(searchQuery); - assertThat(sampleEntities.getTotalElements()).isEqualTo(2); + Iterable 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 sampleEntities = repository.search(searchQuery); - assertThat(sampleEntities.getTotalElements()).isEqualTo(2); + Iterable 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 sampleEntities = repository.search(searchQuery); - assertThat(sampleEntities.getTotalElements()).isEqualTo(0); + Optional sampleEntities = repository.findById(documentId); + assertThat(sampleEntities).isEmpty(); } @Test @@ -502,7 +458,7 @@ public class UUIDElasticsearchRepositoryTests { repository.save(sampleEntityUUIDKeyed2); // when - Iterable sampleEntities = repository.search(termQuery("id", documentId1.toString())); + Iterable sampleEntities = repository.searchById(documentId1); // then assertThat(sampleEntities).isNotNull(); @@ -619,6 +575,8 @@ public class UUIDElasticsearchRepositoryTests { */ interface SampleUUIDKeyedElasticsearchRepository extends ElasticsearchRepository { + List searchById(UUID uuid); + long deleteSampleEntityUUIDKeyedById(UUID id); List deleteByAvailable(boolean available); diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/simple/SimpleElasticsearchRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/simple/SimpleElasticsearchRepositoryIntegrationTests.java index fc4f76ece..8c9665425 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/simple/SimpleElasticsearchRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/simple/SimpleElasticsearchRepositoryIntegrationTests.java @@ -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 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 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 entities = repository.search(termQuery("id", documentId), PageRequest.of(0, 50)); - assertThat(entities).isNotNull(); + Iterable 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 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 sampleEntities = repository.search(searchQuery); - assertThat(sampleEntities.getTotalElements()).isEqualTo(0L); + Iterable 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 sampleEntities = repository.search(searchQuery); - assertThat(sampleEntities.getTotalElements()).isEqualTo(0L); + Iterable 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 sampleEntities = repository.search(searchQuery); - assertThat(sampleEntities.getTotalElements()).isEqualTo(1L); + Iterable 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 sampleEntities = repository.search(searchQuery); - assertThat(sampleEntities.getTotalElements()).isEqualTo(2L); + Iterable 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 sampleEntities = repository.search(searchQuery); - assertThat(sampleEntities.getTotalElements()).isEqualTo(2L); + Iterable 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 sampleEntities = repository.search(searchQuery); - assertThat(sampleEntities.getTotalElements()).isEqualTo(0L); + Iterable sampleEntities = repository.searchById(documentId); + assertThat(sampleEntities).isEmpty(); } @Test @@ -582,7 +514,7 @@ class SimpleElasticsearchRepositoryIntegrationTests { repository.save(sampleEntity2); // when - Iterable sampleEntities = repository.search(termQuery("id", documentId1)); + Iterable sampleEntities = repository.searchById(documentId1); // then assertThat(sampleEntities).isNotNull(); @@ -629,35 +561,8 @@ class SimpleElasticsearchRepositoryIntegrationTests { repository.save(sampleEntity); // then - Page 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 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 entities = repository.findAll(); + assertThat(entities).hasSize(1); } @Test @@ -812,6 +717,7 @@ class SimpleElasticsearchRepositoryIntegrationTests { void deleteByType(String type); + Iterable searchById(String id); } } diff --git a/src/test/java/org/springframework/data/elasticsearch/utils/IndexInitializer.java b/src/test/java/org/springframework/data/elasticsearch/utils/IndexInitializer.java index ad41ae39e..70d9505e6 100644 --- a/src/test/java/org/springframework/data/elasticsearch/utils/IndexInitializer.java +++ b/src/test/java/org/springframework/data/elasticsearch/utils/IndexInitializer.java @@ -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. *