Home > Software design >  Add Size in Elastic NativeSearchQuery
Add Size in Elastic NativeSearchQuery

Time:05-25

        final QueryBuilder contentTagQuery = QueryBuilders.boolQuery()
                .filter( QueryBuilders.termQuery("tenantId" , "en"));

        SearchHits<Content> searchHits =
                elasticsearchOperations.search(
                        new NativeSearchQuery(contentTagQuery), Content.class,
                        IndexCoordinates.of("index"));

How can I add size in this query, as I only need the first result.

CodePudding user response:

You can set this on the Query instance:

NativeSearchQuery query = new NativeSearchQuery(contentTagQuery);
query.setMaxResults(1);
  • Related