栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

深度嵌套类型的Elasticsearch聚合

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

深度嵌套类型的Elasticsearch聚合

它与先前的答案并没有真正的不同。您需要做的就是稍微修改字段名称,以考虑其他嵌套。除此之外,映射中无需进行任何更改。请注意,此查询无需映射更改就可以工作,因为

response
results
都是带有单个元素的数组,如果不是这种情况,它将涉及更多问题,并且需要映射更改和其他查询。

现在查询如下所示:

{  "size": 0,  "aggregations": {    "by_keyword": {      "terms": {        "field": "keyword"      },      "aggs": {        "prop_1_count": {          "nested": { "path": "response.results.items"          },          "aggs": { "prop_1": {   "terms": {     "field": "response.results.items.prop.item_property_1"   } }          }        }      }    }  }}

结果:

{  ...  "aggregations" : {    "by_keyword" : {      "doc_count_error_upper_bound" : 0,      "sum_other_doc_count" : 0,      "buckets" : [ {        "key" : "different keyword",        "doc_count" : 1,        "prop_1_count" : {          "doc_count" : 2,          "prop_1" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ {   "key" : "A",   "doc_count" : 1 }, {   "key" : "C",   "doc_count" : 1 } ]          }        }      }, {        "key" : "my keyword",        "doc_count" : 1,        "prop_1_count" : {          "doc_count" : 3,          "prop_1" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ {   "key" : "A",   "doc_count" : 2 }, {   "key" : "B",   "doc_count" : 1 } ]          }        }      } ]    }  }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375388.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号