首页 > 解决方案 > 如何将 SearchResponse 转换为 JsValue

问题描述

我想知道是否有一些直接的方法可以转换com.sksamuel.elastic4s.http.search.SearchResponseplay.api.libs.json.JsValue.

我看到SearchHitinSearchResponse可以通过 method 转换为 JSON String sourceAsString

但我需要一些信息,SearchResponse例如总点击量。

标签: scalaplay-jsonelastic4s

解决方案


x is Response[SearchResponse]

val s = x.result.hits.hits.map(x => x.sourceAsString)

// hit count
val totalCount = x.result.hits.total


推荐阅读