Remove deprecated suggest calls from operations.

Original Pull Request #2193 
Closes #2192
This commit is contained in:
Peter-Josef Meisch 2022-06-24 12:51:58 +02:00 committed by GitHub
parent 96d0781f24
commit bfc68699e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 8 additions and 101 deletions

View File

@ -34,8 +34,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.search.suggest.Suggest;
import org.elasticsearch.search.suggest.SuggestBuilder;
import org.reactivestreams.Publisher;
import org.springframework.data.elasticsearch.BulkFailureException;
import org.springframework.data.elasticsearch.NoSuchIndexException;
@ -177,8 +175,9 @@ public class ReactiveElasticsearchTemplate extends AbstractReactiveElasticsearch
return Mono.from(execute( //
(ClientCallback<Publisher<co.elastic.clients.elasticsearch.core.ReindexResponse>>) client -> client
.reindex(reindexRequestES)))
.flatMap(response -> (response.task() == null) ? Mono.error(
new UnsupportedBackendOperation("ElasticsearchClient did not return a task id on submit request"))
.flatMap(response -> (response.task() == null)
? Mono.error(
new UnsupportedBackendOperation("ElasticsearchClient did not return a task id on submit request"))
: Mono.just(response.task()));
}
@ -346,8 +345,7 @@ public class ReactiveElasticsearchTemplate extends AbstractReactiveElasticsearch
return client1.scroll(scrollRequest, EntityAsMap.class);
}));
});
},
this::cleanupScroll, (state, ex) -> cleanupScroll(state), this::cleanupScroll);
}, this::cleanupScroll, (state, ex) -> cleanupScroll(state), this::cleanupScroll);
return searchResponses.flatMapIterable(entityAsMapSearchResponse -> entityAsMapSearchResponse.hits().hits())
.map(entityAsMapHit -> DocumentAdapters.from(entityAsMapHit, jsonpMapper));
@ -481,16 +479,6 @@ public class ReactiveElasticsearchTemplate extends AbstractReactiveElasticsearch
return new ReactiveClusterTemplate(client.cluster(), converter);
}
@Override
public Flux<Suggest> suggest(SuggestBuilder suggestion, Class<?> entityType) {
throw new UnsupportedOperationException("not implemented");
}
@Override
public Flux<Suggest> suggest(SuggestBuilder suggestion, IndexCoordinates index) {
throw new UnsupportedOperationException("not implemented");
}
@Override
public Query matchAllQuery() {
return NativeQuery.builder().withQuery(QueryBuilders.matchAllQueryAsQuery()).build();

View File

@ -454,7 +454,6 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate {
}
}
@Override
public SearchResponse suggest(SuggestBuilder suggestion, IndexCoordinates index) {
SearchRequest searchRequest = requestFactory.searchRequest(suggestion, index);
return execute(client -> client.search(searchRequest, RequestOptions.DEFAULT));
@ -638,7 +637,6 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate {
return Version.CURRENT.toString();
}
@Override
@Deprecated
public SearchResponse suggest(SuggestBuilder suggestion, Class<?> clazz) {
return suggest(suggestion, getIndexCoordinatesFor(clazz));

View File

@ -43,7 +43,6 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.reindex.BulkByScrollResponse;
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
import org.elasticsearch.search.suggest.SuggestBuilder;
import org.reactivestreams.Publisher;
import org.springframework.data.elasticsearch.BulkFailureException;
import org.springframework.data.elasticsearch.NoSuchIndexException;
@ -557,26 +556,6 @@ public class ReactiveElasticsearchTemplate extends AbstractReactiveElasticsearch
.onErrorResume(NoSuchIndexException.class, it -> Flux.empty()).map(ElasticsearchAggregation::new);
}
@Override
@Deprecated
public Flux<org.elasticsearch.search.suggest.Suggest> suggest(SuggestBuilder suggestion, Class<?> entityType) {
return doSuggest(suggestion, getIndexCoordinatesFor(entityType));
}
@Override
@Deprecated
public Flux<org.elasticsearch.search.suggest.Suggest> suggest(SuggestBuilder suggestion, IndexCoordinates index) {
return doSuggest(suggestion, index);
}
@Deprecated
private Flux<org.elasticsearch.search.suggest.Suggest> doSuggest(SuggestBuilder suggestion, IndexCoordinates index) {
return Flux.defer(() -> {
SearchRequest request = requestFactory.searchRequest(suggestion, index);
return Flux.from(execute(client -> client.suggest(request)));
});
}
protected Mono<Long> doCount(Query query, Class<?> entityType, IndexCoordinates index) {
return Mono.defer(() -> {

View File

@ -20,7 +20,6 @@ import reactor.core.publisher.Mono;
import java.util.List;
import org.elasticsearch.search.suggest.SuggestBuilder;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
@ -247,28 +246,6 @@ public interface ReactiveSearchOperations {
*/
Flux<? extends AggregationContainer<?>> aggregate(Query query, Class<?> entityType, IndexCoordinates index);
/**
* Does a suggest query
*
* @param suggestion the query
* @param entityType must not be {@literal null}.
* @return the suggest response (Elasticsearch library classes)
* @deprecated since 4.3, use {@link #suggest(Query, Class)}
*/
@Deprecated
Flux<org.elasticsearch.search.suggest.Suggest> suggest(SuggestBuilder suggestion, Class<?> entityType);
/**
* Does a suggest query
*
* @param suggestion the query
* @param index the index to run the query against
* @return the suggest response (Elasticsearch library classes)
* @deprecated since 4.3, use {@link #suggest(Query, Class, IndexCoordinates)}
*/
@Deprecated
Flux<org.elasticsearch.search.suggest.Suggest> suggest(SuggestBuilder suggestion, IndexCoordinates index);
/**
* Does a suggest query.
*

View File

@ -17,12 +17,8 @@ package org.springframework.data.elasticsearch.core;
import java.util.List;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.suggest.SuggestBuilder;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.lang.Nullable;
@ -66,37 +62,6 @@ public interface SearchOperations {
*/
long count(Query query, @Nullable Class<?> clazz, IndexCoordinates index);
/**
* Does a suggest query
*
* @param suggestion the query
* @param clazz the entity class
* @return the suggest response
* @since 4.1
* @deprecated since 4.3 use a {@link NativeSearchQueryBuilder} with
* {@link NativeSearchQueryBuilder#withSuggestBuilder(SuggestBuilder)}, call {@link #search(Query, Class)}
* and get the suggest from {@link SearchHits#getSuggest()}
*/
@Deprecated
default SearchResponse suggest(SuggestBuilder suggestion, Class<?> clazz) {
throw new InvalidDataAccessApiUsageException("Unsupported operation");
}
/**
* Does a suggest query
*
* @param suggestion the query
* @param index the index to run the query against
* @return the suggest response
* @deprecated since 4.3 use a {@link NativeSearchQueryBuilder} with
* {@link NativeSearchQueryBuilder#withSuggestBuilder(SuggestBuilder)}, call {@link #search(Query, Class)}
* and get the suggest from {@link SearchHits#getSuggest()}
*/
@Deprecated
default SearchResponse suggest(SuggestBuilder suggestion, IndexCoordinates index) {
throw new InvalidDataAccessApiUsageException("Unsupported operation");
}
/**
* Execute the query against elasticsearch and return the first returned object.
*

View File

@ -40,8 +40,8 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.CompletionContext;
import org.springframework.data.elasticsearch.annotations.CompletionField;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.IndexQuery;
@ -124,7 +124,7 @@ public abstract class CompletionWithContextsIntegrationTests {
((CompletionSuggestionBuilder) completionSuggestionFuzzyBuilder).contexts(contextMap);
// when
SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(
SearchResponse suggestResponse = ((ElasticsearchRestTemplate) operations).suggest(
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
IndexCoordinates.of("test-index-context-completion"));
assertThat(suggestResponse.getSuggest()).isNotNull();
@ -156,7 +156,7 @@ public abstract class CompletionWithContextsIntegrationTests {
((CompletionSuggestionBuilder) completionSuggestionFuzzyBuilder).contexts(contextMap);
// when
SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(
SearchResponse suggestResponse = ((ElasticsearchRestTemplate) operations).suggest(
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
IndexCoordinates.of("test-index-context-completion"));
assertThat(suggestResponse.getSuggest()).isNotNull();
@ -188,7 +188,7 @@ public abstract class CompletionWithContextsIntegrationTests {
((CompletionSuggestionBuilder) completionSuggestionFuzzyBuilder).contexts(contextMap);
// when
SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(
SearchResponse suggestResponse = ((ElasticsearchRestTemplate) operations).suggest(
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
IndexCoordinates.of("test-index-context-completion"));
assertThat(suggestResponse.getSuggest()).isNotNull();