diff --git a/build.sbt b/build.sbt index e246eedd..1d5db0fc 100644 --- a/build.sbt +++ b/build.sbt @@ -160,6 +160,8 @@ lazy val es68 = (project in file("es68")) libraryDependencies ++= Seq( "com.sksamuel.elastic4s" %% "elastic4s-core" % "6.7.8", "com.sksamuel.elastic4s" %% "elastic4s-http" % "6.7.8", + "com.beachape" %% "enumeratum" % "1.7.2", + "com.beachape" %% "enumeratum-circe" % "1.7.2", "io.circe" %% "circe-parser" % "0.14.6", "io.circe" %% "circe-generic-extras" % "0.14.3", "org.typelevel" %% "cats-core" % "2.10.0", diff --git a/es68/src/main/scala/es/ESConfig.scala b/es68/src/main/scala/es/ESConfig.scala index d81b3b17..6713ccb6 100644 --- a/es68/src/main/scala/es/ESConfig.scala +++ b/es68/src/main/scala/es/ESConfig.scala @@ -6,25 +6,23 @@ import com.sksamuel.elastic4s.http.ElasticProperties object ESConfig { case class ElasticNodeProperties(protocol: String, host: String, port: Int) - case class AppProperties(es: ElasticNodeProperties) import pureconfig._ import pureconfig.generic.auto._ - private lazy val config = - ConfigSource - .resources("application.conf") - .load[AppProperties] - .getOrElse(throw new IllegalArgumentException("config read error")) - - private lazy val es = config.es - - private lazy val options: Map[String, String] = Map.empty - - private lazy val nodes: Seq[ElasticNodeEndpoint] = Seq(ElasticNodeEndpoint(es.protocol, es.host, es.port, None)) - // val props: ElasticProperties = ElasticProperties("http://localhost:9200") - lazy val props: ElasticProperties = ElasticProperties(nodes, options) + def props(fileName: String = "application.conf"): ElasticProperties = { + val appProperties = + ConfigSource + .resources(fileName) + .load[AppProperties] + .getOrElse(throw new IllegalArgumentException("config read error")) + val es = appProperties.es + val options: Map[String, String] = Map.empty + val nodes: Seq[ElasticNodeEndpoint] = Seq(ElasticNodeEndpoint(es.protocol, es.host, es.port, None)) + + ElasticProperties(nodes, options) + } } diff --git a/es68/src/main/scala/es/ExploreElastic68.scala b/es68/src/main/scala/es/ExploreElastic68.scala index feec5283..ecfd0a0f 100644 --- a/es68/src/main/scala/es/ExploreElastic68.scala +++ b/es68/src/main/scala/es/ExploreElastic68.scala @@ -4,7 +4,6 @@ import com.sksamuel.elastic4s.IndexAndType import com.sksamuel.elastic4s.RefreshPolicy import com.sksamuel.elastic4s.http.ElasticClient import com.sksamuel.elastic4s.http.ElasticDsl._ -import com.sksamuel.elastic4s.http.ElasticProperties import com.sksamuel.elastic4s.http.RequestFailure import com.sksamuel.elastic4s.http.RequestSuccess import com.sksamuel.elastic4s.http.Response @@ -24,7 +23,7 @@ import org.scalatest.funsuite.AnyFunSuite class ExploreElastic68 extends AnyFunSuite with BeforeAndAfterAll { - val client: ElasticClient = ElasticClient(ESConfig.props) + val client: ElasticClient = ElasticClient(ESConfig.props()) type EsIndex = String type EsType = String