15
15
*/
16
16
package org .springframework .data .elasticsearch .core .paginating ;
17
17
18
- import static org .assertj .core .api .Assertions .assertThat ;
19
- import static org .assertj .core .api .Assertions .fail ;
18
+ import static org .assertj .core .api .Assertions .*;
20
19
21
20
import java .util .ArrayList ;
22
21
import java .util .List ;
23
22
import java .util .stream .Collectors ;
24
23
import java .util .stream .IntStream ;
25
24
26
- import org .elasticsearch .search .sort .SortBuilders ;
27
- import org .elasticsearch .search .sort .SortOrder ;
28
25
import org .junit .jupiter .api .DisplayName ;
29
26
import org .junit .jupiter .api .Test ;
30
27
import org .springframework .beans .factory .annotation .Autowired ;
36
33
import org .springframework .data .elasticsearch .annotations .FieldType ;
37
34
import org .springframework .data .elasticsearch .core .ElasticsearchOperations ;
38
35
import org .springframework .data .elasticsearch .core .SearchHits ;
39
- import org .springframework .data .elasticsearch .core .query .NativeSearchQueryBuilder ;
40
36
import org .springframework .data .elasticsearch .core .query .Query ;
41
37
import org .springframework .data .elasticsearch .junit .jupiter .SpringIntegrationTest ;
42
38
import org .springframework .lang .Nullable ;
@@ -61,7 +57,7 @@ void shouldReadPagesWithSearchAfter() {
61
57
query .setPageable (PageRequest .of (0 , 3 ));
62
58
query .addSort (Sort .by (Sort .Direction .ASC , "id" ));
63
59
64
- List <Object > searchAfter = null ;
60
+ List <Object > searchAfter = new ArrayList <>() ;
65
61
List <Entity > foundEntities = new ArrayList <>();
66
62
67
63
int loop = 0 ;
@@ -83,41 +79,6 @@ void shouldReadPagesWithSearchAfter() {
83
79
assertThat (foundEntities ).containsExactlyElementsOf (entities );
84
80
}
85
81
86
- @ Test // #2105
87
- @ DisplayName ("should read pages with search_after using native search query" )
88
- void shouldReadPagesWithSearchAfterUsingNativeSearchQuery () {
89
-
90
- List <Entity > entities = IntStream .rangeClosed (1 , 10 ).mapToObj (i -> new Entity ((long ) i , "message " + i ))
91
- .collect (Collectors .toList ());
92
- operations .save (entities );
93
-
94
- NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder ();
95
-
96
- nativeSearchQueryBuilder .withPageable (PageRequest .of (0 , 3 ));
97
- nativeSearchQueryBuilder .withSorts (SortBuilders .fieldSort ("id" ).order (SortOrder .ASC ));
98
-
99
- List <Object > searchAfter = null ;
100
- List <Entity > foundEntities = new ArrayList <>();
101
-
102
- int loop = 0 ;
103
- do {
104
- nativeSearchQueryBuilder .withSearchAfter (searchAfter );
105
- SearchHits <Entity > searchHits = operations .search (nativeSearchQueryBuilder .build (), Entity .class );
106
-
107
- if (searchHits .getSearchHits ().size () == 0 ) {
108
- break ;
109
- }
110
- foundEntities .addAll (searchHits .stream ().map (searchHit -> searchHit .getContent ()).collect (Collectors .toList ()));
111
- searchAfter = searchHits .getSearchHit ((int ) (searchHits .getSearchHits ().size () - 1 )).getSortValues ();
112
-
113
- if (++loop > 10 ) {
114
- fail ("loop not terminating" );
115
- }
116
- } while (true );
117
-
118
- assertThat (foundEntities ).containsExactlyElementsOf (entities );
119
- }
120
-
121
82
@ Document (indexName = "test-search-after" )
122
83
private static class Entity {
123
84
@ Nullable
0 commit comments