Skip to content

Commit

Permalink
Add docValueFields to TopHitsAggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Constant committed Oct 11, 2024
1 parent 2363f4f commit 820de83
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ case class TopHitsAggregation(name: String,
version: Option[Boolean] = None,
scripts: Map[String, Script] = Map.empty,
storedFields: Seq[String] = Nil,
docValueFields: Seq[String] = Nil,
subaggs: Seq[AbstractAggregation] = Nil,
metadata: Map[String, AnyRef] = Map.empty,
highlight: Option[Highlight] = None)
Expand All @@ -42,6 +43,9 @@ case class TopHitsAggregation(name: String,
def storedFields(first: String, rest: String*): TopHitsAggregation = storedFields(first +: rest)
def storedFields(fields: Iterable[String]): TopHitsAggregation = copy(storedFields = fields.toSeq)

def docValueFields(docValueFields: Iterable[String]): TopHitsAggregation =
copy(docValueFields = docValueFields.toSeq)

def version(version: Boolean): TopHitsAggregation = copy(version = version.some)
def trackScores(trackScores: Boolean): TopHitsAggregation = copy(trackScores = trackScores.some)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ object TopHitsAggregationBuilder {

agg.explain.foreach(builder.field("explain", _))

if (agg.storedFields.nonEmpty)
builder.array("docvalue_fields", agg.storedFields.toArray)
if (agg.docValueFields.nonEmpty)
builder.array("docvalue_fields", agg.docValueFields.toArray)

agg.highlight.foreach { highlight =>
builder.rawField("highlight", HighlightBuilderFn(highlight))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TopHitsAggregationBuilderTest extends AnyFunSuite with Matchers {
.from(10)
.version(true)
.explain(false)
.storedFields(List("name"))
.docValueFields(List("name"))
.sortBy(List(FieldSort("price").sortMode(SortMode.Median)))
TopHitsAggregationBuilder(q).string shouldBe
"""{"top_hits":{"size":5,"from":10,"sort":[{"price":{"mode":"median","order":"asc"}}],"explain":false,"docvalue_fields":["name"],"version":true}}"""
Expand Down

0 comments on commit 820de83

Please sign in to comment.