New Elasticsearch Java client API

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.

I think you could write something like

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

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

  • the size and from parameters 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 feature to do deep pagination.
  • the Scroll API if you want to extract a resultset to be consumed by another tool later. (Not recommended anymore)

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