elasticsearch - 在结果中具有相同属性的对象数组上的 Elasticsearch 聚合
问题描述
我有以下文档结构。
{"tagsData": [
{
"hashtag": "computer",
"displayName": "Computer",
"urlKeyword": "computer"
},
{
"hashtag": "artificialIntelligence",
"displayName": "Artificial Intelligence",
"urlKeyword": "artificial-intelligence"
}
]}
我的要求是在标签字段上应用聚合并获得如下结果
{"aggregations": {
"tags": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "computer",
"displayName": "Computer",
"urlKeyword": "computer"
"doc_count": 1
},
{
"key": "artificialIntelligence",
"displayName": "Artificial Intelligence",
"urlKeyword": "artificial-intelligence"
"doc_count": 1
}]}
}}
Elasticsearch 5.3 版请告诉我如何实现这一点?映射和查询应该是什么?
编辑
我正在尝试的映射。
{
"test": {
"properties" : {
"tagsData" : {
"type" : "object",
"properties": {
"hashtag" : {"type": "keyword", "index": "not_analyzed"},
"displayName" : {"type": "keyword", "index": "not_analyzed"},
"urlKeyword" : {"type": "keyword", "index": "not_analyzed"}
}
}
}
}
}
解决方案
推荐阅读
- python - 多线程逐行读取文件
- python - 为什么在检查点是否在多边形内时,patch.contains_point() 的行为与 patch.get_path().contains_point() 的行为不同?
- javascript - 在 Javascript 中循环提示直到满足条件
- wordpress - 如何将我保留的 ngrok pro 域与虚拟主机一起使用
- r - 使用 colorRampPalette 后如何将一种特定颜色分配给 phyloseq 对象中的特定分类群
- machine-learning - 任何改进神经网络对特征月的泛化的方法
- javascript - 使用 jQuery 填充下拉列表
- python - 如何在selenium python中循环文本文件中的每个项目
- javascript - 使用 select 自动填充多个表单域
- json-schema-validator - Json 模式验证器 - 验证未按预期工作