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

**URL:** <https://discuss.elastic.co/t/how-to-set-query-params-from-and-size-in-latest-java-api-8-11/352162>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [January 31, 2024, 9:38am UTC](https://discuss.elastic.co/t/how-to-set-query-params-from-and-size-in-latest-java-api-8-11/352162 "2024-01-31T09:38:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darth\_vader\_22](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/darth_vader_22/32/130197_2.png) [@Darth\_vader\_22](https://discuss.elastic.co/u/Darth_vader_22)\
**Post date:** [January 31, 2024, 9:38am UTC](https://discuss.elastic.co/t/how-to-set-query-params-from-and-size-in-latest-java-api-8-11/352162/1 "2024-01-31T09:38:37Z")

</div>

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

```auto
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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 31, 2024, 9:51am UTC](https://discuss.elastic.co/t/how-to-set-query-params-from-and-size-in-latest-java-api-8-11/352162/2 "2024-01-31T09:51:47Z")

</div>

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);

```

---

<div class="post-metadata">

**Author:** ![Darth\_vader\_22](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/darth_vader_22/32/130197_2.png) [@Darth\_vader\_22](https://discuss.elastic.co/u/Darth_vader_22)\
**Post date:** [January 31, 2024, 10:43am UTC](https://discuss.elastic.co/t/how-to-set-query-params-from-and-size-in-latest-java-api-8-11/352162/3 "2024-01-31T10:43:54Z")

</div>

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));

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 31, 2024, 12:55pm UTC](https://discuss.elastic.co/t/how-to-set-query-params-from-and-size-in-latest-java-api-8-11/352162/4 "2024-01-31T12:55:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Darth\_vader\_22](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/darth_vader_22/32/130197_2.png) [@Darth\_vader\_22](https://discuss.elastic.co/u/Darth_vader_22)\
**Post date:** [January 31, 2024, 1:20pm UTC](https://discuss.elastic.co/t/how-to-set-query-params-from-and-size-in-latest-java-api-8-11/352162/5 "2024-01-31T13:20:56Z")

</div>

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

```auto
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();
    }

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 31, 2024, 1:41pm UTC](https://discuss.elastic.co/t/how-to-set-query-params-from-and-size-in-latest-java-api-8-11/352162/6 "2024-01-31T13:41:29Z")

</div>

What is this object? `reactiveElasticsearchOperations`

---

<div class="post-metadata">

**Author:** ![Darth\_vader\_22](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/darth_vader_22/32/130197_2.png) [@Darth\_vader\_22](https://discuss.elastic.co/u/Darth_vader_22)\
**Post date:** [January 31, 2024, 1:53pm UTC](https://discuss.elastic.co/t/how-to-set-query-params-from-and-size-in-latest-java-api-8-11/352162/7 "2024-01-31T13:53:04Z")

</div>

it's the interface ReactiveElasticsearchOperations .

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 31, 2024, 1:53pm UTC](https://discuss.elastic.co/t/how-to-set-query-params-from-and-size-in-latest-java-api-8-11/352162/8 "2024-01-31T13:53:28Z")

</div>

It's not an Elasticsearch class right?

---

<div class="post-metadata">

**Author:** ![Darth\_vader\_22](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/darth_vader_22/32/130197_2.png) [@Darth\_vader\_22](https://discuss.elastic.co/u/Darth_vader_22)\
**Post date:** [January 31, 2024, 1:57pm UTC](https://discuss.elastic.co/t/how-to-set-query-params-from-and-size-in-latest-java-api-8-11/352162/9 "2024-01-31T13:57:27Z")

</div>

It's part of spring data elasticsearch.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 31, 2024, 1:58pm UTC](https://discuss.elastic.co/t/how-to-set-query-params-from-and-size-in-latest-java-api-8-11/352162/10 "2024-01-31T13:58:38Z")

</div>

So I guess you need to ask them...

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 28, 2024, 1:59pm UTC](https://discuss.elastic.co/t/how-to-set-query-params-from-and-size-in-latest-java-api-8-11/352162/11 "2024-02-28T13:59:36Z")

</div>

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