-
Notifications
You must be signed in to change notification settings - Fork 695
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't generate a query body for NoopQuery (#3078)
* Don't generate a query body for NoopQuery * Exclude empty queries in sequences
- Loading branch information
Showing
7 changed files
with
64 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...src/test/scala/com/sksamuel/elastic4s/requests/searches/queries/NoopQueryBodyFnTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.sksamuel.elastic4s.requests.searches.queries | ||
|
||
import com.sksamuel.elastic4s.ElasticDsl._ | ||
import com.sksamuel.elastic4s.handlers.searches.queries.QueryBuilderFn | ||
import org.scalatest.funsuite.AnyFunSuite | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class NoopQueryBodyFnTest extends AnyFunSuite with Matchers { | ||
test("NoopQuery should not generate a query body") { | ||
val q = boolQuery().should(Seq(NoopQuery)) | ||
QueryBuilderFn(q).string shouldBe """{"bool":{"should":[]}}""" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
.../src/main/scala/com/sksamuel/elastic4s/handlers/searches/queries/NoopQueryBuilderFn.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.sksamuel.elastic4s.handlers.searches.queries | ||
|
||
import com.sksamuel.elastic4s.json.{XContentBuilder, XContentFactory} | ||
|
||
object NoopQueryBuilderFn { | ||
def apply(): XContentBuilder = XContentFactory.parse("") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/search/queries/NoopQueryTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.sksamuel.elastic4s.search.queries | ||
|
||
import scala.util.Try | ||
|
||
import com.sksamuel.elastic4s.requests.searches.queries.NoopQuery | ||
import com.sksamuel.elastic4s.testkit.DockerTests | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class NoopQueryTest extends AnyFlatSpec with Matchers with DockerTests { | ||
Try { | ||
client.execute { | ||
deleteIndex("noop") | ||
}.await | ||
} | ||
|
||
client.execute { | ||
createIndex("noop") | ||
}.await | ||
|
||
"noop query" should "not error out when executed" in { | ||
client.execute { | ||
search("noop").query { | ||
boolQuery().should(Seq(NoopQuery)) | ||
} | ||
}.await.result | ||
} | ||
|
||
"it" should "not error out when executed in a sequence" in { | ||
client.execute { | ||
search("noop").query { | ||
boolQuery().should(Seq(NoopQuery, NoopQuery)) | ||
} | ||
}.await.result | ||
} | ||
} |