说我有一个父文件

curl -XPUT es-host:9200/index/parent_type/1 -d '{

  "foo": "bar"
}'

我有一个 child 证件
curl -XPUT es-host:9200/index/child_type/?parent=1 -d '{

  "child-foo-1": "child-bar-1",
  "child-foo-2": "child-bar-2"
}'

有什么办法可以在父文档聚合下获取我的子文档数据的子聚合,例如,
{
  "aggregations": {

    "foo-aggregations": {

      "buckets": [
        {
          "key": "bar",
          "doc_count": 1,
          "child-foo-1-aggregations": {

            "key": "child-bar-1",
            "doc_count": 1
          },
          "child-foo-2-aggregations": {

            "key": "child-bar-2",
            "doc_count": 1
          }
        }
      ]
    }
  }
}

最佳答案

curl -XPOST 'localhost:9200/index/parent/_search?pretty' -d '
{
  "size": "0",
    "aggs" : {
        "name" : {
            "terms" : {
                "field": "name.keyword"
            },
              "aggs" : {
                    "child_category": {
                        "children" : {
                            "type": "child_type_name"
                        },
                        "aggs" : {
                            "data" : {
                                "terms" : {
                                    "field": "child_field_text.keyword"
                                }

                            }
                        }
                    }
              }
        }
    }
}'

关于elasticsearch - Elasticsearch中子文档的子集合?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24078843/

10-10 18:36