搜索结果正在快递途中

查询子文档,聚合子文档对应的父文档

Elasticsearch | 作者 hubiao | 发布于2020年01月28日 | 阅读数:1749

 
环境:windows 10 ,ES 7.5
需求:查询子文档,聚合子文档对应的父文档
故障:如下语句聚合统计父文档的都是为1
          假设我该查询出来有子文档有532多条数据,然后就8个分类(父文档),但聚合出来 的8个分类数量却是1
 
  

{
"from": 0,
"size": 0,
"query": {
"bool": {
"must": [
{
"has_parent": {
"parent_type": "myParent",
"score": true,
"query": {
"bool": {
"must": [
{
"term": {
"myfield": "6"
}
}
]
}
}
}
},
{
"term": {
"myField": "分类"
}
}
]
}
},
"aggs": {
"page": {
"parent": {
"type": "myChild"
},
"aggs": {
"tags": {
"terms": {
"script": "doc['_id'].value",
"size": 100
}
}
}
}
}
}
 
 
已邀请:

hubiao

赞同来自:

顶起来

laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net

赞同来自:

拆开阶段,先去掉聚合部分,看仅检索满足你的要求不? 
一点点核查原因及问题所在。

hubiao

赞同来自:

顶起来

要回复问题请先登录注册