【发布时间】:2014-09-18 21:02:18
【问题描述】:
我正在使用嵌套映射(如下),它代表一个“任务”,并且有一个“请求”的嵌套元素正在朝着该任务取得进展。
我正在尝试查找所有尚未取得进展的任务,即嵌套对象上的“最大”聚合为空的所有文档。这需要能够过滤聚合的结果 - 这就是我有点卡住的地方。
我可以根据the aggregation 的结果订购。但我找不到过滤方法。 有这样的能力吗?
映射:
mapping = {
properties: {
'prefix' => {
type: "string",
store: true,
index: "not_analyzed"
},
'last_marker' => {
type: "string",
store: true,
index: "not_analyzed"
},
'start_time' => {
type: "date",
store: true,
index: "not_analyzed"
},
'end_time' => {
type: "date",
store: true,
index: "not_analyzed"
},
'obj_count' => {
type: "long",
store: true,
index: "not_analyzed"
},
'requests' => {
type: 'nested',
include_in_parent: true,
'properties' => {
'start_time' => {
type: "date",
store: true,
index: "not_analyzed"
},
'end_time' => {
type: "date",
store: true,
index: "not_analyzed"
},
'amz_req_id' => {
type: "string",
store: true,
index: "not_analyzed"
},
'last_marker' => {
type: "string",
store: true,
index: "not_analyzed"
}
}
}
}
}
按聚合查询排序(并寻找过滤器...):
{
"size":0,
"aggs": {
"pending_prefix": {
"terms": {
"field": "prefix",
"order": {"max_date": "asc"},
"size":20000
},
"aggs": {
"max_date": {
"max": {
"field": "requests.end_time"
}
}
}
}
}
}
【问题讨论】:
-
“嵌套对象上的“最大”聚合为空的文档是什么意思?为了让这个聚合给出空值,整个文档的 requests.end_time 字段是否需要为空?如果是这样,您不能搜索不包含字段 requests.end_time 的文档
-
尝试在映射中去掉
store: true(至少对于要聚合的字段)。我有同样的问题。由于某种原因,Elasticsearch 不会对映射中具有此标志的字段进行聚合。不要忘记在映射更改后重新索引您的数据
标签: elasticsearch filtering aggregation facet elasticsearch-aggregation