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

Children aggregation for recursive parent-child relation leads to incorrect results #8100

Closed
whiter4bbit opened this issue Oct 15, 2014 · 7 comments
Assignees

Comments

@whiter4bbit
Copy link

Hi,

I tried to create recursive parent-child relation:

family-mapping.json:

{
  "mappings": {
    "member": {
      "_parent": {
        "type": "member" 
      },
      "properties" : { 
        "name" : {
          "type" : "string",
          "index" : "not_analyzed"
        }
      }
    }
  }
}

family.json:

{ "index" : { "_id" : "1", "parent" : "0" } }
{ "name" : "Abraham Simpson" }
{ "index" : { "_id" : "2", "parent" : "1" } }
{ "name" : "Homer J Simpson" }
{ "index" : { "_id" : "3", "parent" : "2" } }
{ "name" : "Bart Simpson" }

aggregation.json:

{
  "aggs" : {
    "parent" : {
       "terms" : { "field" : "name" },
       "aggs" : {
          "child-members" : {
             "children" : { "type" : "member" },
             "aggs" : {
               "child-names" : {
                 "terms" : { "field" : "name" }
               }
             }
          }
       }
    }
  }
}

When I'm trying to aggregate this data I'm getting child buckets inside parent ones with same name:

.....
  "aggregations" : {
    "parent" : {
      "doc_count_error_upper_bound" : 0,
      "buckets" : [ {
        "key" : "Abraham Simpson",
        "doc_count" : 1,
        "child-members" : {
          "doc_count" : 1,
          "child-names" : {
            "doc_count_error_upper_bound" : 0,
            "buckets" : [ {
              "key" : "Abraham Simpson",
              "doc_count" : 1
            } ]
          }
        }
      }, {
        "key" : "Bart Simpson",
        "doc_count" : 1,
        "child-members" : {
          "doc_count" : 1,
          "child-names" : {
            "doc_count_error_upper_bound" : 0,
            "buckets" : [ {
              "key" : "Bart Simpson",
              "doc_count" : 1
            } ]
          }
        }
      }, {
        "key" : "Homer J Simpson",
        "doc_count" : 1,
        "child-members" : {
          "doc_count" : 1,
          "child-names" : {
            "doc_count_error_upper_bound" : 0,
            "buckets" : [ {
              "key" : "Homer J Simpson",
              "doc_count" : 1
            } ]
          }
        }
      } ]
    }
  }
}

I'm using 1.4.0-beta1 version (downloaded from elasticsearch.org).

@clintongormley
Copy link
Contributor

@martijnvg I've assigned this to you. I didn't think we supported recursive p/c mappings?

@martijnvg
Copy link
Member

@clintongormley In general in parent/child we never explicitly supported it, but I think we should. This kind of usage works for the has_child query, but not for the has_parent query (#7357) and children agg.

@gmenegatti
Copy link

+1

@rieder91
Copy link

is there any known workaround?

@brendangibat
Copy link

+1

@ArkeologeN
Copy link

+1 - I also need parent / child mapping for nested categories pattern which I'm importing through river from MySQL.

@martijnvg
Copy link
Member

Closing in favour for #11432.

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

7 participants