我查询elasticsearch嵌套字段,并在资源中只得到嵌套字段类别。这段代码适用于没有嵌套字段。
aggs: {
categories: {
nested: {
path: "categories"
},
aggs: {
category_name: {
terms: {
field: "categories.categoryId.keyword",
min_doc_count: 1,
size: 500,
order: {
_count: "desc"
},
},
aggs: {
product: {
top_hits: {
size: 1,
_source: {
include: [
"id", "assets", "categories"
]
}
}
}
}
}
}
}
}
1条答案
按热度按时间dly7yett1#
嵌套上下文无法访问父字段。需要使用reverse_nested aggregation。