-
Notifications
You must be signed in to change notification settings - Fork 18
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): Support 'hasChild' query #191
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
id: elastic_query_has_child | ||
title: "Has Child Query" | ||
--- | ||
|
||
TBD |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,10 @@ | |
|
||
package zio.elasticsearch | ||
|
||
import zio.elasticsearch.ElasticPrimitive.ElasticPrimitive | ||
import zio.elasticsearch.query._ | ||
import zio.schema.Schema | ||
|
||
import ElasticPrimitive.ElasticPrimitive | ||
|
||
object ElasticQuery { | ||
|
||
/** | ||
|
@@ -110,7 +109,36 @@ object ElasticQuery { | |
Bool[Any](filter = queries.toList, must = Nil, mustNot = Nil, should = Nil, boost = None, minimumShouldMatch = None) | ||
|
||
/** | ||
* Constructs an instance of [[zio.elasticsearch.query.HasParent]] using the specified parameters. | ||
* Constructs an instance of [[zio.elasticsearch.query.HasChildQuery]] using the specified parameters. | ||
* | ||
* @param childType | ||
* a name of the child relationship mapped for the join field | ||
* @param query | ||
* query you wish to run on child documents of the child `type` field | ||
* @tparam S | ||
* document for which field query is executed | ||
* @return | ||
* an instance of [[zio.elasticsearch.query.HasChildQuery]] that represents the has parent query to be performed. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ..has child query.. |
||
|
||
final def hasChild[S: Schema](childType: String, query: ElasticQuery[S]): HasChildQuery[S] = | ||
HasChild(childType = childType, query = query) | ||
|
||
/** | ||
* Constructs an instance of [[zio.elasticsearch.query.HasChildQuery]] using the specified parameters. | ||
* | ||
* @param childType | ||
* a name of the child relationship mapped for the join field | ||
* @param query | ||
* query you wish to run on child documents of the child `type` field | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A [[ElasticQuery]] ... |
||
* @return | ||
* an instance of [[zio.elasticsearch.query.HasChildQuery]] that represents the has parent query to be performed. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ..has child query.. |
||
final def hasChild(childType: String, query: ElasticQuery[Any]): HasChildQuery[Any] = | ||
HasChild(childType = childType, query = query) | ||
|
||
/** | ||
* Constructs an instance of [[zio.elasticsearch.query.HasParentQuery]] using the specified parameters. | ||
* | ||
* @param parentType | ||
* a name of the parent relationship mapped for the join field | ||
|
@@ -119,20 +147,20 @@ object ElasticQuery { | |
* @tparam S | ||
* document for which field query is executed | ||
* @return | ||
* an instance of [[zio.elasticsearch.query.HasParent]] that represents the has parent query to be performed. | ||
* an instance of [[zio.elasticsearch.query.HasParentQuery]] that represents the has parent query to be performed. | ||
*/ | ||
final def hasParent[S: Schema](parentType: String, query: ElasticQuery[S]): HasParentQuery[S] = | ||
HasParent(parentType = parentType, query = query) | ||
|
||
/** | ||
* Constructs an instance of [[zio.elasticsearch.query.HasParent]] using the specified parameters. | ||
* Constructs an instance of [[zio.elasticsearch.query.HasParentQuery]] using the specified parameters. | ||
* | ||
* @param parentType | ||
* a name of the parent relationship mapped for the join field | ||
* @param query | ||
* query you wish to run on parent documents of the `parent_type` field | ||
* @return | ||
* an instance of [[zio.elasticsearch.query.HasParent]] that represents the has parent query to be performed. | ||
* an instance of [[zio.elasticsearch.query.HasParentQuery]] that represents the has parent query to be performed. | ||
*/ | ||
final def hasParent(parentType: String, query: ElasticQuery[Any]): HasParentQuery[Any] = | ||
HasParent[Any](parentType = parentType, query = query) | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -109,6 +109,75 @@ private[elasticsearch] final case class Exists[S](field: String) extends ExistsQ | |||||
Obj("exists" -> Obj("field" -> fieldPath.foldRight(field)(_ + "." + _).toJson)) | ||||||
} | ||||||
|
||||||
sealed trait HasChildQuery[S] | ||||||
extends ElasticQuery[S] | ||||||
with HasIgnoreUnmapped[HasChildQuery[S]] | ||||||
with HasInnerHits[HasChildQuery[S]] | ||||||
with HasScoreMode[HasChildQuery[S]] { | ||||||
|
||||||
/** | ||||||
* Sets the `maxChildren` parameter parameter for the [[HasChildQuery]]. | ||||||
* | ||||||
* Indicates maximum number of child documents that match the query allowed for a returned parent document If the | ||||||
* parent document exceeds this limit, it is excluded from the search results. | ||||||
* | ||||||
* @param value | ||||||
* the [[scala.Int]] value for `score` parameter | ||||||
* @return | ||||||
* a new instance of the [[HasChildQuery]] with the `score` value set. | ||||||
*/ | ||||||
def maxChildren(value: Int): HasChildQuery[S] | ||||||
|
||||||
/** | ||||||
* Sets the `minChildren` parameter parameter for the [[HasChildQuery]]. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* | ||||||
* Indicates minimum number of child documents that match the query required to match the query for a returned parent | ||||||
* document. If the parent document does not meet this limit, it is excluded from the search results. | ||||||
* | ||||||
* @param value | ||||||
* the [[scala.Int]] value for `score` parameter | ||||||
* @return | ||||||
* a new instance of the [[HasChildQuery]] with the `score` value set. | ||||||
*/ | ||||||
def minChildren(value: Int): HasChildQuery[S] | ||||||
} | ||||||
|
||||||
private[elasticsearch] final case class HasChild[S]( | ||||||
childType: String, | ||||||
query: ElasticQuery[S], | ||||||
ignoreUnmapped: Option[Boolean] = None, | ||||||
innerHitsField: Option[InnerHits] = None, | ||||||
maxChildren: Option[Int] = None, | ||||||
minChildren: Option[Int] = None, | ||||||
scoreMode: Option[ScoreMode] = None | ||||||
) extends HasChildQuery[S] { self => | ||||||
|
||||||
def ignoreUnmapped(value: Boolean): HasChildQuery[S] = self.copy(ignoreUnmapped = Some(value)) | ||||||
|
||||||
def innerHits(innerHits: InnerHits): HasChildQuery[S] = self.copy(innerHitsField = Some(innerHits)) | ||||||
|
||||||
def maxChildren(value: Int): HasChildQuery[S] = self.copy(maxChildren = Some(value)) | ||||||
|
||||||
def minChildren(value: Int): HasChildQuery[S] = self.copy(minChildren = Some(value)) | ||||||
|
||||||
def paramsToJson(fieldPath: Option[String]): Json = | ||||||
Obj( | ||||||
"has_child" -> Obj( | ||||||
List( | ||||||
Some("type" -> Str(childType)), | ||||||
Some("query" -> query.paramsToJson(None)), | ||||||
ignoreUnmapped.map("ignore_unmapped" -> Json.Bool(_)), | ||||||
innerHitsField.map(_.toStringJsonPair), | ||||||
maxChildren.map("max_children" -> Json.Num(_)), | ||||||
minChildren.map("min_children" -> Json.Num(_)), | ||||||
scoreMode.map(sm => "score_mode" -> Json.Str(sm.toString.toLowerCase)) | ||||||
).flatten: _* | ||||||
) | ||||||
) | ||||||
|
||||||
def scoreMode(value: ScoreMode): HasChildQuery[S] = self.copy(scoreMode = Some(value)) | ||||||
} | ||||||
|
||||||
sealed trait HasParentQuery[S] | ||||||
extends ElasticQuery[S] | ||||||
with HasIgnoreUnmapped[HasParentQuery[S]] | ||||||
|
@@ -155,7 +224,8 @@ private[elasticsearch] final case class HasParent[S]( | |||||
ignoreUnmapped: Option[Boolean] = None, | ||||||
innerHitsField: Option[InnerHits] = None, | ||||||
score: Option[Boolean] = None | ||||||
) extends HasParentQuery[S] { self => | ||||||
) extends HasParentQuery[S] { | ||||||
self => | ||||||
|
||||||
def ignoreUnmapped(value: Boolean): HasParentQuery[S] = | ||||||
self.copy(ignoreUnmapped = Some(value)) | ||||||
|
@@ -178,15 +248,6 @@ private[elasticsearch] final case class HasParent[S]( | |||||
|
||||||
def withScore(value: Boolean): HasParent[S] = | ||||||
self.copy(score = Some(value)) | ||||||
|
||||||
/** | ||||||
* Sets the inner hits configuration for the [[NestedQuery]]. | ||||||
* | ||||||
* @param innerHits | ||||||
* the configuration for inner hits | ||||||
* @return | ||||||
* a new instance of the [[ElasticQuery]] with the specified inner hits configuration. | ||||||
*/ | ||||||
} | ||||||
|
||||||
sealed trait MatchQuery[S] extends ElasticQuery[S] with HasBoost[MatchQuery[S]] | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A [[ElasticQuery]] ...