Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set track_total_hits to false when without sort #233

Merged
merged 6 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ private[elasticsearch] final class HttpExecutor private (esConfig: ElasticConfig

val sortsJson =
if (r.sortBy.isEmpty) {
Obj("sort" -> Arr(ShardDoc.toJson))
Obj("sort" -> Arr(ShardDoc.toJson), "track_total_hits" -> false.toJson)
} else {
Obj("sort" -> Arr(r.sortBy.map(_.toJson)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import zio.Chunk
import zio.json.{DeriveJsonDecoder, JsonDecoder, jsonField}

private[elasticsearch] final case class Hits(
total: Total,
total: Option[Total],
@jsonField("max_score")
maxScore: Option[Double] = None,
hits: Chunk[Hit]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ final class SearchResult private[elasticsearch] (

lazy val response: UIO[SearchWithAggregationsResponse] = ZIO.succeed(fullResponse)

lazy val total: UIO[Long] = ZIO.succeed(fullResponse.hits.total.value)
lazy val total: IO[ElasticException, Long] =
ZIO
.fromOption(fullResponse.hits.total)
.map(_.value)
.mapError(_ => new ElasticException("Total hits are not being tracked."))
}

final class SearchAndAggregateResult private[elasticsearch] (
Expand Down Expand Up @@ -104,5 +108,9 @@ final class SearchAndAggregateResult private[elasticsearch] (

lazy val response: UIO[SearchWithAggregationsResponse] = ZIO.succeed(fullResponse)

lazy val total: UIO[Long] = ZIO.succeed(fullResponse.hits.total.value)
lazy val total: IO[ElasticException, Long] =
ZIO
.fromOption(fullResponse.hits.total)
.map(_.value)
.mapError(_ => new ElasticException("Total hits are not being tracked."))
}