# New Java API migration

**URL:** <https://discuss.elastic.co/t/new-java-api-migration/301963>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [April 8, 2022, 11:46am UTC](https://discuss.elastic.co/t/new-java-api-migration/301963 "2022-04-08T11:46:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alain\_Bod](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alain_bod/32/77345_2.png) [@Alain\_Bod](https://discuss.elastic.co/u/Alain_Bod)\
**Post date:** [April 8, 2022, 11:46am UTC](https://discuss.elastic.co/t/new-java-api-migration/301963/1 "2022-04-08T11:46:23Z")

</div>

Hi,  
We are trying to migrate to the new Java client, and we obviously have difficulties in finding our way in the current (light) documentation. Can you help me with the following?

```auto
            // HLRC code
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.fetchSource(null, "foo")
                    .sort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC)
                    .query(QueryBuilders.matchAllQuery())
                    .size(100);
            SearchRequest request = new SearchRequest("myindex");
            request.source(searchSourceBuilder);

```

migrates to?

```auto
            SearchRequest search = SearchRequest.of(r -> r
                    .index("myindex")
                    .source(b -> b.fetch(true).filter(c -> c.excludes("foo")))
                    .sort(b -> b.field(c -> c.order(SortOrder.Asc)))
                    .query(b -> b.matchAll(c -> c.queryName("matchAllQuery")))
            );

```

The line `b.fetch(true).filter(c -> c.excludes("foo"))` does not compile though, and I'm not sure for the sort condition (how to translate the `FieldSortBuilder.DOC_FIELD_NAME` item?)

Other issue, with the delete API:  
`client.delete(b -> b.index(index).id(ref));`  
How do I know the result of the request? In the HLRC, we could check for `response.status().equals(RestStatus.NOT_FOUND)` for instance, but how to that now?

Cheers,

---

<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:** [May 6, 2022, 11:46am UTC](https://discuss.elastic.co/t/new-java-api-migration/301963/2 "2022-05-06T11:46:49Z")

</div>

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