我正在尝试获取以下Elasticsearch查询的结果。我得到了如下所示的响应。现在,我想根据点击率最高的文档字段“源”来选择存储桶。
POST /data/_search?size=0{
"aggs":{
"by_partyIds":{
"terms":{
"field":"id.keyword"
},"aggs":{
"oldest_record":{
"top_hits":{
"sort":[
{
"createdate.keyword":{
"order":"asc"
}
}
],"_source":[
"source"
],"size":1
}
}
}
}
}
}
响应:
{
"aggregations": {
"by_partyIds": {
"doc_count_error_upper_bound": 0,"sum_other_doc_count": 0,"buckets": [
{
"key": "1","doc_count": 3,"oldest_record": {
"hits": {
"total": 3,"max_score": null,"hits": [
{
"_index": "data","_type": "osr","_id": "DcagSm4B9Wnm0Ke-MgGk","_score": null,"_source": {
"source": "US"
},"sort": [
"20-09-18 05:45:26.000000000AM"
]
}
]
}
}
},{
"key": "2","_id": "7caiSm4B9Wnm0Ke-HwGx","_source": {
"source": "UK"
},"sort": [
"22-09-18 05:45:26.000000000AM"
]
}
]
}
}
}
]
}
}
}
现在我想获得以美国为来源的水桶。我们可以为此编写查询吗?我尝试了桶聚合,它是父管道聚合,它执行一个脚本,该脚本确定当前桶是否将保留在父多桶聚合中。指定的指标必须为数字,并且脚本必须返回布尔值。如果脚本语言是表达式,则允许使用数字返回值。在这种情况下,0.0将被评估为false,所有其他值将被评估为true。