# Missing prepareSearch() method in RestHighLevelClient

**URL:** https://discuss.elastic.co/t/missing-preparesearch-method-in-resthighlevelclient/271631
**Category:** Elasticsearch
**Created:** [April 29, 2021, 11:57am UTC](https://discuss.elastic.co/t/missing-preparesearch-method-in-resthighlevelclient/271631 "2021-04-29T11:57:51Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![cmpich](https://avatars.discourse-cdn.com/v4/letter/c/9de0a6/32.png) [@cmpich](https://discuss.elastic.co/u/cmpich)
#### Post date: [April 29, 2021, 11:57am UTC](https://discuss.elastic.co/t/missing-preparesearch-method-in-resthighlevelclient/271631/1 "2021-04-29T11:57:51Z")

</div>

I am trying to use Aggregation API and for that documentation tells me to use

```auto
SearchResponse sr = node.client().prepareSearch()
        .setQuery( /* your query */ )
        .addAggregation( /* add an aggregation */ )
        .execute().actionGet();

```

But it does not tell me how to get the client object node.client()  
RestHighLevelClient does not have a prepareSearch() method in 7.9.0. Then I tried upgrading to 7.12.1 but then I cannot find the class  
org.elasticsearch.client.RestHighLevelClient  
at all. I am really confused. Am I missing a library? I am using two dependencies:

```auto
		<dependency>
			<groupId>org.elasticsearch</groupId>
			<artifactId>elasticsearch</artifactId>
			<version>7.9.0</version>
		</dependency>
		<dependency>
			<groupId>org.elasticsearch.client</groupId>
			<artifactId>elasticsearch-rest-high-level-client</artifactId>
			<version>7.9.0</version>
		</dependency>

```

Also, the current documentation, e.g. [Aggregations | Java API (deprecated) [7.12] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-aggs.html), states that the doc is deprecated. Another very confusing thing. Can anybody shed some light on this?

---

<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: [April 29, 2021, 2:14pm UTC](https://discuss.elastic.co/t/missing-preparesearch-method-in-resthighlevelclient/271631/2 "2021-04-29T14:14:38Z")

</div>

Welcome!

The TransportClient is indeed deprecated. So you should look at the rest client documentation.

> **[Java REST Client \[7.12\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html)**

Specifically [Search API | Java REST Client [7.12] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-search.html)

I'm also sharing some few examples at:

> **[dadoonet/elasticsearch-java-client-demo](https://github.com/dadoonet/elasticsearch-java-client-demo)**
>
> Elasticsearch Client Java Sample project. Contribute to dadoonet/elasticsearch-java-client-demo development by creating an account on GitHub.

HTH

---

<div class="post-metadata">

### Author: ![cmpich](https://avatars.discourse-cdn.com/v4/letter/c/9de0a6/32.png) [@cmpich](https://discuss.elastic.co/u/cmpich)
#### Post date: [April 29, 2021, 5:23pm UTC](https://discuss.elastic.co/t/missing-preparesearch-method-in-resthighlevelclient/271631/3 "2021-04-29T17:23:31Z")

</div>

> [@cmpich](#):
>
> RestHighLevelClient

What does the RestHighLevelClient class have to do with TransportCLient?  
In your example you are using RestHighLevelClient...

---

<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: [April 29, 2021, 6:13pm UTC](https://discuss.elastic.co/t/missing-preparesearch-method-in-resthighlevelclient/271631/4 "2021-04-29T18:13:05Z")

</div>

As I said:

> The TransportClient is indeed deprecated. So you should look at the rest client documentation.

> [@cmpich](#):
>
> What does the RestHighLevelClient class have to do with TransportCLient?

Nothing.

> [@cmpich](#):
>
> In your example you are using RestHighLevelClient...

Yes. That's the way to go.

---

<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 27, 2021, 6:13pm UTC](https://discuss.elastic.co/t/missing-preparesearch-method-in-resthighlevelclient/271631/5 "2021-05-27T18:13:37Z")

</div>

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