Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(dsl): Implement matchAll query #31

Merged
merged 1 commit into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ object ElasticQuery {

def exists(field: String): Exists = Exists(field)

def matchAll(): MatchAll = MatchAll()

def range(field: String): Range[Unbounded.type, Unbounded.type] = Range.empty(field)

private[elasticsearch] final case class BoolQuery(must: List[ElasticQuery], should: List[ElasticQuery])
Expand Down Expand Up @@ -72,6 +74,10 @@ object ElasticQuery {
override def toJson: Json = Obj("match" -> Obj(field -> value.toJson))
}

private[elasticsearch] final case class MatchAll() extends ElasticQuery {
override def toJson: Json = Obj("match_all" -> Obj())
}

sealed trait LowerBound {
def toJson: Option[(String, Json)]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ object QueryDSLSpec extends ZIOSpecDefault {

assert(query)(equalTo(Exists(field = "day_of_week")))
},
test("successfully create MatchAll Query") {
val query = matchAll()

assert(query)(equalTo(MatchAll()))
},
test("successfully create empty Range Query") {
val query = range(field = "customer_age")

Expand Down Expand Up @@ -230,6 +235,19 @@ object QueryDSLSpec extends ZIOSpecDefault {

assert(query.toJsonBody)(equalTo(expected.toJson))
},
test("properly encode MatchAll Query") {
val query = matchAll()
val expected =
"""
|{
| "query": {
| "match_all": {}
| }
|}
|""".stripMargin

assert(query.toJsonBody)(equalTo(expected.toJson))
},
test("properly encode Unbounded Range Query") {
val query = range(field = "field")
val expected =
Expand Down