class RestHighLevelClient in package client is deprecated

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:


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 = { host ⇒
    new HttpHost(host.getString("host"), host.getInt("port"), config.scheme)

  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 =
  val esVersion = getElasticsearchVersion(esRestClient)

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

  override def close(): Unit = {

  private def getElasticsearchVersion(restClient: RestClient): Int = {
    try {
      val response = new RestHighLevelClientBuilder(restClient)
      val strVersion = response.getVersion.getNumber
    } catch {
      case e: Exception ⇒
        logger.warn("Failed to get ES server version", e)


and the client class where the error is raised:

package com.carrefour.phenix.customer_case.api

import com.carrefour.phenix.core.configuration.Configuration
import{ AfterSalesServiceConfiguration, CustomerCaseSearchService, RefundReceiptSearchService }
import{ LogSupport, ManagedServices }
import com.typesafe.config.Config

import scala.util.Try
import{ ElasticConfiguration, ElasticConnector }
import{ 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 = {"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 = {

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

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

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. But it's still fully functional and can as you mention be used with a version 8 cluster by enabling the compatibility mode.

it is an error and not a warning

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

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