<commit_before>package com.sksamuel.elastic4s.http.get

import java.net.URLEncoder

import com.fasterxml.jackson.databind.JsonNode
import com.sksamuel.elastic4s.HitReader
import com.sksamuel.elastic4s.get.{GetRequest, MultiGetRequest}
import com.sksamuel.elastic4s.http._
import com.sksamuel.exts.Logging
import org.apache.http.entity.ContentType

case class MultiGetResponse(docs: Seq[GetResponse]) {
  def items: Seq[GetResponse] = docs
  def size: Int               = docs.size

  def to[T: HitReader]: IndexedSeq[T]                        = docs.map(_.to[T]).toIndexedSeq
  def safeTo[T: HitReader]: IndexedSeq[Either[Throwable, T]] = docs.map(_.safeTo[T]).toIndexedSeq
}

trait GetHandlers {

  implicit object MultiGetHandler extends Handler[MultiGetRequest, MultiGetResponse] with Logging {

    override def responseHandler: ResponseHandler[MultiGetResponse] = new ResponseHandler[MultiGetResponse] {
      override def handle(response: HttpResponse): Either[ElasticError, MultiGetResponse] = response.statusCode match {
        case 404 | 500 => sys.error(response.toString)
        case _ =>
          val r = ResponseHandler.fromResponse[MultiGetResponse](response)
          val r2 = r.copy(docs = r.docs.map { doc =>
            doc.copy(fields = Option(doc.fields).getOrElse(Map.empty))
          })
          Right(r2)
      }
    }

    override def build(request: MultiGetRequest): ElasticRequest = {
      val body   = MultiGetBodyBuilder(request).string()
      val entity = HttpEntity(body, ContentType.APPLICATION_JSON.getMimeType)
      ElasticRequest("POST", "/_mget", entity)
    }
  }

  implicit object GetHandler extends Handler[GetRequest, GetResponse] with Logging {

    override def responseHandler = new ResponseHandler[GetResponse] {

      override def handle(response: HttpResponse): Either[ElasticError, GetResponse] = {
<commit_msg>Use GET rather than POST for multiget<commit_after>package com.sksamuel.elastic4s.http.get

import java.net.URLEncoder

import com.fasterxml.jackson.databind.JsonNode
import com.sksamuel.elastic4s.HitReader
import com.sksamuel.elastic4s.get.{GetRequest, MultiGetRequest}
import com.sksamuel.elastic4s.http._
import com.sksamuel.exts.Logging
import org.apache.http.entity.ContentType

case class MultiGetResponse(docs: Seq[GetResponse]) {
  def items: Seq[GetResponse] = docs
  def size: Int               = docs.size

  def to[T: HitReader]: IndexedSeq[T]                        = docs.map(_.to[T]).toIndexedSeq
  def safeTo[T: HitReader]: IndexedSeq[Either[Throwable, T]] = docs.map(_.safeTo[T]).toIndexedSeq
}

trait GetHandlers {

  implicit object MultiGetHandler extends Handler[MultiGetRequest, MultiGetResponse] with Logging {

    override def responseHandler: ResponseHandler[MultiGetResponse] = new ResponseHandler[MultiGetResponse] {
      override def handle(response: HttpResponse): Either[ElasticError, MultiGetResponse] = response.statusCode match {
        case 404 | 500 => sys.error(response.toString)
        case _ =>
          val r = ResponseHandler.fromResponse[MultiGetResponse](response)
          val r2 = r.copy(docs = r.docs.map { doc =>
            doc.copy(fields = Option(doc.fields).getOrElse(Map.empty))
          })
          Right(r2)
      }
    }

    override def build(request: MultiGetRequest): ElasticRequest = {
      val body   = MultiGetBodyBuilder(request).string()
      val entity = HttpEntity(body, ContentType.APPLICATION_JSON.getMimeType)
      ElasticRequest("GET", "/_mget", entity)
    }
  }

  implicit object GetHandler extends Handler[GetRequest, GetResponse] with Logging {

    override def responseHandler = new ResponseHandler[GetResponse] {

      override def handle(response: HttpResponse): Either[ElasticError, GetResponse] = {

{'fraction_non_alphanumeric': 0.0999734113267748, 'fraction_numerical': 0.006381281574049455, 'mean_word_length': 3.8045977011494254, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5110181', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1106, 'n_words': 234}