Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.4.0 Children aggregation returns empty buckets #8391

Closed
marekmalek opened this issue Nov 7, 2014 · 1 comment
Closed

1.4.0 Children aggregation returns empty buckets #8391

marekmalek opened this issue Nov 7, 2014 · 1 comment

Comments

@marekmalek
Copy link

I have been trying to test this feature with guide data as follow:

PUT /company
{
  "mappings": {
    "branch": {},
    "employee": {
      "_parent": {
        "type": "branch" 
      }
    }
  }
}

POST /company/branch/_bulk
{ "index": { "_id": "london" }}
{ "name": "London Westminster", "city": "London", "country": "UK" }
{ "index": { "_id": "liverpool" }}
{ "name": "Liverpool Central", "city": "Liverpool", "country": "UK" }
{ "index": { "_id": "paris" }}
{ "name": "Champs Élysées", "city": "Paris", "country": "France" }

POST /company/employee/_bulk
{ "index": { "_id": 2, "parent": "london" }}
{ "name": "Mark Thomas", "dob": "1982-05-16", "hobby": "diving" }
{ "index": { "_id": 3, "parent": "liverpool" }}
{ "name": "Barry Smith", "dob": "1979-04-01", "hobby": "hiking" }
{ "index": { "_id": 4, "parent": "paris" }}
{ "name": "Adrien Grand", "dob": "1987-05-11", "hobby": "horses" }

and execute the same query as here:
http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/children-agg.html

GET /company/branch/_search?search_type=count
{
  "aggs": {
    "country": {
      "terms": { 
        "field": "country"
      },
      "aggs": {
        "employees": {
          "children": { 
            "type": "employee"
          },
          "aggs": {
            "hobby": {
              "terms": { 
                "field": "hobby"
              }
            }
          }
        }
      }
    }
  }
}

A response is:

{
   "took": 87,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 3,
      "max_score": 0,
      "hits": []
   },
   "aggregations": {
      "country": {
         "doc_count_error_upper_bound": 0,
         "sum_other_doc_count": 0,
         "buckets": [
            {
               "key": "uk",
               "doc_count": 2,
               "employees": {
                  "doc_count": 2,
                  "hobby": {
                     "doc_count_error_upper_bound": 0,
                     "sum_other_doc_count": 0,
                     "buckets": []
                  }
               }
            },
            {
               "key": "france",
               "doc_count": 1,
               "employees": {
                  "doc_count": 1,
                  "hobby": {
                     "doc_count_error_upper_bound": 0,
                     "sum_other_doc_count": 0,
                     "buckets": []
                  }
               }
            }
         ]
      }
   }
}

As you can see countries are grouped correctly but buckets for hobbies are empty.

@clintongormley
Copy link
Contributor

Hi @marekmalek

This is a bug in field resolution: the branch in the URL sets the default type, so with hobby, it looks only for branch.hobby. If you change that to employee.hobby then it works correctly.

This bug will be fixed by #4081

I've updated the example in the guide to use employee.hobby. Thanks for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants