@@ -1593,11 +1593,27 @@ void shouldReturnSearchPage() {
15931593 assertThat ((nextPageable .getPageNumber ())).isEqualTo (1 );
15941594 }
15951595
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+
15961613 private List <SampleEntity > createSampleEntities (String type , int numberOfEntities ) {
15971614
15981615 List <SampleEntity > entities = new ArrayList <>();
15991616 for (int i = 0 ; i < numberOfEntities ; i ++) {
1600-
16011617 SampleEntity entity = new SampleEntity ();
16021618 entity .setId (UUID .randomUUID ().toString ());
16031619 entity .setAvailable (true );
@@ -1633,8 +1649,7 @@ void shouldStreamSearchHitsWithQueryAnnotatedMethod() {
16331649
16341650 @ Document (indexName = "test-index-sample-repositories-custom-method" )
16351651 static class SampleEntity {
1636- @ Nullable
1637- @ Id private String id ;
1652+ @ Nullable @ Id private String id ;
16381653 @ Nullable @ Field (type = Text , store = true , fielddata = true ) private String type ;
16391654 @ Nullable @ Field (type = Text , store = true , fielddata = true ) private String message ;
16401655 @ Nullable @ Field (type = Keyword ) private String keyword ;
@@ -1836,6 +1851,9 @@ public interface SampleCustomMethodRepository extends ElasticsearchRepository<Sa
18361851
18371852 SearchPage <SampleEntity > searchByMessage (String message , Pageable pageable );
18381853
1854+ @ Query ("{\" match\" : {\" message\" : \" ?0\" }}" )
1855+ SearchPage <SampleEntity > searchWithQueryByMessage (String message , Pageable pageable );
1856+
18391857 @ CountQuery ("{\" bool\" : {\" must\" : {\" term\" : {\" type\" : \" ?0\" }}}}" )
18401858 long countWithQueryByType (String type );
18411859 }
0 commit comments