有人可以详细说明elasticsearch聚合中reverse_nested标签中的“路径”参数吗?我正在尝试使用不同嵌套级别的键来聚合嵌套桶。以下是详细信息:
使用以下映射创建索引
PUT agg
{
"mappings": {
"sample": {
"properties": {
"product": {
"type": "object",
"properties": {
"name": {
"type": "keyword"
},
"category": {
"type": "keyword"
}
}
},
"features": {
"type": "nested",
"properties": {
"color": {
"type": "keyword"
},
"details": {
"type": "text"
},
"finish": {
"type": "keyword"
}
}
}
}
}
}
}
在“agg”索引中索引一些文档:
POST _bulk
{ "index" : { "_index" : "agg", "_type" : "sample", "_id" : "1" } }
{"product":{"name":"tv","category":"electronics"},"features":[{"color":"black","details":"jet black in color"},{"finish":"matte"}]}
{ "index" : { "_index" : "agg", "_type" : "sample", "_id" : "2" } }
{"product":{"name":"tv","category":"electronics"},"features":[{"color":"black","details":"jet black in color"},{"finish":"glossy"}]}
{ "index" : { "_index" : "agg", "_type" : "sample", "_id" : "3" } }
{"product":{"name":"tv","category":"electronics"},"features":[{"color":"red","details":"apple red in color"},{"finish":"matte"}]}
{ "index" : { "_index" : "agg", "_type" : "sample", "_id" : "4" } }
{"product":{"name":"tv","category":"electronics"},"features":[{"color":"red","details":"blood red in color"},{"finish":"matte"}]}
以下聚合按预期工作:(颜色桶包含完成桶):
GET agg/_search
{
"size": 0,
"aggs": {
"root": {
"nested": {
"path": "features"
},
"aggs": {
"colors": {
"terms": {
"field": "features.color",
"size": 10
},
"aggs": {
"colorToFinish": {
"reverse_nested": {},
"aggs": {
"root": {
"nested": {
"path": "features"
},
"aggs": {
"finishes": {
"terms": {
"field": "features.finish",
"size": 10
}
}
}
}
}
}
}
}
}
}
}
}
但是,以下内容似乎无法按预期工作:
GET agg/_search
{
"size": 0,
"aggs": {
"root": {
"nested": {
"path": "features"
},
"aggs": {
"colors": {
"terms": {
"field": "features.color",
"size": 10
},
"aggs": {
"colorToFinish": {
"reverse_nested": {
"path": "features"
},
"aggs": {
"finishes": {
"terms": {
"field": "features.finish",
"size": 10
}
}
}
}
}
}
}
}
}
}
在非工作的 DSL 中,我试图摆脱对“功能”的嵌套,并再次深入以完成任务。这似乎并没有为“完成”收集桶。
但是,我们从第一个原则到根文档级别并获取字段的方法似乎有效。因此,似乎我没有正确使用 reverse_nested 中的“路径”参数,并且可能没有登陆正确的嵌套。有人知道为什么第二个查询不起作用吗?