Ashish Mishra
Ashish Mishra

Reputation: 155

Add Size in Elastic NativeSearchQuery

        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.

Upvotes: 0

Views: 265

Answers (1)

Abacus
Abacus

Reputation: 19471

You can set this on the Query instance:

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

Upvotes: 1

Related Questions