|
18 | 18 | import static org.assertj.core.api.Assertions.*;
|
19 | 19 | import static org.springframework.data.elasticsearch.client.elc.Queries.*;
|
20 | 20 |
|
| 21 | +import co.elastic.clients.elasticsearch._types.SortOrder; |
21 | 22 | import co.elastic.clients.elasticsearch._types.aggregations.Aggregate;
|
22 | 23 | import co.elastic.clients.elasticsearch._types.aggregations.Buckets;
|
23 | 24 | import co.elastic.clients.elasticsearch._types.aggregations.StringTermsAggregate;
|
|
27 | 28 | import java.util.List;
|
28 | 29 | import java.util.concurrent.atomic.AtomicInteger;
|
29 | 30 |
|
| 31 | +import org.junit.jupiter.api.DisplayName; |
| 32 | +import org.junit.jupiter.api.Test; |
30 | 33 | import org.springframework.context.annotation.Bean;
|
31 | 34 | import org.springframework.context.annotation.Configuration;
|
32 | 35 | import org.springframework.context.annotation.Import;
|
| 36 | +import org.springframework.data.domain.Pageable; |
33 | 37 | import org.springframework.data.elasticsearch.client.elc.Aggregation;
|
34 | 38 | import org.springframework.data.elasticsearch.client.elc.ElasticsearchAggregation;
|
35 | 39 | import org.springframework.data.elasticsearch.client.elc.NativeQuery;
|
|
48 | 52 | @ContextConfiguration(classes = ReactiveElasticsearchELCIntegrationTests.Config.class)
|
49 | 53 | public class ReactiveElasticsearchELCIntegrationTests extends ReactiveElasticsearchIntegrationTests {
|
50 | 54 |
|
| 55 | + @Test // #2745 |
| 56 | + @DisplayName("should use sort defined in native unbounded query") |
| 57 | + void shouldUseSortDefinedInNativeUnboundedQuery() { |
| 58 | + var entity1 = randomEntity(null); |
| 59 | + entity1.setRate(7); |
| 60 | + var entity2 = randomEntity(null); |
| 61 | + entity2.setRate(5); |
| 62 | + var entity3 = randomEntity(null); |
| 63 | + entity3.setRate(11); |
| 64 | + |
| 65 | + operations.saveAll(List.of(entity1, entity2, entity3), SampleEntity.class).blockLast(); |
| 66 | + |
| 67 | + var query = NativeQuery.builder() |
| 68 | + .withQuery(qb -> qb |
| 69 | + .matchAll(m -> m)) |
| 70 | + .withSort(sob -> sob |
| 71 | + .field(f -> f |
| 72 | + .field("rate") |
| 73 | + .order(SortOrder.Asc))) |
| 74 | + .withPageable(Pageable.unpaged()) |
| 75 | + .build(); |
| 76 | + |
| 77 | + var rates = operations.search(query, SampleEntity.class) |
| 78 | + .map(SearchHit::getContent) |
| 79 | + .map(SampleEntity::getRate) |
| 80 | + .collectList().block(); |
| 81 | + assertThat(rates).containsExactly(5, 7, 11); |
| 82 | + |
| 83 | + query = NativeQuery.builder() |
| 84 | + .withQuery(qb -> qb |
| 85 | + .matchAll(m -> m)) |
| 86 | + .withSort(sob -> sob |
| 87 | + .field(f -> f |
| 88 | + .field("rate") |
| 89 | + .order(SortOrder.Desc))) |
| 90 | + .withPageable(Pageable.unpaged()) |
| 91 | + .build(); |
| 92 | + |
| 93 | + rates = operations.search(query, SampleEntity.class) |
| 94 | + .map(SearchHit::getContent) |
| 95 | + .map(SampleEntity::getRate) |
| 96 | + .collectList().block(); |
| 97 | + assertThat(rates).containsExactly(11, 7, 5); |
| 98 | + } |
| 99 | + |
51 | 100 | @Configuration
|
52 | 101 | @Import({ ReactiveElasticsearchTemplateConfiguration.class })
|
53 | 102 | static class Config {
|
|
0 commit comments