From 9f352c99d78d9eb002e9888d049eecfeb075f005 Mon Sep 17 00:00:00 2001 From: Dimitrije Bulaja Date: Tue, 14 Mar 2023 11:21:42 +0100 Subject: [PATCH 1/3] Return sealed traits instead of private case classes in api --- .../zio/elasticsearch/ElasticExecutor.scala | 10 +- .../zio/elasticsearch/ElasticQuery.scala | 136 +++++++++++------- .../zio/elasticsearch/ElasticRequest.scala | 129 +++++++++-------- .../elasticsearch/HttpElasticExecutor.scala | 47 +++--- 4 files changed, 185 insertions(+), 137 deletions(-) diff --git a/modules/library/src/main/scala/zio/elasticsearch/ElasticExecutor.scala b/modules/library/src/main/scala/zio/elasticsearch/ElasticExecutor.scala index 30e209eab..b1e634e21 100644 --- a/modules/library/src/main/scala/zio/elasticsearch/ElasticExecutor.scala +++ b/modules/library/src/main/scala/zio/elasticsearch/ElasticExecutor.scala @@ -17,7 +17,7 @@ package zio.elasticsearch import sttp.client3.SttpBackend -import zio.elasticsearch.ElasticRequest.Search +import zio.elasticsearch.ElasticRequest.SearchRequest import zio.schema.Schema import zio.stream.{Stream, ZStream} import zio.{RIO, Task, URLayer, ZIO, ZLayer} @@ -25,9 +25,9 @@ import zio.{RIO, Task, URLayer, ZIO, ZLayer} private[elasticsearch] trait ElasticExecutor { def execute[A](request: ElasticRequest[A]): Task[A] - def stream(request: Search): Stream[Throwable, Item] + def stream(request: SearchRequest): Stream[Throwable, Item] - def streamAs[A: Schema](request: Search): Stream[Throwable, A] + def streamAs[A: Schema](request: SearchRequest): Stream[Throwable, A] } object ElasticExecutor { @@ -40,9 +40,9 @@ object ElasticExecutor { private[elasticsearch] def execute[A](request: ElasticRequest[A]): RIO[ElasticExecutor, A] = ZIO.serviceWithZIO[ElasticExecutor](_.execute(request)) - private[elasticsearch] def stream(request: Search): ZStream[ElasticExecutor, Throwable, Item] = + private[elasticsearch] def stream(request: SearchRequest): ZStream[ElasticExecutor, Throwable, Item] = ZStream.serviceWithStream[ElasticExecutor](_.stream(request)) - private[elasticsearch] def streamAs[A: Schema](request: Search): ZStream[ElasticExecutor, Throwable, A] = + private[elasticsearch] def streamAs[A: Schema](request: SearchRequest): ZStream[ElasticExecutor, Throwable, A] = ZStream.serviceWithStream[ElasticExecutor](_.streamAs[A](request)) } diff --git a/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala b/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala index 53d789683..25c24ed25 100644 --- a/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala +++ b/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala @@ -21,28 +21,28 @@ import zio.json.ast.Json.{Arr, Num, Obj, Str} import scala.annotation.unused -trait HasBoost[S] { - def boost(value: Double): ElasticQuery[S] +trait HasBoost[Q <: HasBoost[Q]] { + def boost(value: Double): Q } -sealed trait HasCaseInsensitive[S] { - def caseInsensitive(value: Boolean): ElasticQuery[S] +sealed trait HasCaseInsensitive[Q <: HasCaseInsensitive[Q]] { + def caseInsensitive(value: Boolean): Q - def caseInsensitiveFalse: ElasticQuery[S] + def caseInsensitiveFalse: Q - def caseInsensitiveTrue: ElasticQuery[S] + def caseInsensitiveTrue: Q } -sealed trait HasIgnoreUnmapped[S] { - def ignoreUnmapped(value: Boolean): ElasticQuery[S] +sealed trait HasIgnoreUnmapped[Q <: HasIgnoreUnmapped[Q]] { + def ignoreUnmapped(value: Boolean): Q - def ignoreUnmappedFalse: ElasticQuery[S] + def ignoreUnmappedFalse: Q - def ignoreUnmappedTrue: ElasticQuery[S] + def ignoreUnmappedTrue: Q } -sealed trait HasScoreMode[S] { - def scoreMode(scoreMode: ScoreMode): ElasticQuery[S] +sealed trait HasScoreMode[Q <: HasScoreMode[Q]] { + def scoreMode(scoreMode: ScoreMode): Q } sealed trait ElasticQuery[-S] { self => @@ -77,52 +77,55 @@ object ElasticQuery { def toJson(implicit EP: ElasticPrimitive[A]): Json = EP.toJson(value) } - def contains[S](field: Field[S, _], value: String): Wildcard[S] = + def contains[S](field: Field[S, _], value: String): WildcardQuery[S] = Wildcard(field = field.toString, value = s"*$value*", boost = None, caseInsensitive = None) - def contains(field: String, value: String): Wildcard[Any] = + def contains(field: String, value: String): WildcardQuery[Any] = Wildcard(field = field, value = s"*$value*", boost = None, caseInsensitive = None) - def exists[S](field: Field[S, _]): Exists[S] = Exists(field = field.toString) + def exists[S](field: Field[S, _]): ExistsQuery[S] = Exists(field = field.toString) - def exists(field: String): Exists[Any] = Exists(field = field) + def exists(field: String): ExistsQuery[Any] = Exists(field = field) - def filter[S](queries: ElasticQuery[S]*): Bool[S] = + def filter[S](queries: ElasticQuery[S]*): BoolQuery[S] = Bool[S](filter = queries.toList, must = Nil, should = Nil, boost = None) - def matchAll: MatchAll = MatchAll(boost = None) + def matchAll: MatchAllQuery = MatchAll(boost = None) - def matches[S, A: ElasticPrimitive](field: Field[S, A], multiField: Option[String] = None, value: A): Match[S, A] = + def matches[S, A: ElasticPrimitive](field: Field[S, A], multiField: Option[String] = None, value: A): MatchQuery[S] = Match(field = field.toString ++ multiField.map("." ++ _).getOrElse(""), value = value) - def matches[A: ElasticPrimitive](field: String, value: A): Match[Any, A] = + def matches[A: ElasticPrimitive](field: String, value: A): MatchQuery[Any] = Match(field = field, value = value) - def must[S](queries: ElasticQuery[S]*): Bool[S] = + def must[S](queries: ElasticQuery[S]*): BoolQuery[S] = Bool[S](filter = Nil, must = queries.toList, should = Nil, boost = None) - def nested[S, A](path: Field[S, Seq[A]], query: ElasticQuery[A]): Nested[S] = + def nested[S, A](path: Field[S, Seq[A]], query: ElasticQuery[A]): NestedQuery[S] = Nested(path = path.toString, query = query, scoreMode = None, ignoreUnmapped = None) - def nested(path: String, query: ElasticQuery[_]): Nested[Any] = + def nested(path: String, query: ElasticQuery[_]): NestedQuery[Any] = Nested(path = path, query = query, scoreMode = None, ignoreUnmapped = None) - def range[S, A](field: Field[S, A], multiField: Option[String] = None): Range[S, A, Unbounded.type, Unbounded.type] = + def range[S, A]( + field: Field[S, A], + multiField: Option[String] = None + ): RangeQuery[S, A, Unbounded.type, Unbounded.type] = Range.empty(field.toString ++ multiField.map("." ++ _).getOrElse("")) - def range(field: String): Range[Any, Any, Unbounded.type, Unbounded.type] = + def range(field: String): RangeQuery[Any, Any, Unbounded.type, Unbounded.type] = Range.empty[Any, Any](field = field) - def should[S](queries: ElasticQuery[S]*): Bool[S] = + def should[S](queries: ElasticQuery[S]*): BoolQuery[S] = Bool[S](filter = Nil, must = Nil, should = queries.toList, boost = None) - def startsWith[S](field: Field[S, _], value: String): Wildcard[S] = + def startsWith[S](field: Field[S, _], value: String): WildcardQuery[S] = Wildcard(field = field.toString, value = s"$value*", boost = None, caseInsensitive = None) - def startsWith(field: String, value: String): Wildcard[Any] = + def startsWith(field: String, value: String): WildcardQuery[Any] = Wildcard(field = field, value = s"$value*", boost = None, caseInsensitive = None) - def term[S, A: ElasticPrimitive](field: Field[S, A], multiField: Option[String] = None, value: A): Term[S, A] = + def term[S, A: ElasticPrimitive](field: Field[S, A], multiField: Option[String] = None, value: A): TermQuery[S] = Term( field = field.toString ++ multiField.map("." ++ _).getOrElse(""), value = value, @@ -139,7 +142,13 @@ object ElasticQuery { def wildcard(field: String, value: String): Wildcard[Any] = Wildcard(field = field, value = value, boost = None, caseInsensitive = None) - sealed trait BoolQuery[S] extends ElasticQuery[S] with HasBoost[S] + sealed trait BoolQuery[S] extends ElasticQuery[S] with HasBoost[BoolQuery[S]] { + def filter(queries: ElasticQuery[S]*): Bool[S] + + def must(queries: ElasticQuery[S]*): Bool[S] + + def should(queries: ElasticQuery[S]*): Bool[S] + } private[elasticsearch] final case class Bool[S]( filter: List[ElasticQuery[S]], @@ -147,7 +156,7 @@ object ElasticQuery { should: List[ElasticQuery[S]], boost: Option[Double] ) extends BoolQuery[S] { self => - def boost(value: Double): Bool[S] = self.copy(boost = Some(value)) + def boost(value: Double): BoolQuery[S] = self.copy(boost = Some(value)) def filter(queries: ElasticQuery[S]*): Bool[S] = self.copy(filter = filter ++ queries) @@ -184,15 +193,18 @@ object ElasticQuery { ) } - sealed trait MatchAllQuery extends ElasticQuery[Any] with HasBoost[Any] + sealed trait MatchAllQuery extends ElasticQuery[Any] with HasBoost[MatchAllQuery] private[elasticsearch] final case class MatchAll(boost: Option[Double]) extends MatchAllQuery { self => - def boost(value: Double): MatchAll = self.copy(boost = Some(value)) + def boost(value: Double): MatchAllQuery = self.copy(boost = Some(value)) def paramsToJson(fieldPath: Option[String]): Json = Obj("match_all" -> Obj(boost.map("boost" -> Num(_)).toList: _*)) } - sealed trait NestedQuery[S] extends ElasticQuery[S] with HasIgnoreUnmapped[S] with HasScoreMode[S] + sealed trait NestedQuery[S] + extends ElasticQuery[S] + with HasIgnoreUnmapped[NestedQuery[S]] + with HasScoreMode[NestedQuery[S]] private[elasticsearch] final case class Nested[S]( path: String, @@ -200,11 +212,11 @@ object ElasticQuery { scoreMode: Option[ScoreMode], ignoreUnmapped: Option[Boolean] ) extends NestedQuery[S] { self => - def ignoreUnmapped(value: Boolean): Nested[S] = self.copy(ignoreUnmapped = Some(value)) + def ignoreUnmapped(value: Boolean): NestedQuery[S] = self.copy(ignoreUnmapped = Some(value)) - def ignoreUnmappedFalse: Nested[S] = ignoreUnmapped(false) + def ignoreUnmappedFalse: NestedQuery[S] = ignoreUnmapped(false) - def ignoreUnmappedTrue: Nested[S] = ignoreUnmapped(true) + def ignoreUnmappedTrue: NestedQuery[S] = ignoreUnmapped(true) def paramsToJson(fieldPath: Option[String]): Json = Obj( @@ -218,7 +230,7 @@ object ElasticQuery { ) ) - def scoreMode(scoreMode: ScoreMode): Nested[S] = self.copy(scoreMode = Some(scoreMode)) + def scoreMode(scoreMode: ScoreMode): NestedQuery[S] = self.copy(scoreMode = Some(scoreMode)) } sealed trait LowerBound { @@ -249,16 +261,35 @@ object ElasticQuery { def toJson: Option[(String, Json)] = None } - sealed trait RangeQuery[S] extends ElasticQuery[S] with HasBoost[S] + sealed trait RangeQuery[S, A, LB <: LowerBound, UB <: UpperBound] + extends ElasticQuery[S] + with HasBoost[RangeQuery[S, A, LB, UB]] { + def gt[B <: A: ElasticPrimitive](value: B)(implicit + @unused ev: LB =:= Unbounded.type + ): Range[S, B, GreaterThan[B], UB] + + def gte[B <: A: ElasticPrimitive](value: B)(implicit + @unused ev: LB =:= Unbounded.type + ): Range[S, B, GreaterThanOrEqualTo[B], UB] + + def lt[B <: A: ElasticPrimitive](value: B)(implicit + @unused ev: UB =:= Unbounded.type + ): Range[S, B, LB, LessThan[B]] + + def lte[B <: A: ElasticPrimitive](value: B)(implicit + @unused ev: UB =:= Unbounded.type + ): Range[S, B, LB, LessThanOrEqualTo[B]] + + } private[elasticsearch] final case class Range[S, A, LB <: LowerBound, UB <: UpperBound] private ( field: String, lower: LB, upper: UB, boost: Option[Double] - ) extends RangeQuery[S] { self => + ) extends RangeQuery[S, A, LB, UB] { self => - def boost(value: Double): Range[S, A, LB, UB] = self.copy(boost = Some(value)) + def boost(value: Double): RangeQuery[S, A, LB, UB] = self.copy(boost = Some(value)) def gt[B <: A: ElasticPrimitive](value: B)(implicit @unused ev: LB =:= Unbounded.type @@ -298,7 +329,7 @@ object ElasticQuery { ) } - sealed trait TermQuery[S] extends ElasticQuery[S] with HasBoost[S] with HasCaseInsensitive[S] + sealed trait TermQuery[S] extends ElasticQuery[S] with HasBoost[TermQuery[S]] with HasCaseInsensitive[TermQuery[S]] private[elasticsearch] final case class Term[S, A: ElasticPrimitive]( field: String, @@ -306,13 +337,13 @@ object ElasticQuery { boost: Option[Double], caseInsensitive: Option[Boolean] ) extends TermQuery[S] { self => - def boost(value: Double): Term[S, A] = self.copy(boost = Some(value)) + def boost(value: Double): TermQuery[S] = self.copy(boost = Some(value)) - def caseInsensitive(value: Boolean): Term[S, A] = self.copy(caseInsensitive = Some(value)) + def caseInsensitive(value: Boolean): TermQuery[S] = self.copy(caseInsensitive = Some(value)) - def caseInsensitiveFalse: Term[S, A] = caseInsensitive(false) + def caseInsensitiveFalse: TermQuery[S] = caseInsensitive(false) - def caseInsensitiveTrue: Term[S, A] = caseInsensitive(true) + def caseInsensitiveTrue: TermQuery[S] = caseInsensitive(true) def paramsToJson(fieldPath: Option[String]): Json = { val termFields = Some("value" -> value.toJson) ++ boost.map("boost" -> Num(_)) ++ caseInsensitive.map( @@ -322,7 +353,10 @@ object ElasticQuery { } } - sealed trait WildcardQuery[S] extends ElasticQuery[S] with HasBoost[S] with HasCaseInsensitive[S] + sealed trait WildcardQuery[S] + extends ElasticQuery[S] + with HasBoost[WildcardQuery[S]] + with HasCaseInsensitive[WildcardQuery[S]] private[elasticsearch] final case class Wildcard[S]( field: String, @@ -330,13 +364,13 @@ object ElasticQuery { boost: Option[Double], caseInsensitive: Option[Boolean] ) extends WildcardQuery[S] { self => - def boost(value: Double): Wildcard[S] = self.copy(boost = Some(value)) + def boost(value: Double): WildcardQuery[S] = self.copy(boost = Some(value)) - def caseInsensitive(value: Boolean): Wildcard[S] = self.copy(caseInsensitive = Some(value)) + def caseInsensitive(value: Boolean): WildcardQuery[S] = self.copy(caseInsensitive = Some(value)) - def caseInsensitiveFalse: Wildcard[S] = caseInsensitive(false) + def caseInsensitiveFalse: WildcardQuery[S] = caseInsensitive(false) - def caseInsensitiveTrue: Wildcard[S] = caseInsensitive(true) + def caseInsensitiveTrue: WildcardQuery[S] = caseInsensitive(true) def paramsToJson(fieldPath: Option[String]): Json = { val wildcardFields = Some("value" -> value.toJson) ++ boost.map("boost" -> Num(_)) ++ caseInsensitive.map( diff --git a/modules/library/src/main/scala/zio/elasticsearch/ElasticRequest.scala b/modules/library/src/main/scala/zio/elasticsearch/ElasticRequest.scala index 0a083cc2d..0d28d17b9 100644 --- a/modules/library/src/main/scala/zio/elasticsearch/ElasticRequest.scala +++ b/modules/library/src/main/scala/zio/elasticsearch/ElasticRequest.scala @@ -19,16 +19,16 @@ package zio.elasticsearch import zio.elasticsearch.Routing.Routing import zio.schema.Schema -trait HasRefresh[A] { - def refresh(value: Boolean): ElasticRequest[A] +trait HasRefresh[R <: HasRefresh[R]] { + def refresh(value: Boolean): R - def refreshFalse: ElasticRequest[A] + def refreshFalse: R - def refreshTrue: ElasticRequest[A] + def refreshTrue: R } -trait HasRouting[A] { - def routing(value: Routing): ElasticRequest[A] +trait HasRouting[R <: HasRouting[R]] { + def routing(value: Routing): R } sealed trait BulkableRequest[A] extends ElasticRequest[A] @@ -37,43 +37,43 @@ sealed trait ElasticRequest[A] object ElasticRequest { - def bulk(requests: BulkableRequest[_]*): Bulk = + def bulk(requests: BulkableRequest[_]*): BulkRequest = Bulk.of(requests = requests: _*) - def create[A: Schema](index: IndexName, doc: A): Create = + def create[A: Schema](index: IndexName, doc: A): CreateRequest = Create(index = index, document = Document.from(doc), refresh = None, routing = None) - def create[A: Schema](index: IndexName, id: DocumentId, doc: A): CreateWithId = + def create[A: Schema](index: IndexName, id: DocumentId, doc: A): CreateWithIdRequest = CreateWithId(index = index, id = id, document = Document.from(doc), refresh = None, routing = None) - def createIndex(name: IndexName): CreateIndex = + def createIndex(name: IndexName): CreateIndexRequest = CreateIndex(name = name, definition = None) - def createIndex(name: IndexName, definition: String): CreateIndex = + def createIndex(name: IndexName, definition: String): CreateIndexRequest = CreateIndex(name = name, definition = Some(definition)) - def deleteById(index: IndexName, id: DocumentId): DeleteById = + def deleteById(index: IndexName, id: DocumentId): DeleteByIdRequest = DeleteById(index = index, id = id, refresh = None, routing = None) - def deleteByQuery(index: IndexName, query: ElasticQuery[_]): DeleteByQuery = + def deleteByQuery(index: IndexName, query: ElasticQuery[_]): DeleteByQueryRequest = DeleteByQuery(index = index, query = query, refresh = None, routing = None) - def deleteIndex(name: IndexName): DeleteIndex = + def deleteIndex(name: IndexName): DeleteIndexRequest = DeleteIndex(name = name) - def exists(index: IndexName, id: DocumentId): Exists = + def exists(index: IndexName, id: DocumentId): ExistRequest = Exists(index = index, id = id, routing = None) - def getById(index: IndexName, id: DocumentId): GetById = + def getById(index: IndexName, id: DocumentId): GetByIdRequest = GetById(index = index, id = id, refresh = None, routing = None) - def search(index: IndexName, query: ElasticQuery[_]): Search = + def search(index: IndexName, query: ElasticQuery[_]): SearchRequest = Search(index = index, query = query, routing = None) - def upsert[A: Schema](index: IndexName, id: DocumentId, doc: A): CreateOrUpdate = + def upsert[A: Schema](index: IndexName, id: DocumentId, doc: A): CreateOrUpdateRequest = CreateOrUpdate(index = index, id = id, document = Document.from(doc), refresh = None, routing = None) - sealed trait BulkRequest extends ElasticRequest[Unit] with HasRefresh[Unit] with HasRouting[Unit] + sealed trait BulkRequest extends ElasticRequest[Unit] with HasRefresh[BulkRequest] with HasRouting[BulkRequest] private[elasticsearch] final case class Bulk( requests: List[BulkableRequest[_]], @@ -81,13 +81,13 @@ object ElasticRequest { refresh: Option[Boolean], routing: Option[Routing] ) extends BulkRequest { self => - def refresh(value: Boolean): Bulk = self.copy(refresh = Some(value)) + def refresh(value: Boolean): BulkRequest = self.copy(refresh = Some(value)) - def refreshFalse: Bulk = refresh(false) + def refreshFalse: BulkRequest = refresh(false) - def refreshTrue: Bulk = refresh(true) + def refreshTrue: BulkRequest = refresh(true) - def routing(value: Routing): Bulk = self.copy(routing = Some(value)) + def routing(value: Routing): BulkRequest = self.copy(routing = Some(value)) lazy val body: String = requests.flatMap { r => r match { @@ -114,7 +114,10 @@ object ElasticRequest { Bulk(requests = requests.toList, index = None, refresh = None, routing = None) } - sealed trait CreateRequest extends BulkableRequest[DocumentId] with HasRefresh[DocumentId] with HasRouting[DocumentId] + sealed trait CreateRequest + extends BulkableRequest[DocumentId] + with HasRefresh[CreateRequest] + with HasRouting[CreateRequest] private[elasticsearch] final case class Create( index: IndexName, @@ -122,19 +125,19 @@ object ElasticRequest { refresh: Option[Boolean], routing: Option[Routing] ) extends CreateRequest { self => - def refresh(value: Boolean): Create = self.copy(refresh = Some(value)) + def refresh(value: Boolean): CreateRequest = self.copy(refresh = Some(value)) - def refreshFalse: Create = refresh(false) + def refreshFalse: CreateRequest = refresh(false) - def refreshTrue: Create = refresh(true) + def refreshTrue: CreateRequest = refresh(true) - def routing(value: Routing): Create = self.copy(routing = Some(value)) + def routing(value: Routing): CreateRequest = self.copy(routing = Some(value)) } sealed trait CreateWithIdRequest extends BulkableRequest[CreationOutcome] - with HasRefresh[CreationOutcome] - with HasRouting[CreationOutcome] + with HasRefresh[CreateWithIdRequest] + with HasRouting[CreateWithIdRequest] private[elasticsearch] final case class CreateWithId( index: IndexName, @@ -143,13 +146,13 @@ object ElasticRequest { refresh: Option[Boolean], routing: Option[Routing] ) extends CreateWithIdRequest { self => - def refresh(value: Boolean): CreateWithId = self.copy(refresh = Some(value)) + def refresh(value: Boolean): CreateWithIdRequest = self.copy(refresh = Some(value)) - def refreshFalse: CreateWithId = refresh(false) + def refreshFalse: CreateWithIdRequest = refresh(false) - def refreshTrue: CreateWithId = refresh(true) + def refreshTrue: CreateWithIdRequest = refresh(true) - def routing(value: Routing): CreateWithId = self.copy(routing = Some(value)) + def routing(value: Routing): CreateWithIdRequest = self.copy(routing = Some(value)) } sealed trait CreateIndexRequest extends ElasticRequest[CreationOutcome] @@ -159,7 +162,10 @@ object ElasticRequest { definition: Option[String] ) extends CreateIndexRequest - sealed trait CreateOrUpdateRequest extends BulkableRequest[Unit] with HasRefresh[Unit] with HasRouting[Unit] + sealed trait CreateOrUpdateRequest + extends BulkableRequest[Unit] + with HasRefresh[CreateOrUpdateRequest] + with HasRouting[CreateOrUpdateRequest] private[elasticsearch] final case class CreateOrUpdate( index: IndexName, @@ -168,19 +174,19 @@ object ElasticRequest { refresh: Option[Boolean], routing: Option[Routing] ) extends CreateOrUpdateRequest { self => - def refresh(value: Boolean): CreateOrUpdate = self.copy(refresh = Some(value)) + def refresh(value: Boolean): CreateOrUpdateRequest = self.copy(refresh = Some(value)) - def refreshFalse: CreateOrUpdate = refresh(false) + def refreshFalse: CreateOrUpdateRequest = refresh(false) - def refreshTrue: CreateOrUpdate = refresh(true) + def refreshTrue: CreateOrUpdateRequest = refresh(true) - def routing(value: Routing): CreateOrUpdate = self.copy(routing = Some(value)) + def routing(value: Routing): CreateOrUpdateRequest = self.copy(routing = Some(value)) } sealed trait DeleteByIdRequest extends BulkableRequest[DeletionOutcome] - with HasRefresh[DeletionOutcome] - with HasRouting[DeletionOutcome] + with HasRefresh[DeleteByIdRequest] + with HasRouting[DeleteByIdRequest] private[elasticsearch] final case class DeleteById( index: IndexName, @@ -188,19 +194,19 @@ object ElasticRequest { refresh: Option[Boolean], routing: Option[Routing] ) extends DeleteByIdRequest { self => - def refresh(value: Boolean): DeleteById = self.copy(refresh = Some(value)) + def refresh(value: Boolean): DeleteByIdRequest = self.copy(refresh = Some(value)) - def refreshFalse: DeleteById = refresh(false) + def refreshFalse: DeleteByIdRequest = refresh(false) - def refreshTrue: DeleteById = refresh(true) + def refreshTrue: DeleteByIdRequest = refresh(true) - def routing(value: Routing): DeleteById = self.copy(routing = Some(value)) + def routing(value: Routing): DeleteByIdRequest = self.copy(routing = Some(value)) } sealed trait DeleteByQueryRequest extends ElasticRequest[DeletionOutcome] - with HasRefresh[DeletionOutcome] - with HasRouting[DeletionOutcome] + with HasRefresh[DeleteByQueryRequest] + with HasRouting[DeleteByQueryRequest] private[elasticsearch] final case class DeleteByQuery( index: IndexName, @@ -208,30 +214,33 @@ object ElasticRequest { refresh: Option[Boolean], routing: Option[Routing] ) extends DeleteByQueryRequest { self => - def refresh(value: Boolean): DeleteByQuery = self.copy(refresh = Some(value)) + def refresh(value: Boolean): DeleteByQueryRequest = self.copy(refresh = Some(value)) - def refreshFalse: DeleteByQuery = refresh(false) + def refreshFalse: DeleteByQueryRequest = refresh(false) - def refreshTrue: DeleteByQuery = refresh(true) + def refreshTrue: DeleteByQueryRequest = refresh(true) - def routing(value: Routing): DeleteByQuery = self.copy(routing = Some(value)) + def routing(value: Routing): DeleteByQueryRequest = self.copy(routing = Some(value)) } sealed trait DeleteIndexRequest extends ElasticRequest[DeletionOutcome] final case class DeleteIndex(name: IndexName) extends DeleteIndexRequest - sealed trait ExistRequest extends ElasticRequest[Boolean] with HasRouting[Boolean] + sealed trait ExistRequest extends ElasticRequest[Boolean] with HasRouting[ExistRequest] private[elasticsearch] final case class Exists( index: IndexName, id: DocumentId, routing: Option[Routing] ) extends ExistRequest { self => - def routing(value: Routing): Exists = self.copy(routing = Some(value)) + def routing(value: Routing): ExistRequest = self.copy(routing = Some(value)) } - sealed trait GetByIdRequest extends ElasticRequest[GetResult] with HasRefresh[GetResult] with HasRouting[GetResult] + sealed trait GetByIdRequest + extends ElasticRequest[GetResult] + with HasRefresh[GetByIdRequest] + with HasRouting[GetByIdRequest] private[elasticsearch] final case class GetById( index: IndexName, @@ -239,22 +248,22 @@ object ElasticRequest { refresh: Option[Boolean], routing: Option[Routing] ) extends GetByIdRequest { self => - def refresh(value: Boolean): GetById = self.copy(refresh = Some(value)) + def refresh(value: Boolean): GetByIdRequest = self.copy(refresh = Some(value)) - def refreshFalse: GetById = refresh(false) + def refreshFalse: GetByIdRequest = refresh(false) - def refreshTrue: GetById = refresh(true) + def refreshTrue: GetByIdRequest = refresh(true) - def routing(value: Routing): GetById = self.copy(routing = Some(value)) + def routing(value: Routing): GetByIdRequest = self.copy(routing = Some(value)) } - sealed trait GetByQueryRequest extends ElasticRequest[SearchResult] + sealed trait SearchRequest extends ElasticRequest[SearchResult] private[elasticsearch] final case class Search( index: IndexName, query: ElasticQuery[_], routing: Option[Routing] - ) extends GetByQueryRequest + ) extends SearchRequest private def getActionAndMeta(requestType: String, parameters: List[(String, Any)]): String = parameters.collect { case (name, Some(value)) => s""""$name" : "${value.toString}"""" } diff --git a/modules/library/src/main/scala/zio/elasticsearch/HttpElasticExecutor.scala b/modules/library/src/main/scala/zio/elasticsearch/HttpElasticExecutor.scala index eb144f9f1..6379ae186 100644 --- a/modules/library/src/main/scala/zio/elasticsearch/HttpElasticExecutor.scala +++ b/modules/library/src/main/scala/zio/elasticsearch/HttpElasticExecutor.scala @@ -55,12 +55,12 @@ private[elasticsearch] final class HttpElasticExecutor private (config: ElasticC case r: Search => executeSearch(r) } - def stream(r: Search): Stream[Throwable, Item] = + def stream(r: SearchRequest): Stream[Throwable, Item] = ZStream.paginateChunkZIO("") { s => if (s.isEmpty) executeGetByQueryWithScroll(r) else executeGetByScroll(s) } - def streamAs[A: Schema](r: Search): Stream[Throwable, A] = + def streamAs[A: Schema](r: SearchRequest): Stream[Throwable, A] = ZStream .paginateChunkZIO("") { s => if (s.isEmpty) executeGetByQueryWithScroll(r) else executeGetByScroll(s) @@ -245,25 +245,30 @@ private[elasticsearch] final class HttpElasticExecutor private (config: ElasticC } } - private def executeGetByQueryWithScroll(r: Search): Task[(Chunk[Item], Option[String])] = - sendRequestWithCustomResponse( - request - .post( - uri"${config.uri}/${r.index}/$Search".withParams((Scroll, ScrollDefaultDuration)) - ) - .response(asJson[ElasticQueryResponse]) - .contentType(ApplicationJson) - .body(r.query.toJson) - ).flatMap { response => - response.code match { - case HttpOk => - response.body.fold( - e => ZIO.fail(new ElasticException(s"Exception occurred: ${e.getMessage}")), - value => ZIO.succeed((Chunk.fromIterable(value.results).map(Item), value.scrollId)) - ) - case _ => - ZIO.fail(createElasticExceptionFromCustomResponse(response)) - } + private def executeGetByQueryWithScroll(r: SearchRequest): Task[(Chunk[Item], Option[String])] = + r match { + case s: Search => + sendRequestWithCustomResponse( + request + .post( + uri"${config.uri}/${s.index}/$Search".withParams( + getQueryParams(List((Scroll, Some(ScrollDefaultDuration)), ("routing", s.routing))) + ) + ) + .response(asJson[ElasticQueryResponse]) + .contentType(ApplicationJson) + .body(s.query.toJson) + ).flatMap { response => + response.code match { + case HttpOk => + response.body.fold( + e => ZIO.fail(new ElasticException(s"Exception occurred: ${e.getMessage}")), + value => ZIO.succeed((Chunk.fromIterable(value.results).map(Item), value.scrollId)) + ) + case _ => + ZIO.fail(createElasticExceptionFromCustomResponse(response)) + } + } } private def executeGetByScroll(scrollId: String): Task[(Chunk[Item], Option[String])] = From 6308dfce6789319885b86deb2e5599765aab4a3c Mon Sep 17 00:00:00 2001 From: Dimitrije Bulaja Date: Tue, 14 Mar 2023 11:45:23 +0100 Subject: [PATCH 2/3] Refactor code --- .../zio/elasticsearch/ElasticQuery.scala | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala b/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala index 25c24ed25..aba9ce47b 100644 --- a/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala +++ b/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala @@ -143,11 +143,11 @@ object ElasticQuery { Wildcard(field = field, value = value, boost = None, caseInsensitive = None) sealed trait BoolQuery[S] extends ElasticQuery[S] with HasBoost[BoolQuery[S]] { - def filter(queries: ElasticQuery[S]*): Bool[S] + def filter(queries: ElasticQuery[S]*): BoolQuery[S] - def must(queries: ElasticQuery[S]*): Bool[S] + def must(queries: ElasticQuery[S]*): BoolQuery[S] - def should(queries: ElasticQuery[S]*): Bool[S] + def should(queries: ElasticQuery[S]*): BoolQuery[S] } private[elasticsearch] final case class Bool[S]( @@ -158,10 +158,10 @@ object ElasticQuery { ) extends BoolQuery[S] { self => def boost(value: Double): BoolQuery[S] = self.copy(boost = Some(value)) - def filter(queries: ElasticQuery[S]*): Bool[S] = + def filter(queries: ElasticQuery[S]*): BoolQuery[S] = self.copy(filter = filter ++ queries) - def must(queries: ElasticQuery[S]*): Bool[S] = + def must(queries: ElasticQuery[S]*): BoolQuery[S] = self.copy(must = must ++ queries) def paramsToJson(fieldPath: Option[String]): Json = { @@ -173,7 +173,7 @@ object ElasticQuery { Obj("bool" -> Obj(boolFields.toList: _*)) } - def should(queries: ElasticQuery[S]*): Bool[S] = + def should(queries: ElasticQuery[S]*): BoolQuery[S] = self.copy(should = should ++ queries) } @@ -266,20 +266,19 @@ object ElasticQuery { with HasBoost[RangeQuery[S, A, LB, UB]] { def gt[B <: A: ElasticPrimitive](value: B)(implicit @unused ev: LB =:= Unbounded.type - ): Range[S, B, GreaterThan[B], UB] + ): RangeQuery[S, B, GreaterThan[B], UB] def gte[B <: A: ElasticPrimitive](value: B)(implicit @unused ev: LB =:= Unbounded.type - ): Range[S, B, GreaterThanOrEqualTo[B], UB] + ): RangeQuery[S, B, GreaterThanOrEqualTo[B], UB] def lt[B <: A: ElasticPrimitive](value: B)(implicit @unused ev: UB =:= Unbounded.type - ): Range[S, B, LB, LessThan[B]] + ): RangeQuery[S, B, LB, LessThan[B]] def lte[B <: A: ElasticPrimitive](value: B)(implicit @unused ev: UB =:= Unbounded.type - ): Range[S, B, LB, LessThanOrEqualTo[B]] - + ): RangeQuery[S, B, LB, LessThanOrEqualTo[B]] } private[elasticsearch] final case class Range[S, A, LB <: LowerBound, UB <: UpperBound] private ( @@ -293,22 +292,22 @@ object ElasticQuery { def gt[B <: A: ElasticPrimitive](value: B)(implicit @unused ev: LB =:= Unbounded.type - ): Range[S, B, GreaterThan[B], UB] = + ): RangeQuery[S, B, GreaterThan[B], UB] = self.copy(lower = GreaterThan(value)) def gte[B <: A: ElasticPrimitive](value: B)(implicit @unused ev: LB =:= Unbounded.type - ): Range[S, B, GreaterThanOrEqualTo[B], UB] = + ): RangeQuery[S, B, GreaterThanOrEqualTo[B], UB] = self.copy(lower = GreaterThanOrEqualTo(value)) def lt[B <: A: ElasticPrimitive](value: B)(implicit @unused ev: UB =:= Unbounded.type - ): Range[S, B, LB, LessThan[B]] = + ): RangeQuery[S, B, LB, LessThan[B]] = self.copy(upper = LessThan(value)) def lte[B <: A: ElasticPrimitive](value: B)(implicit @unused ev: UB =:= Unbounded.type - ): Range[S, B, LB, LessThanOrEqualTo[B]] = + ): RangeQuery[S, B, LB, LessThanOrEqualTo[B]] = self.copy(upper = LessThanOrEqualTo(value)) def paramsToJson(fieldPath: Option[String]): Json = { From 6f4384497074ca07c135cf41991e86ff025ea235 Mon Sep 17 00:00:00 2001 From: Dimitrije Bulaja Date: Tue, 14 Mar 2023 12:14:54 +0100 Subject: [PATCH 3/3] Format code --- .../zio/elasticsearch/ElasticQuery.scala | 74 ++++++++++------ .../zio/elasticsearch/ElasticRequest.scala | 87 ++++++++++++------- 2 files changed, 106 insertions(+), 55 deletions(-) diff --git a/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala b/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala index aba9ce47b..64cdb6983 100644 --- a/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala +++ b/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala @@ -48,7 +48,8 @@ sealed trait HasScoreMode[Q <: HasScoreMode[Q]] { sealed trait ElasticQuery[-S] { self => def paramsToJson(fieldPath: Option[String]): Json - final def toJson: Json = Obj("query" -> self.paramsToJson(None)) + final def toJson: Json = + Obj("query" -> self.paramsToJson(None)) } object ElasticQuery { @@ -83,14 +84,17 @@ object ElasticQuery { def contains(field: String, value: String): WildcardQuery[Any] = Wildcard(field = field, value = s"*$value*", boost = None, caseInsensitive = None) - def exists[S](field: Field[S, _]): ExistsQuery[S] = Exists(field = field.toString) + def exists[S](field: Field[S, _]): ExistsQuery[S] = + Exists(field = field.toString) - def exists(field: String): ExistsQuery[Any] = Exists(field = field) + def exists(field: String): ExistsQuery[Any] = + Exists(field = field) def filter[S](queries: ElasticQuery[S]*): BoolQuery[S] = Bool[S](filter = queries.toList, must = Nil, should = Nil, boost = None) - def matchAll: MatchAllQuery = MatchAll(boost = None) + def matchAll: MatchAllQuery = + MatchAll(boost = None) def matches[S, A: ElasticPrimitive](field: Field[S, A], multiField: Option[String] = None, value: A): MatchQuery[S] = Match(field = field.toString ++ multiField.map("." ++ _).getOrElse(""), value = value) @@ -156,7 +160,8 @@ object ElasticQuery { should: List[ElasticQuery[S]], boost: Option[Double] ) extends BoolQuery[S] { self => - def boost(value: Double): BoolQuery[S] = self.copy(boost = Some(value)) + def boost(value: Double): BoolQuery[S] = + self.copy(boost = Some(value)) def filter(queries: ElasticQuery[S]*): BoolQuery[S] = self.copy(filter = filter ++ queries) @@ -180,25 +185,29 @@ object ElasticQuery { sealed trait ExistsQuery[S] extends ElasticQuery[S] private[elasticsearch] final case class Exists[S](field: String) extends ExistsQuery[S] { - def paramsToJson(fieldPath: Option[String]): Json = Obj( - "exists" -> Obj("field" -> (fieldPath.map(_ + ".").getOrElse("") + field).toJson) - ) + def paramsToJson(fieldPath: Option[String]): Json = + Obj( + "exists" -> Obj("field" -> (fieldPath.map(_ + ".").getOrElse("") + field).toJson) + ) } sealed trait MatchQuery[S] extends ElasticQuery[S] private[elasticsearch] final case class Match[S, A: ElasticPrimitive](field: String, value: A) extends MatchQuery[S] { - def paramsToJson(fieldPath: Option[String]): Json = Obj( - "match" -> Obj(fieldPath.map(_ + ".").getOrElse("") + field -> value.toJson) - ) + def paramsToJson(fieldPath: Option[String]): Json = + Obj( + "match" -> Obj(fieldPath.map(_ + ".").getOrElse("") + field -> value.toJson) + ) } sealed trait MatchAllQuery extends ElasticQuery[Any] with HasBoost[MatchAllQuery] private[elasticsearch] final case class MatchAll(boost: Option[Double]) extends MatchAllQuery { self => - def boost(value: Double): MatchAllQuery = self.copy(boost = Some(value)) + def boost(value: Double): MatchAllQuery = + self.copy(boost = Some(value)) - def paramsToJson(fieldPath: Option[String]): Json = Obj("match_all" -> Obj(boost.map("boost" -> Num(_)).toList: _*)) + def paramsToJson(fieldPath: Option[String]): Json = + Obj("match_all" -> Obj(boost.map("boost" -> Num(_)).toList: _*)) } sealed trait NestedQuery[S] @@ -212,11 +221,14 @@ object ElasticQuery { scoreMode: Option[ScoreMode], ignoreUnmapped: Option[Boolean] ) extends NestedQuery[S] { self => - def ignoreUnmapped(value: Boolean): NestedQuery[S] = self.copy(ignoreUnmapped = Some(value)) + def ignoreUnmapped(value: Boolean): NestedQuery[S] = + self.copy(ignoreUnmapped = Some(value)) - def ignoreUnmappedFalse: NestedQuery[S] = ignoreUnmapped(false) + def ignoreUnmappedFalse: NestedQuery[S] = + ignoreUnmapped(false) - def ignoreUnmappedTrue: NestedQuery[S] = ignoreUnmapped(true) + def ignoreUnmappedTrue: NestedQuery[S] = + ignoreUnmapped(true) def paramsToJson(fieldPath: Option[String]): Json = Obj( @@ -230,7 +242,8 @@ object ElasticQuery { ) ) - def scoreMode(scoreMode: ScoreMode): NestedQuery[S] = self.copy(scoreMode = Some(scoreMode)) + def scoreMode(scoreMode: ScoreMode): NestedQuery[S] = + self.copy(scoreMode = Some(scoreMode)) } sealed trait LowerBound { @@ -288,7 +301,8 @@ object ElasticQuery { boost: Option[Double] ) extends RangeQuery[S, A, LB, UB] { self => - def boost(value: Double): RangeQuery[S, A, LB, UB] = self.copy(boost = Some(value)) + def boost(value: Double): RangeQuery[S, A, LB, UB] = + self.copy(boost = Some(value)) def gt[B <: A: ElasticPrimitive](value: B)(implicit @unused ev: LB =:= Unbounded.type @@ -336,13 +350,17 @@ object ElasticQuery { boost: Option[Double], caseInsensitive: Option[Boolean] ) extends TermQuery[S] { self => - def boost(value: Double): TermQuery[S] = self.copy(boost = Some(value)) + def boost(value: Double): TermQuery[S] = + self.copy(boost = Some(value)) - def caseInsensitive(value: Boolean): TermQuery[S] = self.copy(caseInsensitive = Some(value)) + def caseInsensitive(value: Boolean): TermQuery[S] = + self.copy(caseInsensitive = Some(value)) - def caseInsensitiveFalse: TermQuery[S] = caseInsensitive(false) + def caseInsensitiveFalse: TermQuery[S] = + caseInsensitive(false) - def caseInsensitiveTrue: TermQuery[S] = caseInsensitive(true) + def caseInsensitiveTrue: TermQuery[S] = + caseInsensitive(true) def paramsToJson(fieldPath: Option[String]): Json = { val termFields = Some("value" -> value.toJson) ++ boost.map("boost" -> Num(_)) ++ caseInsensitive.map( @@ -363,13 +381,17 @@ object ElasticQuery { boost: Option[Double], caseInsensitive: Option[Boolean] ) extends WildcardQuery[S] { self => - def boost(value: Double): WildcardQuery[S] = self.copy(boost = Some(value)) + def boost(value: Double): WildcardQuery[S] = + self.copy(boost = Some(value)) - def caseInsensitive(value: Boolean): WildcardQuery[S] = self.copy(caseInsensitive = Some(value)) + def caseInsensitive(value: Boolean): WildcardQuery[S] = + self.copy(caseInsensitive = Some(value)) - def caseInsensitiveFalse: WildcardQuery[S] = caseInsensitive(false) + def caseInsensitiveFalse: WildcardQuery[S] = + caseInsensitive(false) - def caseInsensitiveTrue: WildcardQuery[S] = caseInsensitive(true) + def caseInsensitiveTrue: WildcardQuery[S] = + caseInsensitive(true) def paramsToJson(fieldPath: Option[String]): Json = { val wildcardFields = Some("value" -> value.toJson) ++ boost.map("boost" -> Num(_)) ++ caseInsensitive.map( diff --git a/modules/library/src/main/scala/zio/elasticsearch/ElasticRequest.scala b/modules/library/src/main/scala/zio/elasticsearch/ElasticRequest.scala index 0d28d17b9..3b0dfd6b2 100644 --- a/modules/library/src/main/scala/zio/elasticsearch/ElasticRequest.scala +++ b/modules/library/src/main/scala/zio/elasticsearch/ElasticRequest.scala @@ -81,13 +81,17 @@ object ElasticRequest { refresh: Option[Boolean], routing: Option[Routing] ) extends BulkRequest { self => - def refresh(value: Boolean): BulkRequest = self.copy(refresh = Some(value)) + def refresh(value: Boolean): BulkRequest = + self.copy(refresh = Some(value)) - def refreshFalse: BulkRequest = refresh(false) + def refreshFalse: BulkRequest = + refresh(false) - def refreshTrue: BulkRequest = refresh(true) + def refreshTrue: BulkRequest = + refresh(true) - def routing(value: Routing): BulkRequest = self.copy(routing = Some(value)) + def routing(value: Routing): BulkRequest = + self.copy(routing = Some(value)) lazy val body: String = requests.flatMap { r => r match { @@ -125,13 +129,17 @@ object ElasticRequest { refresh: Option[Boolean], routing: Option[Routing] ) extends CreateRequest { self => - def refresh(value: Boolean): CreateRequest = self.copy(refresh = Some(value)) + def refresh(value: Boolean): CreateRequest = + self.copy(refresh = Some(value)) - def refreshFalse: CreateRequest = refresh(false) + def refreshFalse: CreateRequest = + refresh(false) - def refreshTrue: CreateRequest = refresh(true) + def refreshTrue: CreateRequest = + refresh(true) - def routing(value: Routing): CreateRequest = self.copy(routing = Some(value)) + def routing(value: Routing): CreateRequest = + self.copy(routing = Some(value)) } sealed trait CreateWithIdRequest @@ -146,13 +154,17 @@ object ElasticRequest { refresh: Option[Boolean], routing: Option[Routing] ) extends CreateWithIdRequest { self => - def refresh(value: Boolean): CreateWithIdRequest = self.copy(refresh = Some(value)) + def refresh(value: Boolean): CreateWithIdRequest = + self.copy(refresh = Some(value)) - def refreshFalse: CreateWithIdRequest = refresh(false) + def refreshFalse: CreateWithIdRequest = + refresh(false) - def refreshTrue: CreateWithIdRequest = refresh(true) + def refreshTrue: CreateWithIdRequest = + refresh(true) - def routing(value: Routing): CreateWithIdRequest = self.copy(routing = Some(value)) + def routing(value: Routing): CreateWithIdRequest = + self.copy(routing = Some(value)) } sealed trait CreateIndexRequest extends ElasticRequest[CreationOutcome] @@ -174,13 +186,17 @@ object ElasticRequest { refresh: Option[Boolean], routing: Option[Routing] ) extends CreateOrUpdateRequest { self => - def refresh(value: Boolean): CreateOrUpdateRequest = self.copy(refresh = Some(value)) + def refresh(value: Boolean): CreateOrUpdateRequest = + self.copy(refresh = Some(value)) - def refreshFalse: CreateOrUpdateRequest = refresh(false) + def refreshFalse: CreateOrUpdateRequest = + refresh(false) - def refreshTrue: CreateOrUpdateRequest = refresh(true) + def refreshTrue: CreateOrUpdateRequest = + refresh(true) - def routing(value: Routing): CreateOrUpdateRequest = self.copy(routing = Some(value)) + def routing(value: Routing): CreateOrUpdateRequest = + self.copy(routing = Some(value)) } sealed trait DeleteByIdRequest @@ -194,13 +210,17 @@ object ElasticRequest { refresh: Option[Boolean], routing: Option[Routing] ) extends DeleteByIdRequest { self => - def refresh(value: Boolean): DeleteByIdRequest = self.copy(refresh = Some(value)) + def refresh(value: Boolean): DeleteByIdRequest = + self.copy(refresh = Some(value)) - def refreshFalse: DeleteByIdRequest = refresh(false) + def refreshFalse: DeleteByIdRequest = + refresh(false) - def refreshTrue: DeleteByIdRequest = refresh(true) + def refreshTrue: DeleteByIdRequest = + refresh(true) - def routing(value: Routing): DeleteByIdRequest = self.copy(routing = Some(value)) + def routing(value: Routing): DeleteByIdRequest = + self.copy(routing = Some(value)) } sealed trait DeleteByQueryRequest @@ -214,13 +234,17 @@ object ElasticRequest { refresh: Option[Boolean], routing: Option[Routing] ) extends DeleteByQueryRequest { self => - def refresh(value: Boolean): DeleteByQueryRequest = self.copy(refresh = Some(value)) + def refresh(value: Boolean): DeleteByQueryRequest = + self.copy(refresh = Some(value)) - def refreshFalse: DeleteByQueryRequest = refresh(false) + def refreshFalse: DeleteByQueryRequest = + refresh(false) - def refreshTrue: DeleteByQueryRequest = refresh(true) + def refreshTrue: DeleteByQueryRequest = + refresh(true) - def routing(value: Routing): DeleteByQueryRequest = self.copy(routing = Some(value)) + def routing(value: Routing): DeleteByQueryRequest = + self.copy(routing = Some(value)) } sealed trait DeleteIndexRequest extends ElasticRequest[DeletionOutcome] @@ -234,7 +258,8 @@ object ElasticRequest { id: DocumentId, routing: Option[Routing] ) extends ExistRequest { self => - def routing(value: Routing): ExistRequest = self.copy(routing = Some(value)) + def routing(value: Routing): ExistRequest = + self.copy(routing = Some(value)) } sealed trait GetByIdRequest @@ -248,13 +273,17 @@ object ElasticRequest { refresh: Option[Boolean], routing: Option[Routing] ) extends GetByIdRequest { self => - def refresh(value: Boolean): GetByIdRequest = self.copy(refresh = Some(value)) + def refresh(value: Boolean): GetByIdRequest = + self.copy(refresh = Some(value)) - def refreshFalse: GetByIdRequest = refresh(false) + def refreshFalse: GetByIdRequest = + refresh(false) - def refreshTrue: GetByIdRequest = refresh(true) + def refreshTrue: GetByIdRequest = + refresh(true) - def routing(value: Routing): GetByIdRequest = self.copy(routing = Some(value)) + def routing(value: Routing): GetByIdRequest = + self.copy(routing = Some(value)) } sealed trait SearchRequest extends ElasticRequest[SearchResult]