Skip to content

Commit

Permalink
add rest_total_hits_as_int param
Browse files Browse the repository at this point in the history
  • Loading branch information
kimxogus committed Dec 13, 2019
1 parent 4f88a95 commit 33f8799
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ package com.sksamuel.elastic4s.searches

import com.sksamuel.exts.OptionImplicits._

case class MultiSearchRequest(searches: Iterable[SearchRequest], maxConcurrentSearches: Option[Int] = None, typedKeys: Option[Boolean] = None) {
case class MultiSearchRequest(searches: Iterable[SearchRequest],
maxConcurrentSearches: Option[Int] = None,
typedKeys: Option[Boolean] = None,
restTotalHitsAsInt: Option[Boolean] = None) {
def maxConcurrentSearches(max: Int): MultiSearchRequest = copy(maxConcurrentSearches = max.some)

def typedKeys(enabled: Boolean): MultiSearchRequest = copy(typedKeys = enabled.some)

def restTotalHitsAsInt(restTotalHitsAsInt: Boolean): MultiSearchRequest = copy(restTotalHitsAsInt = restTotalHitsAsInt.some)
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ case class SearchRequest(indexesTypes: IndexesAndTypes,
profile: Option[Boolean] = None,
source: Option[String] = None,
trackHits: Option[Boolean] = None,
typedKeys: Option[Boolean] = None) {
typedKeys: Option[Boolean] = None,
restTotalHitsAsInt: Option[Boolean] = None) {

/** Adds a single string query to this search
*
Expand Down Expand Up @@ -300,4 +301,6 @@ case class SearchRequest(indexesTypes: IndexesAndTypes,
def collapse(collapse: CollapseRequest): SearchRequest = copy(collapse = collapse.some)

def typedKeys(enabled: Boolean): SearchRequest = copy(typedKeys = enabled.some)

def restTotalHitsAsInt(restTotalHitsAsInt: Boolean): MultiSearchRequest = copy(restTotalHitsAsInt = restTotalHitsAsInt.some)
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ trait SearchHandlers {
val params = scala.collection.mutable.Map.empty[String, String]
request.maxConcurrentSearches.map(_.toString).foreach(params.put("max_concurrent_searches", _))
request.typedKeys.map(_.toString).foreach(params.put("typed_keys", _))
request.restTotalHitsAsInt.map(_.toString).foreach(params.put("rest_total_hits_as_int", _))

val body = MultiSearchBuilderFn(request)
logger.debug("Executing msearch: " + body)
Expand Down Expand Up @@ -88,6 +89,8 @@ trait SearchHandlers {

request.typedKeys.map(_.toString).foreach(params.put("typed_keys", _))

request.restTotalHitsAsInt.map(_.toString).foreach(params.put("rest_total_hits_as_int", _))

val body = request.source.getOrElse(SearchBodyBuilderFn(request).string())
ElasticRequest("POST", endpoint, params.toMap, HttpEntity(body, ContentType.APPLICATION_JSON.getMimeType))
}
Expand Down

0 comments on commit 33f8799

Please sign in to comment.