Skip to content

[feature request] Parent aggregation #9705

@Kamapcuc

Description

@Kamapcuc

For example, I have data:

PUT test
PUT test/battle/_mapping
{
  "battle": {
    "_parent": {
      "type": "tank"
    }
  }
}

PUT test/tank/sherman
{"nation" : "usa"}

PUT test/tank/hellcat
{"nation" : "usa"}

PUT test/tank/panter
{"nation" : "germany"}

PUT test/battle/1?parent=sherman
PUT test/battle/2?parent=hellcat
PUT test/battle/3?parent=hellcat
PUT test/battle/4?parent=hellcat
PUT test/battle/5?parent=panter
PUT test/battle/6?parent=panter
{
  "date": "15.02.2015",
  "result": "win"
}

So, I played 4 battles on American tanks and 2 on German tanks. I want to receive those data, when searching for battles. But I can do it only when I search for tanks:

GET test/tank/_search
{
  "size": 0,
  "aggs": {
    "nation": {
      "terms": {
        "field": "nation"
      },
      "aggs": {
        "battles_count": {
          "children": {
            "type": "battle"
          }
        }
      }
    }
  }
}

Although, I can make such a monster:

GET replays/battle/_search
{
  "size": 0,
  "aggs": {
    "usa": {
      "filter": {
        "has_parent": {
          "parent_type": "tank",
          "query": {
            "term": {
              "nation": "usa"
            }
          }
        }
      },
      "aggs": {
        "count": {
          "value_count": {
            "field": "_id"
          }
        }
      }
    },
    "germany": {
      "filter": {
        "has_parent": {
          "parent_type": "tank",
          "query": {
            "term": {
              "nation": "germany"
            }
          }
        }
      },
      "aggs": {
        "count": {
          "value_count": {
            "field": "_id"
          }
        }
      }
    }
  }
}

But it's VERY uncomfortable and I must know all the terms of nation field. So, I'm asking for some kind of parent aggregation.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions