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

Within a sub-aggregation of a reverse_nested aggregation, cannot filter on nested fields #6994

Closed
lmeck opened this issue Jul 23, 2014 · 2 comments

Comments

@lmeck
Copy link

commented Jul 23, 2014

I'm unsure if this is a bug or something that wasn't intended to work. In the example below, I'm trying to find the 'foo' object that has the nested 'bar' object named 'bar0'. I then want to know how many nested 'baz' objects the 'foo' contains. After using reverse_nested I can use the first-level fields of 'foo0', but not the nested fields.

Using my actual data this sometimes did work, which is why I thought there might be a bug here. So for example two root objects would contain a certain nested object ('bar'), but only one was returning a proper count of another nested object (baz). With my example I wasn't able to recreate this.

DELETE /_all

PUT /foos

PUT /foos/foo/_mapping
{
  "foo": {
    "properties": {
      "bar": {
        "type": "nested",
        "properties": {
          "name": {
            "type": "string"
          }
        }
      },
      "baz": {
        "type": "nested",
        "properties": {
          "name": {
            "type": "string"
          }
        }
      },
      "name": {
        "type": "string"
      }
    }
  }
}

PUT /foos/foo/0
{
  "bar": [
    {
      "name": "bar0"
    },
    {
      "name": "bar1"
    }
  ],
  "baz": [
    {
      "name": "baz0"
    },
    {
      "name": "baz1"
    }
  ],
  "name": "foo0"
}
PUT /foos/foo/1
{
  "bar": [
    {
      "name": "bar2"
    },
    {
      "name": "bar3"
    }
  ],
  "baz": [
    {
      "name": "baz2"
    },
    {
      "name": "baz3"
    }
  ],
  "name": "foo1"
}

#this should give a count of 2 under baz, but it's 0 instead

POST /foos/foo/_search?pretty
{
  "size": 0,
  "aggs": {
    "bar": {
      "nested": {
        "path": "bar"
      },
      "aggs": {
        "bar_filter": {
          "filter": {
            "bool": {
              "must": {
                "term": {
                  "bar.name": "bar0"
                }
              }
            }
          },
          "aggs": {
            "foo": {
              "reverse_nested": {},
              "aggs": {
                "name": {
                  "terms": {
                    "field": "name"
                  },
                  "aggs": {
                    "baz": {
                      "nested": {
                        "path": "baz"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

# this works and give the right number of baz
POST /foos/foo/_search?pretty
{
  "size": 0,
  "aggs": {
    "foo_filter": {
      "filter": {
        "bool": {
          "must": {
            "term": {
              "name": "foo0"
            }
          }
        }
      },
      "aggs": {
        "baz": {
          "nested": {
            "path": "baz"
          }
        }
      }
    }
  }
}
@clintongormley

This comment has been minimized.

Copy link
Member

commented Jul 24, 2014

@martijnvg I've confirmed this behaviour - looks like a bug to me.

@martijnvg

This comment has been minimized.

Copy link
Member

commented Jul 27, 2014

@lmeck @clintongormley This is indeed a bug. I opened #7048 for this.

martijnvg added a commit that referenced this issue Jul 28, 2014
…of the closest `reverse_nested` aggregator.

Closes #6994
Closes #7048
martijnvg added a commit that referenced this issue Jul 28, 2014
…of the closest `reverse_nested` aggregator.

Closes #6994
Closes #7048
@martijnvg martijnvg closed this in 2e9ee5c Jul 28, 2014
mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.