# New Elasticsearch Java API: Source is null when search is execute

**URL:** <https://discuss.elastic.co/t/new-elasticsearch-java-api-source-is-null-when-search-is-execute/309980>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [July 19, 2022, 6:14am UTC](https://discuss.elastic.co/t/new-elasticsearch-java-api-source-is-null-when-search-is-execute/309980 "2022-07-19T06:14:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ALX\_DM](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alx_dm/32/106314_2.png) [@ALX\_DM](https://discuss.elastic.co/u/ALX_DM)\
**Post date:** [July 19, 2022, 6:14am UTC](https://discuss.elastic.co/t/new-elasticsearch-java-api-source-is-null-when-search-is-execute/309980/1 "2022-07-19T06:14:04Z")

</div>

I want to implement this command using the new ES Java API client but the result shows `source` as `null`

```auto
POST /test_event_202207/_search?typed_keys=true
{
  "sort":[{"time":{"order":"desc"}}]
}

```

If I excecute this in Kibana, `source` is not null.

Does anyboby encounter this kind of problem?

Below is my code:

```auto
       SearchRequest searchRequest = SearchRequest.of(r -> r
        .index("test_event_202207")
        .sort(s->s.field(f->f.field("time").order(SortOrder.Desc)))
      );

      final SearchResponse response;
      try {
        response = esClient.search(searchRequest, Void.class);
      } catch (final IOException e) {
        throw new UncheckedIOException(e);
      }

       List<Hit> listSearchHit = response.hits().hits();
      Optional<Hit> searchHit = listSearchHit.stream().findFirst();

```

When you check the searchHit variable, it is null....

---

<div class="post-metadata">

**Author:** ![bweston](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bweston/32/108437_2.png) [@bweston](https://discuss.elastic.co/u/bweston)\
**Post date:** [July 19, 2022, 7:29am UTC](https://discuss.elastic.co/t/new-elasticsearch-java-api-source-is-null-when-search-is-execute/309980/2 "2022-07-19T07:29:11Z")

</div>

Hi,

I'm thinking your problem is around the use of Void.class. The intention of that parameter is so you can hydrate a POJO with the data from your search. That said, I tried a tweaked version of your example with my codebase and it doesn't compile. It expects List\<Hit\> listSearchHit.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/4/5486392251b9372ddba70752d449db9cf9cf357e.png)

If I change to List\<Hit\> and look at the returned value, there are no fields with any data populated.

Try creating a simple class with just your **time** field and replace **Void.class** with **MyClass.class** and see what happens.

---

<div class="post-metadata">

**Author:** ![ALX\_DM](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alx_dm/32/106314_2.png) [@ALX\_DM](https://discuss.elastic.co/u/ALX_DM)\
**Post date:** [July 19, 2022, 7:30am UTC](https://discuss.elastic.co/t/new-elasticsearch-java-api-source-is-null-when-search-is-execute/309980/3 "2022-07-19T07:30:56Z")

</div>

@bweston

Thank you!

I got your point and I was led to the right direction.  
It should be `ObjectNode.class` since it returns a json string.

---

<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:** [August 16, 2022, 7:31am UTC](https://discuss.elastic.co/t/new-elasticsearch-java-api-source-is-null-when-search-is-execute/309980/4 "2022-08-16T07:31:04Z")

</div>

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