Skip to content

Commit

Permalink
Fix code remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjaftn committed Nov 30, 2023
1 parent 84860b3 commit e0bf016
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private[elasticsearch] object AvgAggregationResponse {
implicit val decoder: JsonDecoder[AvgAggregationResponse] = DeriveJsonDecoder.gen[AvgAggregationResponse]
}

case class BucketDecoder(fields: Chunk[(String, Json)]) extends JsonDecoderOps {
private[elasticsearch] case class BucketDecoder(fields: Chunk[(String, Json)]) extends JsonDecoderOps {
val allFields: Map[String, Any] = fields.flatMap { case (field, data) =>
field match {
case "key" =>
Expand Down Expand Up @@ -267,9 +267,10 @@ private[elasticsearch] final case class FilterAggregationResponse(

private[elasticsearch] object FilterAggregationResponse {
implicit val decoder: JsonDecoder[FilterAggregationResponse] = Obj.decoder.mapOrFail { case Obj(fields) =>
val allFields = BucketDecoder(fields).allFields
val docCount = allFields("doc_count").asInstanceOf[Int]
val subAggs = BucketDecoder(fields).subAggs
val bucketDecoder = BucketDecoder(fields)
val allFields = bucketDecoder.allFields
val docCount = allFields("doc_count").asInstanceOf[Int]
val subAggs = bucketDecoder.subAggs

Right(FilterAggregationResponse.apply(docCount, Option(subAggs).filter(_.nonEmpty)))
}
Expand Down Expand Up @@ -376,10 +377,11 @@ private[elasticsearch] final case class TermsAggregationBucket(

private[elasticsearch] object TermsAggregationBucket {
implicit val decoder: JsonDecoder[TermsAggregationBucket] = Obj.decoder.mapOrFail { case Obj(fields) =>
val allFields = BucketDecoder(fields).allFields
val key = allFields("key").asInstanceOf[String]
val docCount = allFields("doc_count").asInstanceOf[Int]
val subAggs = BucketDecoder(fields).subAggs
val bucketDecoder = BucketDecoder(fields)
val allFields = bucketDecoder.allFields
val docCount = allFields("doc_count").asInstanceOf[Int]
val key = allFields("key").asInstanceOf[String]
val subAggs = bucketDecoder.subAggs

Right(TermsAggregationBucket.apply(key, docCount, Option(subAggs).filter(_.nonEmpty)))
}
Expand Down

0 comments on commit e0bf016

Please sign in to comment.