Children aggregation broken in Elasticsearch 2.1?

六眼飞鱼酱① 提交于 2019-12-20 03:16:52

问题


In investigating the issue in this question I noticed what seems to be a bug in Elasticsearch 2.1.

Did I miss one of the breaking changes, or is this an actual bug?

With this setup:

PUT /test_index
{
    "mappings": {
        "parent_doc": {
            "properties": {
                "name": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "town": {
                    "type": "string",
                    "index": "not_analyzed"
                }
            }
        },
        "child_doc": {
            "_parent": {
               "type": "parent_doc"
            }, 
            "properties": {
                "name": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "age": {
                    "type": "integer"
                }
            }
        }
    }
}

POST /test_index/parent_doc/_bulk
{"index":{"_id":1}}
{"name":"Bob","town":"Memphis"}
{"index":{"_id":2}}
{"name":"Alice","town":"Chicago"}
{"index":{"_id":3}}
{"name":"Bill","town":"Chicago"}

POST /test_index/child_doc/_bulk
{"index":{"_id":3,"_parent":1}}
{"name":"Jill","age":5}
{"index":{"_id":4,"_parent":1}}
{"name":"Joey","age":3}
{"index":{"_id":5,"_parent":2}}
{"name":"John","age":2}
{"index":{"_id":6,"_parent":3}}
{"name":"Betty","age":6}
{"index":{"_id":7,"_parent":3}}
{"name":"Dan","age":1}

When I run the following query in ES 1.7.3, I get the expected result:

POST /test_index/parent_doc/_search
{
   "size": 0,
   "aggs": {
      "towns": {
         "terms": {
            "field": "town"
         },
         "aggs": {
            "parent_names": {
               "terms": {
                  "field": "name"
               },
               "aggs": {
                  "child_docs": {
                     "children": {
                        "type": "child_doc"
                     }
                  }
               }
            }
         }
      }
   }
}

result (ES 1.7.3):

{
   "took": 8,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 3,
      "max_score": 0,
      "hits": []
   },
   "aggregations": {
      "towns": {
         "doc_count_error_upper_bound": 0,
         "sum_other_doc_count": 0,
         "buckets": [
            {
               "key": "Chicago",
               "doc_count": 2,
               "parent_names": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                     {
                        "key": "Alice",
                        "doc_count": 1,
                        "child_docs": {
                           "doc_count": 1
                        }
                     },
                     {
                        "key": "Bill",
                        "doc_count": 1,
                        "child_docs": {
                           "doc_count": 2
                        }
                     }
                  ]
               }
            },
            {
               "key": "Memphis",
               "doc_count": 1,
               "parent_names": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                     {
                        "key": "Bob",
                        "doc_count": 1,
                        "child_docs": {
                           "doc_count": 2
                        }
                     }
                  ]
               }
            }
         ]
      }
   }
}

However, when I run the same code against ES 2.1.0, I get this:

{
   "took": 12,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 3,
      "max_score": 0,
      "hits": []
   },
   "aggregations": {
      "towns": {
         "doc_count_error_upper_bound": 0,
         "sum_other_doc_count": 0,
         "buckets": [
            {
               "key": "Chicago",
               "doc_count": 2,
               "parent_names": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                     {
                        "key": "Alice",
                        "doc_count": 1,
                        "child_docs": {
                           "doc_count": 0
                        }
                     },
                     {
                        "key": "Bill",
                        "doc_count": 1,
                        "child_docs": {
                           "doc_count": 0
                        }
                     }
                  ]
               }
            },
            {
               "key": "Memphis",
               "doc_count": 1,
               "parent_names": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                     {
                        "key": "Bob",
                        "doc_count": 1,
                        "child_docs": {
                           "doc_count": 0
                        }
                     }
                  ]
               }
            }
         ]
      }
   }
}

Here's the code I used:

http://sense.qbox.io/gist/70b2b39e6611a39480bd922804177e0e3d201f5a

来源:https://stackoverflow.com/questions/34072977/children-aggregation-broken-in-elasticsearch-2-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!