diff --git a/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/requests/get/GetTest.scala b/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/requests/get/GetTest.scala index 2f11f423a..aadc13487 100644 --- a/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/requests/get/GetTest.scala +++ b/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/requests/get/GetTest.scala @@ -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 { diff --git a/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/search/SearchTest.scala b/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/search/SearchTest.scala index 3420deb16..06c0b1561 100644 --- a/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/search/SearchTest.scala +++ b/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/search/SearchTest.scala @@ -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 { diff --git a/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/search/queries/MatchQueryTest.scala b/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/search/queries/MatchQueryTest.scala index 43ee15573..20a5fc20e 100644 --- a/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/search/queries/MatchQueryTest.scala +++ b/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/search/queries/MatchQueryTest.scala @@ -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") + } }