How to build a nested structure with Rails and ElasticSearch? -


i have feature model belongs_to featurekey , featurevalue.

featurekey#name => 'color' featurevalue#name => 'red' 

i generate nested aggregations structure build shopping cart filter (facet) navigation.

ideally, structure like

{ features: {   { key: color, values: [ red, blue, yellow ] },   { key: size, values: [ large, medium, small ]} }} 

can anyone suggest how can this?

what i'm using:

{       "size":1000,     "fields":[           "id",         "name",         "price"     ],     "query":{           "filtered":{               "filter":{                   "bool":{                       "must":[                           {                               "term":{                                   "categories":4838                             }                         }                     ]                 }             }         }     },     "aggs":{           "price":{               "stats":{                   "field":"price"             }         },         "discounted":{               "terms":{                   "field":"discounted"             }         },         "stock":{               "filter":{                   "range":{                       "stock":{                           "gt":0                     }                 }             }         },         "colour":{               "terms":{                   "field":"colour"             }         },         "size":{               "terms":{                   "field":"size"             }         }     } } 

add or remove aggregations wish. wish filter category, left in simplicity's sake.


Comments