我想在ElasticSearch 2.4中使用PipeLine聚合(Bucket Selector Aggregation)到嵌套字段聚合。我想做类似下面的事情,但我没有成功。如果可以在嵌套字段中进行PipeLine聚合,请指教我吗?
public class Cover {
private String url;
private String cloudinaryId;
private Integer width;
private Integer height;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getCloudinaryId() {
return cloudinaryId;
}
public void setCloudinaryId(String cloudinaryId) {
this.cloudinaryId = cloudinaryId;
}
public Integer getWidth() {
return width;
}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
}
答案 0 :(得分:1)
我找到了查询的解决方案。实际上,存储区选择器Aggregation应该与嵌套聚合并行,并且路径应该由'>'引用。如下图所示:
{
"size": 0,
"aggregations": {
"amount": {
"terms": {
"field": "countId",
"size": 0
},
"aggregations": {
"totalPaidAmount": {
"nested": {
"path": "count"
},
"aggregations": {
"paidAmountTotal": {
"sum": {
"field": "count.totalPaidAmount"
}
}
}
},
"paidAmount_filter": {
"bucket_selector": {
"script": {
"inline": "amount > 1000"
},
"buckets_path": {
"amount": "totalPaidAmount>paidAmountTotal"
}
}
}
}
}
}
}
答案 1 :(得分:-1)
您在params
值中缺少script
。所以,paidAmount_filter
应该是这样的:
"bucket_filter": {
"bucket_selector": {
"buckets_path": {
"amount ": "paidAmountTotal"
},
"script": "params.amount > 5000000"
}
}