Skip to content

Commit

Permalink
OK-711: example of making domain objects for queries
Browse files Browse the repository at this point in the history
  • Loading branch information
pkalliok committed Jan 22, 2025
1 parent 8aca5dd commit 769a524
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,28 @@ import java.util.concurrent.CompletableFuture

import scala.collection.immutable.Stream.concat

abstract class Query

case class MatchQuery(`match`: Map[String, String]) extends Query

case class Search(
query: Query,
size: Integer,
sort: Map[String, String],
search_after: Option[List[String]]
)

object ElasticQueries {
import org.json4s.JsonDSL._
implicit val formats = DefaultFormats

def toteutusSearch(after: Option[String]) : JValue = {
val query = (("query" -> ("match" -> ("tila" -> "julkaistu"))) ~
("size" -> 1000) ~
("sort" -> ("oid.keyword" -> "asc")))
after match {
case None => query
case Some(s) => query ~ ("search_after" -> List(after))
}
}
def toteutusSearch(after: Option[String]) : JValue =
Extraction.decompose(Search(
MatchQuery(Map("tila" -> "julkaistu")),
1000,
Map("oid.keyword" -> "asc"),
after.map(List(_))
))
}

object ElasticClient extends Logging with KoutaJsonFormats {
Expand Down

0 comments on commit 769a524

Please sign in to comment.