# Best practice for TDocument class reference to pass to Java's ElasticsearchClient methods?

**URL:** <https://discuss.elastic.co/t/best-practice-for-tdocument-class-reference-to-pass-to-javas-elasticsearchclient-methods/344473>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [October 5, 2023, 11:22am UTC](https://discuss.elastic.co/t/best-practice-for-tdocument-class-reference-to-pass-to-javas-elasticsearchclient-methods/344473 "2023-10-05T11:22:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ilgrosso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ilgrosso/32/94485_2.png) [@ilgrosso](https://discuss.elastic.co/u/ilgrosso)\
**Post date:** [October 5, 2023, 11:22am UTC](https://discuss.elastic.co/t/best-practice-for-tdocument-class-reference-to-pass-to-javas-elasticsearchclient-methods/344473/1 "2023-10-05T11:22:23Z")

</div>

Hi,  
I am using the latest Java REST API client and wondering what `Class<TDocument>` reference I should be passing to [the search() method](https://github.com/elastic/elasticsearch-java/blob/v8.10.2/java-client/src/main/java/co/elastic/clients/elasticsearch/ElasticsearchClient.java#L1890) in case of no object domain model is being used.

At present I am using a bare `Map.class` and things are working as expected, though `@SuppressWarnings("rawtypes")` is needed: see for example [https://github.com/apache/syncope/blob/master/ext/elasticsearch/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/ElasticsearchAnySearchDAO.java#L314-L320](https://github.com/apache/syncope/blob/master/ext/elasticsearch/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/ElasticsearchAnySearchDAO.java#L314-L320)

Is such approach correct? TIA  
Regards.

---

<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:** [October 5, 2023, 12:02pm UTC](https://discuss.elastic.co/t/best-practice-for-tdocument-class-reference-to-pass-to-javas-elasticsearchclient-methods/344473/2 "2023-10-05T12:02:37Z")

</div>

If you don't need to get the documents, you can pass Void.

Otherwise ObjectNode. See [Reading documents by id | Elasticsearch Java API Client [8.10] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/reading.html)

---

<div class="post-metadata">

**Author:** ![ilgrosso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ilgrosso/32/94485_2.png) [@ilgrosso](https://discuss.elastic.co/u/ilgrosso)\
**Post date:** [October 5, 2023, 12:14pm UTC](https://discuss.elastic.co/t/best-practice-for-tdocument-class-reference-to-pass-to-javas-elasticsearchclient-methods/344473/3 "2023-10-05T12:14:45Z")

</div>

Thank you very much @dadoonet it seems I did miss the part about `ObjectNode` from the docs.  
The `Void` option is indeed very interesting, I'd suggest to include it in the docs as well.

Regards.

---

<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:** [November 2, 2023, 12:15pm UTC](https://discuss.elastic.co/t/best-practice-for-tdocument-class-reference-to-pass-to-javas-elasticsearchclient-methods/344473/4 "2023-11-02T12:15:43Z")

</div>

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