Return multiple fields when performing aggregations

Hi all,

Is there a way to return other fields besides "key" and "doc_count" when performing aggregations? I don't want to do aggregation on multiple fields, I just want multiple fields to be returned in Aggregation results.

Below is my current setup, "attributes" is mapped as nested field.

I want to group by "searchid" as it is done now, but I also want the other fields inside "attributes" to be returned in the aggregation results, like "description.NL", "searchable", "public" etc.

Document looks like this

    {

        "id": "123990",
        "name": "Copy printer paper",
        "description": "Test product",
        "shortdescription": "",
        "keywords": "COPY,PRINTER",
        "keywords_custom": "",
        "attributes": [
            {
                "id": "ATTR_COLOR",
                "searchid": "attr_color",
                "description": {
                    "NL": "Product color"
                },
                "searchable": false,
                "public": false,
                "hidden": false,
                "type": "text",
                "textvalue": {
                    "NL": [
                        "WHITE"
                    ]
                }
            },
            {
                "id": "ATTR_FORMAT",
                "searchid": "attr_format",
                "description": {
                    "NL": "Product format"
                },
                "searchable": false,
                "public": false,
                "hidden": false,
                "type": "text",
                "textvalue": {
                    "NL": [
                        "A4"
                    ]
                }
            },
            {
                "id": "ATTR_PROMOTION",
                "searchid": "attr_promotion",
                "description": {
                    "NL": "Promotion"
                },
                "searchable": false,
                "public": false,
                "hidden": false,
                "type": "enum",
                "enumvalue": [
                    "N"
                ]
            }
        ]
    }

Query:

    "aggs":{
       "attributes":{
          "nested":{
             "path":"attributes"
          },
          "aggs":{
             "key":{
                "terms":{
                   "field":"attributes.searchid.keyword"
                },
                "aggs":{
                   "value":{
                      "terms":{
                         "field":"attributes.textvalue.NL.keyword"
                      }
                   }
                }
             }
          }
       }
    }

Current aggregation result:


    "attributes": {
        "doc_count": 10,
        "key": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 72,
            "buckets": [ {
                "key": "attr_color",
                "doc_count": 12,
                "value": {
                    "doc_count_error_upper_bound": 0,
                    "sum_other_doc_count": 0,
                    "buckets": [
                        {
                            "key": "WHITE",
                            "doc_count": 1
                        }
                    ]
                }
            },
            {
                "key": "attr_format",
                "doc_count": 12,
                "value": {
                    "doc_count_error_upper_bound": 0,
                    "sum_other_doc_count": 0,
                    "buckets": [{
                            "key": "A4",
                            "doc_count": 1
                        }
                    ]
                }
            }]
        }
    }

Aggregation result that I want:

 {
    "attributes": {
        "doc_count": 10,
        "key": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 72,
            "buckets": [ {
                "key": "attr_color",
                ++ "desription.NL": "Product color",
                ++ "searchable": false,
                ++ "public": false,
                ++ "hidden": false,
                "doc_count": 12,
                "value": {
                    "doc_count_error_upper_bound": 0,
                    "sum_other_doc_count": 0,
                    "buckets": [
                        {
                            "key": "WHITE",
                            "doc_count": 1
                        }
                    ]
                }
            },
        }
    }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.