Skip to content

Commit

Permalink
-- elastic + pureconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
djnzx committed Sep 13, 2023
1 parent 35d4f43 commit 264c532
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ lazy val es68 = (project in file("es68"))
"io.circe" %% "circe-parser" % "0.14.6",
"io.circe" %% "circe-generic-extras" % "0.14.3",
"org.typelevel" %% "cats-core" % "2.10.0",
"com.github.pureconfig" %% "pureconfig" % "0.17.4",
),
)

Expand Down
5 changes: 5 additions & 0 deletions es68/src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
es {
protocol: "http"
host: "localhost"
port: 9200
}
30 changes: 30 additions & 0 deletions es68/src/main/scala/es/ESConfig.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package es

import com.sksamuel.elastic4s.http.ElasticNodeEndpoint
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)

}
4 changes: 2 additions & 2 deletions es68/src/main/scala/es/ExploreElastic68.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import org.scalatest.funsuite.AnyFunSuite

class ExploreElastic68 extends AnyFunSuite with BeforeAndAfterAll {

val client: ElasticClient = ElasticClient(ESConfig.props)

type EsIndex = String
type EsType = String
val props: ElasticProperties = ElasticProperties("http://localhost:9200")
val client: ElasticClient = ElasticClient(props)
val myIndex: EsIndex = "artists"
val myType: EsType = "myType"
val myIndexAndType: IndexAndType = myIndex / myType
Expand Down

0 comments on commit 264c532

Please sign in to comment.