Skip to content

Commit

Permalink
Feat: add support for docvalue_fields in TopHitsAggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Constant committed Oct 10, 2024
1 parent 5c126aa commit 2363f4f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ object TopHitsAggregationBuilder {

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

if (agg.storedFields.nonEmpty)
builder.array("docvalue_fields", agg.storedFields.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,9 +13,10 @@ class TopHitsAggregationBuilderTest extends AnyFunSuite with Matchers {
.from(10)
.version(true)
.explain(false)
.storedFields(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,"version":true}}"""
"""{"top_hits":{"size":5,"from":10,"sort":[{"price":{"mode":"median","order":"asc"}}],"explain":false,"docvalue_fields":["name"],"version":true}}"""
}

test("top hits aggregation builder should support highlighting") {
Expand Down

0 comments on commit 2363f4f

Please sign in to comment.