value withFilter不是java.util.list的成员

时间:2018-04-13 13:15:12

标签: scala elasticsearch

for {
  bucket: Terms.Bucket <- topLevelBuckets
  aggResult = AggResult(bucket.getKeyAsString, bucket.getDocCount,
    bucket.getAggregations.get("total_usage").asInstanceOf[Sum].getValue)
} yield aggResult

}

case class AggResult(bucketKey: String, bucketCount: Long, bucketValue: Double)

//这里我想返回一个AggResult列表,但它显示我错误

/* Error:(113, 35) value withFilter is not a member of
java.util.List[org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket]
for {
  bucket: Terms.Bucket <-  topLevelBuckets
*/

/ * 这工作正常,但返回一个数组 * /

def extractAggResults_(client: TcpClient): Array[AggResult] = {

    val nestingAggregation = client.execute(aggQuery).await

    val topLevelBuckets = nestingAggregation.aggregations.termsResult("by_users").getBuckets
    topLevelBuckets.toArray() map(bucket =>  AggResult(bucket.asInstanceOf[Terms.Bucket].getKeyAsString, bucket.asInstanceOf[Terms.Bucket].getDocCount, bucket.asInstanceOf[Terms.Bucket].getAggregations.get("total_usage").asInstanceOf[Sum].getValue))
  }

1 个答案:

答案 0 :(得分:0)

请注意,不推荐使用JavaConversions(在评论中链接)。

使用

<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.1.0" />

如果您需要将Java deleteMethod :(NSString *) indexRecord { //Handle your local database deletion here } 传递给其他方法,请在结果上调用import scala.collection.JavaConverters._ for { bucket <- topLevelBuckets.asScala } yield AggResult(bucket.getKeyAsString, bucket.getDocCount, bucket.getAggregations.get("total_usage").asInstanceOf[Sum].getValue)

List.asJava是廉价的操作;它们只是创建简单的适配器对象而不复制所有元素,因为需要转换为Scala asJava