How to set query params 'from' and 'size' in latest java api 8.11

Hello,

i'm trying to send a request with a specific from and size parameters , by default there are set to ( from=0 , size=10) .
here's a snippet of my code where i construct my search query

Query query = NativeQuery.builder()
                .withQuery(boolQuery._toQuery())
                .withAggregation("id", compositeAggregation._toAggregation())
                .build();

could anyone guide me on how to specify the 'size' and 'from' parameters in my query using the elasticsearch api ?

i appreciate your help ! thank you

The size is not part of a query but part of a search request.

Something like this:

client.search(sr -> sr.index("index_name").size(10).from(0), Void.class);

thanks for the hint , i tried to implement the solution you provided but i didn't work in my case , i'm using an aggregate.

reactiveElasticsearchOperations.aggregate( query, Void.class, IndexCoordinates.of(appIndex));

Could you share a bit more of your code? Like a test case?
I'd like to see the classes you are using.

I don't have a test case yet , but here's a snippet of the code :

public Flux<MyService> findServices(LocalDateTime from, LocalDateTime to) {

        return reactiveElasticsearchOperations.aggregate(
                        buildQuery(from, to),
                        Void.class,
                        IndexCoordinates.of(appIndex))
                .flatMap(getServicesFromAggregation()) ;
}

Query buildQuery(LocalDateTime from, LocalDateTime to) {
 
        RangeQuery rangeQuery = QueryBuilders.range()
                .field(@timestamp)
                .gte(JsonData.of(from.format(formatter)))
                .lte(JsonData.of(to.format(formatter)))
                .format("date_optional_time")
                .build();
 
        BoolQuery boolQuery = QueryBuilders.bool()
                .must(rangeQuery._toQuery())
                .mustNot(QueryBuilders.match().field("level").query("DEBUG").build()._toQuery())
                .build();

        CompositeAggregationSource src = CompositeAggregationSource.of(s -> s
                .terms(term -> term
                        .field("src")
                        .missingBucket(false)));

        CompositeAggregationSource description = CompositeAggregationSource.of(s -> s
                .terms(term -> term
                        .field("description")
                        .missingBucket(false)));

        CompositeAggregation compositeAggregation = CompositeAggregation.of(c -> c.size(100)
                .sources(Map.of("id_field", srcCompositeAggregationSource),
                        Map.of(appDescriptionField, descriptionCompositeAggregationSource)));

        return NativeQuery.builder()
                .withQuery(boolQuery._toQuery())
                .withAggregation("id", compositeAggregation._toAggregation())
                .build();
    }

What is this object? reactiveElasticsearchOperations

it's the interface ReactiveElasticsearchOperations .

It's not an Elasticsearch class right?

It's part of spring data elasticsearch.

So I guess you need to ask them...

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.