Skip to content

Commit

Permalink
-- elastic
Browse files Browse the repository at this point in the history
  • Loading branch information
djnzx committed Sep 13, 2023
1 parent 264c532 commit 97e8238
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 12 additions & 14 deletions es68/src/main/scala/es/ESConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
3 changes: 1 addition & 2 deletions es68/src/main/scala/es/ExploreElastic68.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 97e8238

Please sign in to comment.