elasticsearch—对嵌套字段进行聚合并对字段(从根)进行子聚合的弹性查询返回空的存储桶数组

yb3bgrhw  于 2021-06-10  发布在  ElasticSearch
关注(0)|答案(1)|浏览(418)

我编写了一个查询,其中一个聚合在嵌套字段上,另一个子聚合在未嵌套但在根中的字段上。我本想为每个ownerid得到一个和,但是我得到了一个空的bucket数组。
下面的查询返回一个空的bucket数组-尽管有结果和正和。

GET my-index/_search
{
  "size": 0,
  "aggs": {
    "agg_owner": {
      "nested": {
        "path": "owner_fields"
      },
      "aggs": {
        "raw_names": {
          "terms": {
            "field": "owner_fields.id.keyword",
            "size": 10
          },
          "aggs": {
            "total_amount": {
              "reverse_nested": {},
              "aggs": {
                "total_inner_amount": {
                  "terms": {
                    "field": "amount",
                    "size": 10
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

退货:

{
  "took" : 4,
  "timed_out" : false,
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 45430,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "aggregations" : {
    "agg_owner" : {
      "doc_count" : 15494,
      "raw_names" : {
        "doc_count_error_upper_bound" : 0,
        "sum_other_doc_count" : 0,
        "buckets" : [ ]
      }
    }
  }
}

我希望每个ownerid都能得到一笔钱,但那没有发生。

yh2wf1be

yh2wf1be1#

必须从聚合中删除关键字:“owner\u fields.id.keyword”=>“owner\u fields.id”

相关问题