Skip to content

Commit

Permalink
Keep includes when specifying excludes and vice versa
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippus committed May 5, 2024
1 parent 0a5c0af commit 0616a97
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ class GetTest extends AnyFlatSpec with Matchers with DockerTests {
resp.sourceAsMap shouldBe Map("name" -> "bud lite")
}

it should "support source includes and excludes" in {

val resp = client.execute {
get("8") from "beer" fetchSourceInclude(List("name")) fetchSourceExclude(List("bran"))
}.await.result

resp.exists should be(true)
resp.id shouldBe "8"
resp.sourceAsMap shouldBe Map("name" -> "bud lite")
}

it should "retrieve a document supporting stored fields" in {

val resp = client.execute {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ class SearchTest extends AnyWordSpec with DockerTests with Matchers {
search("chess") query matchAllQuery() sourceExclude "count"
}.await.result.hits.hits.map(_.sourceAsString).toSet shouldBe Set("{\"name\":\"pawn\",\"value\":1}", "{\"aka\":\"horse\",\"name\":\"knight\",\"value\":3}", "{\"name\":\"king\",\"value\":0}", "{\"aka\":\"castle\",\"name\":\"rook\",\"value\":5}", "{\"name\":\"queen\",\"value\":10}", "{\"name\":\"bishop\",\"value\":3}")
}
"support a mix of source includes and excludes" in {
client.execute {
search("chess") query matchAllQuery() sourceInclude "value" sourceExclude "name"
}.await.result.hits.hits.map(_.sourceAsString).toSet shouldBe Set("{\"value\":0}", "{\"value\":1}", "{\"value\":3}", "{\"value\":5}", "{\"value\":10}")
}
"support constantScoreQuery" should {
"work with termQuery" in {
client.execute {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,22 @@ class MatchQueryTest

resp.hits.hits.head.sourceAsMap shouldBe Map("scientist.name" -> "Jules Violle")
}

"a match query" should "support excluding nested properties" in {

val resp = client.execute {
search("units") query matchQuery("name", "candela") sourceExclude "scientist.name"
}.await.result

resp.hits.hits.head.sourceAsMap shouldBe Map("name" -> "candela", "scientist.country" -> "France")
}

"a match query" should "support including and excluding nested properties" in {

val resp = client.execute {
search("units") query matchQuery("name", "candela") sourceInclude "scientist.name" sourceExclude "scientist.country"
}.await.result

resp.hits.hits.head.sourceAsMap shouldBe Map("name" -> "candela")
}
}

0 comments on commit 0616a97

Please sign in to comment.