弹性搜索嵌套聚合 - 文档中的方法不起作用

Elastic search nested aggregations - method from documentation is not working

我是 ES 的新手,正在努力处理嵌套聚合。 这是我的虚拟数据对象([这是我的数据对象][1][1]:https://i.stack.imgur.com/X7oaM.png)。我只是想从 "modern" 字段中获取最低成本。

我已阅读以下关于我要解决的问题的帖子。 None 他们帮我解决了问题
- - https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html - https://madewithlove.be/elasticsearch-aggregations/ - https://iridakos.com/tutorials/2018/10/22/elasticsearch-bucket-aggregations.html - https://github.com/elastic/elasticsearch/issues/9317

此外,我已经在整个 Whosebug 上进行了搜索,但没有成功( 是的,我已经尝试了几乎所有遇到的解决方案,但都没有成功)。

根据文档和上述帖子及更多内容,嵌套聚合应 运行 如下:

GET /loquesea/_search
{
  "size": 0,
  "aggs": {
    "modern_costs": {
      "nested": {
        "path": "modern"
      },
      "aggs": {
        "min_cost": {
          "min": {
            "field": "modern.cost1"
          }
        }
      }
    }
  }
}

然而,完成后,这是我得到的:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 3,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "aggregations" : {
    "modern_costs" : {
      "doc_count" : 0
    }
  }
}

我花了几个小时试图使基本的嵌套聚合工作。我做错了什么?

问题已解决。事实证明,由于我没有在映射中将 "cars" 的类型声明为 "nested",因此嵌套聚合将不起作用。原因是在 Elastic Search 中,由于类型未声明为 "nested",ES 会将 "cars" 视为对象。