Search By Id in Java API Client


I am trying to migrate my existing Elastic Search Rest High Level Client from 6.3.2 to the latest Java Client API.

My current code has

               SearchRequest sr = new SearchRequest(indexName);
                SearchSourceBuilder srBuilder = new SearchSourceBuilder();
                SearchResponse searchResponse =;

In Java API Client though, I can't seem to find a way to work with the Id Query. Would appreciate any help here.

Thank you

Hi @DavJane

This code can help you:

List<String> ids = List.of("1", "2");
var idsQuery = IdsQuery.of(idq -> idq.values(ids));
var request = SearchRequest.of(s -> s
    .query(Query.of(q -> q.ids(idsQuery))

Thank you very much!

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