在Elasticsearch 2.1中破坏了儿童聚合?

时间:2015-12-03 17:56:09

标签: elasticsearch elasticsearch-2.0

在调查this question中的问题时,我注意到Elasticsearch 2.1中的错误似乎是什么。

我是否错过了其中一个重大变化,或者这是一个真正的错误?

使用此设置:

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}

当我在ES 1.7.3中运行以下查询时,我得到了预期的结果:

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"
                     }
                  }
               }
            }
         }
      }
   }
}

结果(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
                        }
                     }
                  ]
               }
            }
         ]
      }
   }
}

然而,当我针对ES 2.1.0运行相同的代码时,我得到了这个:

{
   "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
                        }
                     }
                  ]
               }
            }
         ]
      }
   }
}

这是我使用的代码:

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

0 个答案:

没有答案