All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sksamuel.elastic4s.requests.searches.MultiSearchResponse.scala Maven / Gradle / Ivy

There is a newer version: 8.15.4
Show newest version
package com.sksamuel.elastic4s.requests.searches

import com.sksamuel.elastic4s.{ElasticError, HitReader}

import scala.util.Try

case class MultisearchResponseItem(index: Int, status: Int, response: Either[ElasticError, SearchResponse])

case class MultiSearchResponse(items: Seq[MultisearchResponseItem]) {

  def size: Int = items.size

  def failures: Seq[ElasticError] = items.map(_.response).collect {
    case left: Left[ElasticError, SearchResponse] => left.left.get
  }

  def successes: Seq[SearchResponse] = items.map(_.response).collect {
    case right: Right[ElasticError, SearchResponse] => right.right.get
  }

  def to[T: HitReader]: IndexedSeq[T] = successes.flatMap(_.hits.hits).map(_.to[T]).toIndexedSeq
  def safeTo[T: HitReader]: IndexedSeq[Try[T]] = successes.flatMap(_.hits.hits).map(_.safeTo[T]).toIndexedSeq
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy