# New Elasticsearch Java client API

**URL:** <https://discuss.elastic.co/t/new-elasticsearch-java-client-api/308695>\
**Category:** Elasticsearch\
**Created:** [July 1, 2022, 10:06pm UTC](https://discuss.elastic.co/t/new-elasticsearch-java-client-api/308695 "2022-07-01T22:06:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zxuz111](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zxuz111/32/100222_2.png) [@zxuz111](https://discuss.elastic.co/u/zxuz111)\
**Post date:** [July 1, 2022, 10:06pm UTC](https://discuss.elastic.co/t/new-elasticsearch-java-client-api/308695/1 "2022-07-01T22:06:58Z")

</div>

I am trying to switch from high level rest client to this new client (Java). I tried a simple matchAll query as follows and I got 2 questions need your help:

```
    SearchResponse<Publication> response = esClient.search(s -> s
        .index("publications") 
        .query(q -> q      
            .matchAll(t -> t.queryName(""))
        ),
        Publication.class      
    );

```

My first question is, Is the code " .matchAll(t -\> t.queryName(""))" correct? (even it's working fine)

Secondly, the query by default only returns the first 10 documents. How can I return the whole result list?

It would be greatly appreciated if anyone could help me with the above questions.

---

<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:** [July 2, 2022, 5:40am UTC](https://discuss.elastic.co/t/new-elasticsearch-java-client-api/308695/2 "2022-07-02T05:40:03Z")

</div>

I think you could write something like

```auto
SearchResponse<Publication> response = esClient.search(s -> s
        .index("publications") 
        .size(10000)
        .query(q -> q      
            .matchAll(t -> t)
        ),
        Publication.class      
    );

```

---

<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:** [July 2, 2022, 5:41am UTC](https://discuss.elastic.co/t/new-elasticsearch-java-client-api/308695/3 "2022-07-02T05:41:29Z")

</div>

If you want to get more hits, you can use:

- the [`size` and `from` parameters](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html) to display by default up to 10000 records to your users. If you want to change this limit, you can change `index.max_result_window` setting but be aware of the consequences (ie memory).
- the [search after](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html) feature to do deep pagination.
- the [Scroll API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html) if you want to extract a resultset to be consumed by another tool later. (Not recommended anymore)

---

<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:** [July 30, 2022, 5:42am UTC](https://discuss.elastic.co/t/new-elasticsearch-java-client-api/308695/4 "2022-07-30T05:42:02Z")

</div>

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