Separation of hits returned from elastic by nested field value

I've index with products there. I'm trying to separate hits returned from elastic by nested field value. There's my shortened

  {
          "mapping": {
            "product": {
              "properties": {        
                "id": {
                  "type": "integer"
                },
                "model_name": {
                  "type": "text",          
                },
                "variants": {
                  "type": "nested",
                  "properties": {
                    "attributes": {
                      "type": "nested",
                      "properties": {
                        "id": {
                          "type": "integer"
                        },
                        "name": {
                          "type": "text"
                        },
                        "product_attribute_id": {
                          "type": "integer"
                        },               
                        "value": {
                          "type": "text"
                        }
                      }
                    },
                    "id": {
                      "type": "integer"
                    },
                    "product_id": {
                      "type": "integer"
                    }            
                  }
                }
              }
            }
          }
    }

And product example (there's is more variants and attributes in product - I just cut them off):

{
   "_index":"product_index",
   "_type":"product",
   "id":192,
   "model_name":"Some tshirt",
   "variants":[
      {
         "id":1271,
         "product_id":192,
         "attributes":[
            {
               "id":29,
               "name":"clothesSize",
               "value":"XL",
               "product_attribute_id":36740
            }
         ]
      },
      {
         "id":1272,
         "product_id":192,
         "attributes":[
            {
               "id":29,
               "name":"clothesSize",
               "value":"L",
               "product_attribute_id":36741
            }
         ]
      }
   ]
} 

The field in question is attribute id. Let's say I want to separate products by size attribute - id 29. It would be perfect if the response would look like:

"hits" : [
{
   "_index":"product_index",
   "_type":"product",
   "id":192,
   "model_name":"Some tshirt",
   "variants":[
      {
         "id":1271,
         "product_id":192,
         "attributes":[
            {
               "id":29,
               "name":"clothesSize",
               "value":"XL",
               "product_attribute_id":36740
            }
         ]
      }
   ]
},     
{
   "_index":"product_index",
   "_type":"product",
   "id":192,
   "model_name":"Some tshirt",
   "variants":[      
      {
         "id":1272,
         "product_id":192,
         "attributes":[
            {
               "id":29,
               "name":"clothesSize",
               "value":"L",
               "product_attribute_id":36741
            }
         ]
      }
   ]
}]

I thought about separate all variants in elastic request and then group them on application side by those attribute but i think it's not most elegant and above all, efficient way.
What are the elastic keywords that I should be interested in?
Thank you in advance for your help.

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