# class RestHighLevelClient in package client is deprecated

**URL:** https://discuss.elastic.co/t/class-resthighlevelclient-in-package-client-is-deprecated/343399
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [September 19, 2023, 8:30pm UTC](https://discuss.elastic.co/t/class-resthighlevelclient-in-package-client-is-deprecated/343399 "2023-09-19T20:30:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Nassereddine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nassereddine/32/127343_2.png) [@Nassereddine](https://discuss.elastic.co/u/Nassereddine)
#### Post date: [September 19, 2023, 8:30pm UTC](https://discuss.elastic.co/t/class-resthighlevelclient-in-package-client-is-deprecated/343399/1 "2023-09-19T20:30:46Z")

</div>

I am upgrading Elasticsearch from 7.9.2 to 7.17.6 and then to 8.4.2, in the first step i am upgrading the es cluster to the 7.17.6 version , and compiling all other ES clients, the compilation is good for all the other clients besides one client ( a scala 2.12.11 Elasticsearch client), I got the error

`RestManagedServices.scala:32:26: class RestHighLevelClient in package client is deprecated`

here is the definition of the elasticConnector class:

```auto
package com.carrefour.phenix.support

import java.io.Closeable
import com.typesafe.config.Config
import org.apache.http.HttpHost
import org.apache.http.auth.{ AuthScope, UsernamePasswordCredentials }
import org.apache.http.impl.client.BasicCredentialsProvider
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder
import org.elasticsearch.client._
import org.slf4j.LoggerFactory

/**
 *
 */
class ElasticConnector(val config: ElasticConfiguration) extends Closeable {

  def this(conf: Config) = this(new ElasticConfiguration(conf))

  val logger = LoggerFactory.getLogger(classOf[ElasticConnector].getName)

  import scala.language.{ implicitConversions, postfixOps }

  val hosts = config.hosts.map { host ⇒
    new HttpHost(host.getString("host"), host.getInt("port"), config.scheme)
  }.toList

  lazy val esClientBuilder: RestClientBuilder = RestClient.builder(hosts: _*)

  //configure authentication if provided
  (config.user, config.password) match {
    case (Some(user), Some(password)) ⇒ {
      val credentialsProvider = new BasicCredentialsProvider
      credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password))
      esClientBuilder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
        override def customizeHttpClient(httpClientBuilder: HttpAsyncClientBuilder): HttpAsyncClientBuilder = httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)
      })
    }
    case _ ⇒
  }

  val esRestClient = esClientBuilder.build()
  val esVersion = getElasticsearchVersion(esRestClient)

  lazy val esHighLevelClient: RestHighLevelClient = new RestHighLevelClientBuilder(esRestClient)
    .setApiCompatibilityMode(esVersion >= 8)
    .build()

  override def close(): Unit = {
    esHighLevelClient.close()
  }

  private def getElasticsearchVersion(restClient: RestClient): Int = {
    try {
      val response = new RestHighLevelClientBuilder(restClient).build.info(RequestOptions.DEFAULT)
      val strVersion = response.getVersion.getNumber
      strVersion.split("\\.").head.toInt
    } catch {
      case e: Exception ⇒
        logger.warn("Failed to get ES server version", e)
        -1
    }
  }

}

```

and the client class where the error is raised:

```auto
package com.carrefour.phenix.customer_case.api

import com.carrefour.phenix.core.configuration.Configuration
import com.carrefour.phenix.customer_case.api.services.{ AfterSalesServiceConfiguration, CustomerCaseSearchService, RefundReceiptSearchService }
import com.carrefour.phenix.rest.app.{ LogSupport, ManagedServices }
import com.typesafe.config.Config

import scala.util.Try
import java.io.Closeable
import com.carrefour.phenix.support.{ ElasticConfiguration, ElasticConnector }
import com.google.cloud.bigtable.data.v2.{ BigtableDataClient, BigtableDataSettings }
import org.elasticsearch.client.RestHighLevelClient

final class RestManagedServices(val customerCaseSearchConfig: AfterSalesServiceConfiguration, bigtableSettings: BigtableDataSettings)
    extends ManagedServices with LogSupport {

  val provider = new RestManagedServicesProvider(customerCaseSearchConfig.elasticConf)

  val customerCaseSearch = new CustomerCaseSearchService(provider.elasticConnector.esHighLevelClient, customerCaseSearchConfig)

  lazy val bigtableDataClient: BigtableDataClient = BigtableDataClient.create(bigtableSettings)
  lazy val refundReceiptService = new RefundReceiptSearchService(customerCaseSearchConfig, bigtableDataClient)

  override def releaseServices(): Unit = {
    log.info("Shutting down customers-after-sales-service-api services.")
  }
}

class RestManagedServicesProvider(config: Config) extends Configuration(config) with Closeable {

  val elasticConnector = new ElasticConnector(new ElasticConfiguration(config))
  val esHighLevelClient: RestHighLevelClient = elasticConnector.esHighLevelClient

  override def close(): Unit = {
    Try(elasticConnector.close)
  }
}

```

By the way I need the method search and all other methodes defined in es 7.9.2 and still supported by 7.17.6 and then 8.4.2.

The official doc of es explains that the rest high level clients will be used for an ES cluster under 8.x version when setting setApiCompatibilityMode to true , which is my case here while defining the es connector class:

[REST API compatibility workflow](https://www.elastic.co/guide/en/elasticsearch/reference/8.10/rest-api-compatibility.html)

Please a call to all Es experts and scala lover , please help me

---

<div class="post-metadata">

### Author: ![swallez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/swallez/32/11972_2.png) [@swallez](https://discuss.elastic.co/u/swallez)
#### Post date: [September 20, 2023, 5:42pm UTC](https://discuss.elastic.co/t/class-resthighlevelclient-in-package-client-is-deprecated/343399/2 "2023-09-20T17:42:14Z")

</div>

`RestManagedServices.scala:32:26: class RestHighLevelClient in package client is deprecated` - this this an error or a compilation warning?

The `RestHighLevelClient` is indeed deprecated in version 7 because it has been removed in version 8 in favor of the [Java API client](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/index.html). But it's still fully functional and can as you mention be used with a version 8 cluster by enabling the compatibility mode.

---

<div class="post-metadata">

### Author: ![Nassereddine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nassereddine/32/127343_2.png) [@Nassereddine](https://discuss.elastic.co/u/Nassereddine)
#### Post date: [September 20, 2023, 5:44pm UTC](https://discuss.elastic.co/t/class-resthighlevelclient-in-package-client-is-deprecated/343399/3 "2023-09-20T17:44:51Z")

</div>

it is an error and not a warning

---

<div class="post-metadata">

### Author: ![Nassereddine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nassereddine/32/127343_2.png) [@Nassereddine](https://discuss.elastic.co/u/Nassereddine)
#### Post date: [September 20, 2023, 9:23pm UTC](https://discuss.elastic.co/t/class-resthighlevelclient-in-package-client-is-deprecated/343399/4 "2023-09-20T21:23:14Z")

</div>

should I desactivate the deprecation error or is it hiding something dangereous?

---

<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: [October 18, 2023, 9:24pm UTC](https://discuss.elastic.co/t/class-resthighlevelclient-in-package-client-is-deprecated/343399/5 "2023-10-18T21:24:05Z")

</div>

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