【发布时间】:2020-11-11 14:40:32
【问题描述】:
我有一个带有嵌套字段映射的“产品”索引。我通过嵌套对象的 id 执行嵌套聚合和术语聚合的搜索查询。如何从桶中的嵌套对象中获取“title”和“slug”属性?
PUT /products
{
"mappings": {
"properties": {
"categories": {
"type": "nested",
"properties": {
"id": { "type": "long" },
"title": { "type": "text" },
"slug": { "type": "keyword" }
}
}
}
}
}
POST /products/_doc
{
"name": "Acer Aspire 5 Slim Laptop",
"categories": [
{
"id": 1,
"title": "Laptops",
"slug": "/catalog/laptops"
},
{
"id": 2,
"title": "Ultrabooks",
"slug": "/catalog/ultrabooks"
}
]
}
GET /products/_search
{
"query": {
"match": { "name": "acer" }
},
"aggs": {
"categories": {
"nested": {
"path": "categories"
},
"aggs": {
"id": {"terms": {"field": "categories.id"}}
}
}
}
}
【问题讨论】:
标签: elasticsearch elasticsearch-aggregation elasticsearch-7