Usage
In order to execute an Elasticsearch request we can rely on the Elasticsearch layer which offers an execute method accepting an ElasticRequest. In order to build the Elasticsearch layer we need to provide the following layers:
ElasticExecutor: if you provideElasticExecutor.local, it will run onlocalhost:9200. Otherwise, if you want to useElasticExecutor.live, you must also provideElasticConfig.SttpClient: useHttpClientZioBackend.layer()from sttp, or opt in toElasticBackend.layer()(see Elastic Executor).
import sttp.client4.httpclient.zio.HttpClientZioBackend
import zio.elasticsearch._
import zio._
object ZIOElasticsearchExample extends ZIOAppDefault {
val indexName = IndexName("index")
val result: RIO[Elasticsearch, CreationOutcome] =
Elasticsearch.execute(ElasticRequest.createIndex(indexName))
override def run =
result.provide(
ElasticExecutor.local,
Elasticsearch.layer,
HttpClientZioBackend.layer()
)
}