Search code examples
javaspringelasticsearchjava-8spring-data

How to increase response size in elasticsearch with spring-data using @Query annotation?


Currently the below query is only returning 10 search hits. I want to increase it to 100. How to do it??

    @Query("{\"match\": {\"metaData.transcript1\": {\"query\": \"?0\",\"fuzziness\": \"AUTO\",\"prefix_length\": \"0\",\"max_expansions\": \"100\",\"boost\": \"1.0\"}}}")
    @Highlight(fields = {@HighlightField(name = "metaData.transcript1")}, parameters = @HighlightParameters(
            preTags = "<em>",
            postTags = "</em>",
            fragmentSize = 50
            numberOfFragments = 3
        ))
    List<SearchHit<Audio>> findByKeyword(String query);```

Solution

  • Try with Page

      @Query("{\"match\": {\"metaData.transcript1\": {\"query\": \"?0\",\"fuzziness\": \"AUTO\",\"prefix_length\": \"0\",\"max_expansions\": \"100\",\"boost\": \"1.0\"}}}")
        @Highlight(fields = {@HighlightField(name = "metaData.transcript1")}, parameters = @HighlightParameters(
                preTags = "<em>",
                postTags = "</em>",
                fragmentSize = 50
                numberOfFragments = 3
            ))
        Page<SearchHit<Audio>> findByKeyword(String query,Pageable pageable);
    

    and use like it

    Page<SearchHit<Audio>> audios = repository.findAll("query_string",PageRequest.of(0, 100));