From 33f87996b2faed53a37e532629d74d863d8ebbc9 Mon Sep 17 00:00:00 2001 From: Taehyun Kim Date: Sat, 14 Dec 2019 02:19:45 +0900 Subject: [PATCH] add rest_total_hits_as_int param --- .../sksamuel/elastic4s/searches/MultiSearchRequest.scala | 7 ++++++- .../com/sksamuel/elastic4s/searches/SearchRequest.scala | 5 ++++- .../sksamuel/elastic4s/http/search/SearchHandlers.scala | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/searches/MultiSearchRequest.scala b/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/searches/MultiSearchRequest.scala index 0afd090cf1..18dcf6a326 100644 --- a/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/searches/MultiSearchRequest.scala +++ b/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/searches/MultiSearchRequest.scala @@ -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) } diff --git a/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/searches/SearchRequest.scala b/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/searches/SearchRequest.scala index f427272004..4a41f89c39 100644 --- a/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/searches/SearchRequest.scala +++ b/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/searches/SearchRequest.scala @@ -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 * @@ -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) } diff --git a/elastic4s-http/src/main/scala/com/sksamuel/elastic4s/http/search/SearchHandlers.scala b/elastic4s-http/src/main/scala/com/sksamuel/elastic4s/http/search/SearchHandlers.scala index a656090912..cd2f1a9dc3 100644 --- a/elastic4s-http/src/main/scala/com/sksamuel/elastic4s/http/search/SearchHandlers.scala +++ b/elastic4s-http/src/main/scala/com/sksamuel/elastic4s/http/search/SearchHandlers.scala @@ -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) @@ -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)) }