有哪些文本封面做的好的网站,网站开发计入什么费用,温州市城乡建设建档案馆网站,怎样注册公司邮箱账号在Elasticsearch中#xff0c;Parent Aggregation是一种特殊的单桶聚合#xff0c;用于选择具有指定类型的父文档#xff0c;这些类型是通过一个join字段定义的。以下是关于Parent Aggregation的详细介绍#xff1a;
1.基本概念
Parent Aggregation是一种聚合操作#x…在Elasticsearch中Parent Aggregation是一种特殊的单桶聚合用于选择具有指定类型的父文档这些类型是通过一个join字段定义的。以下是关于Parent Aggregation的详细介绍
1.基本概念
Parent Aggregation是一种聚合操作主要用于处理父-子关系的文档。通过这种聚合可以将子文档的聚合结果映射到父文档上从而实现跨文档类型的聚合。
2.应用场景
假设有一个索引其中包含问题question和答案answer两种类型的文档。answer文档通过join字段与question文档关联。通过Parent Aggregation可以将答案的聚合结果如答案的数量、答案的作者等映射到问题文档上。
3.配置方法
在使用Parent Aggregation时需要指定以下内容
• type指定子文档的类型。例如在问题和答案的场景中type应设置为answer。
• 子聚合可以在Parent Aggregation中嵌套其他聚合操作例如terms、avg等。
4.示例
以下是一个具体的例子展示如何使用Parent Aggregation将答案的作者聚合到问题的标签上
索引映射
json
PUT parent_example
{ mappings: { properties: { join: { type: join, relations: { question: answer } } } }
} 索引文档
json
PUT parent_example/_doc/1
{ join: { name: question }, body: I have Windows 2003 server and i bought a new Windows 2008 server..., title: Whats the best way to file transfer my site from server to a newer one?, tags: [ windows-server-2003, windows-server-2008, file-transfer ]
} PUT parent_example/_doc/2?routing1
{ join: { name: answer, parent: 1 }, owner: { location: Norfolk, United Kingdom, display_name: Sam, id: 48 }, body: Unfortunately youre pretty much limited to FTP..., creation_date: 2009-05-04T13:45:37.030
} 查询
json
POST parent_example/_search?size0
{ aggs: { top-names: { terms: { field: owner.display_name.keyword, size: 10 }, aggs: { to-questions: { parent: { type: answer }, aggs: { top-tags: { terms: { field: tags.keyword, size: 10 } } } } } } }
} 响应
json
{ aggregations: { top-names: { buckets: [ { key: Sam, doc_count: 1, to-questions: { doc_count: 1, top-tags: { buckets: [ { key: file-transfer, doc_count: 1 }, { key: windows-server-2003, doc_count: 1 }, { key: windows-server-2008, doc_count: 1 } ] } } } ] } }
} 5.注意事项
• Parent Aggregation依赖于join字段来定义父-子关系。
• 子聚合可以是任意类型的聚合操作但必须与父文档的类型兼容。
通过Parent Aggregation可以有效地将子文档的聚合结果映射到父文档上从而实现复杂的跨文档类型的聚合操作。