Skip to content

Commit

Permalink
Fix code remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
petarcurcin committed Jun 24, 2023
1 parent 813252f commit 0c1e2b3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
30 changes: 30 additions & 0 deletions docs/overview/aggregations/elastic_aggregation_missing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
id: elastic_aggregation_missing
title: "Missing Aggregation"
---

The `Missing` aggregation is a field data based single bucket aggregation, that creates a bucket of all documents in the current document set context that are missing a field value.

In order to use the `Missing` aggregation import the following:
```scala
import zio.elasticsearch.aggregation.MissingAggregation
import zio.elasticsearch.ElasticAggregation.missingAggregation
```

You can create a `Missing` aggregation using the `missingAggregation` method this way:
```scala
val aggregation: MissingAggregation = missingAggregation(name = "missingAggregation", field = "stringField")
```

You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Missing` aggregation using the `missingAggregation` method this way:
```scala
// Document.stringField must be string value, because of Missing aggregation
val aggregation: MissingAggregation = missingAggregation(name = "missingAggregation", field = Document.stringField)
```

If you want to add aggregation (on the same level), you can use `withAgg` method:
```scala
val multipleAggregations: MultipleAggregations = missingAggregation(name = "missingAggregation1", field = Document.stringField).withAgg(missingAggregation(name = "missingAggregation2", field = Document.stringField))
```

You can find more information about `Missing` aggregation [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-aggregations-bucket-missing-aggregation.html).
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ object ElasticAggregation {
* aggregation name
* @param field
* the type-safe field for which missing aggregation will be executed
* @tparam A
* expected number type
* @return
* an instance of [[zio.elasticsearch.aggregation.MissingAggregation]] that represents missing aggregation to be
* performed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private[elasticsearch] object MinAggregationResponse {
}

private[elasticsearch] final case class MissingAggregationResponse(@jsonField("doc_count") docCount: Int)
extends AggregationResponse
extends AggregationResponse

private[elasticsearch] object MissingAggregationResponse {
implicit val decoder: JsonDecoder[MissingAggregationResponse] = DeriveJsonDecoder.gen[MissingAggregationResponse]
Expand Down Expand Up @@ -136,6 +136,8 @@ private[elasticsearch] object TermsAggregationBucket {
Some(field -> MaxAggregationResponse(value = objFields("value").unsafeAs[Double]))
case str if str.contains("min#") =>
Some(field -> MinAggregationResponse(value = objFields("value").unsafeAs[Double]))
case str if str.contains("missing#") =>
Some(field -> MissingAggregationResponse(docCount = objFields("doc_count").unsafeAs[Int]))
case str if str.contains("sum#") =>
Some(field -> SumAggregationResponse(value = objFields("value").unsafeAs[Double]))
case str if str.contains("terms#") =>
Expand Down Expand Up @@ -165,6 +167,8 @@ private[elasticsearch] object TermsAggregationBucket {
(field.split("#")(1), data.asInstanceOf[MaxAggregationResponse])
case str if str.contains("min#") =>
(field.split("#")(1), data.asInstanceOf[MinAggregationResponse])
case str if str.contains("missing#") =>
(field.split("#")(1), data.asInstanceOf[MissingAggregationResponse])
case str if str.contains("sum#") =>
(field.split("#")(1), data.asInstanceOf[SumAggregationResponse])
case str if str.contains("terms#") =>
Expand Down

0 comments on commit 0c1e2b3

Please sign in to comment.