我正在尝试使用特殊键示例从弹性搜索中获取结果:
平均工资,按城市,性别
所以我检查了metrics_aggregations
我能够
AvgAggregationBuilder totalDuration = AggregationBuilders.avg("salaryAvg").field("salary");
它确实返回了最高水平 - 没有特定领域的平均工资
所以我尝试使用subAggregation
AvgAggregationBuilder totalDuration = AggregationBuilders
.avg("salaryAvg").field("salary")
.subAggregation(AggregationBuilders.terms("city").field("gender"));
但我得到以下错误
服务器错误。21525\nElasticsearchStatusException[Elasticsearch 异常 [type=aggregation_initialization_exception,reason=Aggregator [salaryAvg] 类型 [avg] 不能接受子聚合]]\n\tat org.elasticsearch.rest.BytesRestResponse.errorFromXConten
我如何使用弹性搜索查询它我想要的是与 SQL 非常相似的东西 - group by
我的弹性响应数据的每一行看起来都是这样的:
widgetResponse.getHits().getHits()[0].getSourceAsMap().get("attributes")
{HashMap$Node@53898} "city" -> "new York"
{HashMap$Node@53899} "pageId" -> "123"
{HashMap$Node@53900} "salary" -> "45765"
{HashMap$Node@53900} "gender" -> "female"
{HashMap$Node@53901} "userId" -> "324"
{HashMap$Node@53902} "accountId" -> "456"
widgetResponse.getHits().getHits()[1].getSourceAsMap().get("attributes")
{HashMap$Node@53898} "city" -> "new Jersy"
{HashMap$Node@53899} "pageId" -> "123"
{HashMap$Node@53899} "salary" -> "77777"
{HashMap$Node@53900} "gender" -> "female"
{HashMap$Node@53901} "userId" -> "334"
{HashMap$Node@53902} "accountId" -> "999"
如何使用 Elastic search JAVA API 支持它?
我也试过
运行它:
AvgAggregationBuilder totalDuration0 = AggregationBuilders.avg(TOTAL_DURATION_AVG).field(TOTAL_DURATION);
TermsAggregationBuilder totalDuration = AggregationBuilders.terms(TOTAL_DURATION_AVG)
.field(ATTRIBUTES_WIDGET_ID).subAggregation(totalDuration0);
我收到了这个回复
似乎有不同的平均值以及每个行的行数 - 此列表中的行但我不知道哪个“键”指向似乎是一个字节数组
但它与我拥有的实际密钥不匹配 [key] 似乎与不同的平均值重复,所以我在这里缺少什么。?