我有一个嵌套聚合,只返回10个结果。我希望它返回1000个结果。但是,我不知道在哪里指定大小。我的映射看起来像(在YAML中但是被处理成json,不用担心)
mappings:
datainfo:
properties:
filterValues:
type: string
metadata:
properties:
isPrimary:
type: boolean
name:
index: not_analyzed
type: string
source:
enabled: false
type: object
type:
index: not_analyzed
type: string
val:
index: not_analyzed
type: string
type: nested
source:
enabled: false
type: object
title:
type: string
我的查询类似于
{
"query": "<some query>",
"aggs": {
"series": {
"nested": { "path": "metadata" },
"aggs": {
"val": {
"terms": { "field": "metadata.val" },
"aggs": {
"type": {
"terms": { "field": "metadata.name" }
}
}
}
}
}
}
}
我在哪里放置“大小”字段以使此返回X结果?它目前只返回10
答案 0 :(得分:0)
要指定查询结果的数量,您可以使用size, or size with range:
{
"query": "<some query>",
"size": 1000,
"aggs": {
"series": {
"nested": { "path": "metadata" },
"aggs": {
"val": {
"terms": { "field": "metadata.val" },
"aggs": {
"type": {
"terms": { "field": "metadata.name" }
}
}
}
}
}
}
}
要指定聚合存储桶上的结果数,可以使用Top Hits Aggregation(示例来自链接):
{
"aggs": {
"top-tags": {
"terms": {
"field": "tags",
"size": 3
},
"aggs": {
"top_tag_hits": {
"top_hits": {
"sort": [
{
"last_activity_date": {
"order": "desc"
}
}
],
"_source": {
"includes": [
"title"
]
},
"size" : 100
}
}
}
}
}
}
如果您只需要聚合结果,一种推荐的方法是为查询结果指定大小0,从而消除第一次获取并因此表现更好。