Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searchkick aggregations

I have the following two aggregations in Rails using searchkick gem. When I used any of them separately, it works like a charm. But I want to "merge" them together and cannot figure out how to do it :(.

Aggregation 1:

aggs: { price_vat: { ranges: [{to: 5}, {from: 5, to: 10}, {from: 10}] } }

Aggregation 2:

aggs: ['property_options.property_id', 'property_options.id', 'property_options.value_cs', 'property_options.value_en', 'manufacturer_id'] 

Is there any expert on this who knows how to do it? Really appreciated. Thank you and have a good weekend, Miro.

like image 983
Miroslav Avatar asked Sep 02 '26 14:09

Miroslav


1 Answers

you have to the define the "aggs" as hashes. Then you can easily merge them together.

example:

range_aggregations = { price_vat: { ranges: [{to: 5}, {from: 5, to: 10}, {from: 10}] } }
base_aggregations = {
   property_options.property_id: {},
   property_options.id: {}
}

Now merge them togehter:

range_aggregations.merge(base_aggregations)
like image 159
timtomaschoff Avatar answered Sep 04 '26 15:09

timtomaschoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!