@@ -1593,11 +1593,27 @@ void shouldReturnSearchPage() {
1593
1593
assertThat ((nextPageable .getPageNumber ())).isEqualTo (1 );
1594
1594
}
1595
1595
1596
+ @ Test // #1811
1597
+ @ DisplayName ("should return SearchPage with query" )
1598
+ void shouldReturnSearchPageWithQuery () {
1599
+ List <SampleEntity > entities = createSampleEntities ("abc" , 20 );
1600
+ repository .saveAll (entities );
1601
+
1602
+ SearchPage <SampleEntity > searchPage = repository .searchWithQueryByMessage ("Message" , PageRequest .of (0 , 10 ));
1603
+
1604
+ assertThat (searchPage ).isNotNull ();
1605
+ SearchHits <SampleEntity > searchHits = searchPage .getSearchHits ();
1606
+ assertThat (searchHits ).isNotNull ();
1607
+ assertThat ((searchHits .getTotalHits ())).isEqualTo (20 );
1608
+ assertThat (searchHits .getSearchHits ()).hasSize (10 );
1609
+ Pageable nextPageable = searchPage .nextPageable ();
1610
+ assertThat ((nextPageable .getPageNumber ())).isEqualTo (1 );
1611
+ }
1612
+
1596
1613
private List <SampleEntity > createSampleEntities (String type , int numberOfEntities ) {
1597
1614
1598
1615
List <SampleEntity > entities = new ArrayList <>();
1599
1616
for (int i = 0 ; i < numberOfEntities ; i ++) {
1600
-
1601
1617
SampleEntity entity = new SampleEntity ();
1602
1618
entity .setId (UUID .randomUUID ().toString ());
1603
1619
entity .setAvailable (true );
@@ -1633,8 +1649,7 @@ void shouldStreamSearchHitsWithQueryAnnotatedMethod() {
1633
1649
1634
1650
@ Document (indexName = "test-index-sample-repositories-custom-method" )
1635
1651
static class SampleEntity {
1636
- @ Nullable
1637
- @ Id private String id ;
1652
+ @ Nullable @ Id private String id ;
1638
1653
@ Nullable @ Field (type = Text , store = true , fielddata = true ) private String type ;
1639
1654
@ Nullable @ Field (type = Text , store = true , fielddata = true ) private String message ;
1640
1655
@ Nullable @ Field (type = Keyword ) private String keyword ;
@@ -1836,6 +1851,9 @@ public interface SampleCustomMethodRepository extends ElasticsearchRepository<Sa
1836
1851
1837
1852
SearchPage <SampleEntity > searchByMessage (String message , Pageable pageable );
1838
1853
1854
+ @ Query ("{\" match\" : {\" message\" : \" ?0\" }}" )
1855
+ SearchPage <SampleEntity > searchWithQueryByMessage (String message , Pageable pageable );
1856
+
1839
1857
@ CountQuery ("{\" bool\" : {\" must\" : {\" term\" : {\" type\" : \" ?0\" }}}}" )
1840
1858
long countWithQueryByType (String type );
1841
1859
}
0 commit comments