Aggregations over similarly-structured objects but in different paths

Hi fellows

I am looking for a possibility to perform a terms aggregation over two (or more?) similarly structured objects in different path at which I am interested in two attributes each. (Related: Facets resulting in objects instead of primitive types)

For example, I have something like this:

{"car": {
    "front": {
      "color": {
        "code": "123",
        "text": "blue"
      }    },
    "back": {
      "color": {
        "code": "321",
        "text": "green"  }} }}

I also have an aggregation (with subaggregation; not shown here) at hand that returns all available color.code/text combinations....for either "car.front" or "car.back" but not both! :frowning:
What I want to have is a terms aggregations with the following semantics "Aggregate all colors (with code and text) of all cars no matter which part of the car the color is on".

I'd love to have it as follows but unfortunately asterisks are not working with the "field" property.

{
    "aggs" : {
        "colorCodes" : {
            "terms" : { "field" : "*.color.code" }
        }, agg .... --> subaggregation for *.color.text not shown here
    }
}

As suggested in the documentation so-called "multi-field terms" are not possible. A workaround is to introduce a copy_to field in the mapping and collect (for the example above) both color codes in one field. Well, I am always interested in the related text as well.

Is there a convenient way to solve this or do I have to do some tricky hack?

Thanks in advance for your suggestions.

Stefan

hello @sjtuner, i never seen a wildcard in aggregations, the only idea that i have is maybe change a little the structure of your data. for car have two different nested object, in each object you have par example position : "front" or "back" , the color and text. after in your aggregation you will have the data mixed for the color and with a sub-aggregation you can separate/know if is front our back.

{
    "car": [
        {
            "position": "front",
            "color_code": "123",
            "color_text": "blue"
        },
        {
            "position": "back",
            "color_code": "321",
            "color_text": "green"
        }
    ]
}

and also put all the data at the same level to avoid reverse_nested

Hi @Camilo_Sierra,

thanks for the idea! I have think that through but at the first glance it sounds like a real option.

Best regards, Stefan