Missing prepareSearch() method in RestHighLevelClient

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

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:

		<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, states that the doc is deprecated. Another very confusing thing. Can anybody shed some light on this?

Welcome!

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

Specifically Search API | Java REST Client [7.12] | Elastic

I'm also sharing some few examples at:

HTH

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

As I said:

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

Nothing.

Yes. That's the way to go.

1 Like

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