-
Notifications
You must be signed in to change notification settings - Fork 694
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added span field masking query (#2568)
Co-authored-by: Maxim D <[email protected]>
- Loading branch information
1 parent
bf26a9e
commit f3e70d0
Showing
5 changed files
with
53 additions
and
3 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
18 changes: 18 additions & 0 deletions
18
...m/sksamuel/elastic4s/requests/searches/queries/span/SpanFieldMaskingQueryBodyFnTest.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,18 @@ | ||
package com.sksamuel.elastic4s.requests.searches.queries.span | ||
|
||
import com.sksamuel.elastic4s.handlers.searches.queries.span.SpanFieldMaskingQueryBodyFn | ||
import com.sksamuel.elastic4s.requests.searches.span.{SpanFieldMaskingQuery, SpanTermQuery} | ||
import org.scalatest.funsuite.AnyFunSuite | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class SpanFieldMaskingQueryBodyFnTest extends AnyFunSuite with Matchers { | ||
test("SpanFieldMaskingQueryBodyFn apply should return appropriate XContentBuilder") { | ||
val builder = SpanFieldMaskingQueryBodyFn.apply(SpanFieldMaskingQuery( | ||
field = "masked_field", | ||
query = SpanTermQuery("field1", "value1", Some("name1"), Some(4.0)), | ||
boost = Some(2.0), | ||
queryName = Some("rootName") | ||
)) | ||
builder.string() shouldBe """{"span_field_masking":{"field":"masked_field","boost":2.0,"_name":"rootName","query":{"span_term":{"field1":"value1","boost":4.0,"_name":"name1"}}}}""" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
.../src/main/scala/com/sksamuel/elastic4s/requests/searches/span/SpanFieldMaskingQuery.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,9 @@ | ||
package com.sksamuel.elastic4s.requests.searches.span | ||
|
||
case class SpanFieldMaskingQuery(field: String, query: SpanQuery, boost: Option[Double] = None, queryName: Option[String] = None) | ||
extends SpanQuery { | ||
|
||
def boost(boost: Double): SpanFieldMaskingQuery = copy(boost = Option(boost)) | ||
def queryName(queryName: String): SpanFieldMaskingQuery = withQueryName(queryName) | ||
def withQueryName(queryName: String): SpanFieldMaskingQuery = copy(queryName = Option(queryName)) | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...a/com/sksamuel/elastic4s/handlers/searches/queries/span/SpanFieldMaskingQueryBodyFn.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,21 @@ | ||
package com.sksamuel.elastic4s.handlers.searches.queries.span | ||
|
||
import com.sksamuel.elastic4s.handlers.searches.queries | ||
import com.sksamuel.elastic4s.json.{XContentBuilder, XContentFactory} | ||
import com.sksamuel.elastic4s.requests.searches.span.SpanFieldMaskingQuery | ||
|
||
object SpanFieldMaskingQueryBodyFn { | ||
def apply(q: SpanFieldMaskingQuery): XContentBuilder = { | ||
val builder = XContentFactory.jsonBuilder() | ||
builder.startObject("span_field_masking") | ||
|
||
builder.field("field", q.field) | ||
q.boost.foreach(builder.field("boost", _)) | ||
q.queryName.foreach(builder.field("_name", _)) | ||
|
||
builder.rawField("query", queries.QueryBuilderFn(q.query)) | ||
|
||
builder.endObject() | ||
builder.endObject() | ||
} | ||
} |