Creating a filter aggregation dynamically?
See original GitHub issueHello!
So Iām trying to create a query based on the amount of filter items selected. So the default filter for a specific list type looks like:
bodybuilder()
.aggregations('terms', 'listingType.keyword', 'Type')
.build()
Which works as expected. I have the aggregation bucket I need.
What If an item was selected? Iād want to add that filter to it.
This is what I want it to look like:
bodybuilder()
.addFilter('term', 'itemTypeId', 2)
.aggregations('terms', 'listingType.keyword', 'Type')
.build()
Or if multiple items were selected thenā¦
bodybuilder()
.addFilter('term', 'itemTypeId', id)
.addFilter('term', 'moo.keyword', moo)
.addFilter('term', 'make.keyword', make)
.aggregations('terms', 'listingType.keyword', 'Type')
.build()
I have an array of selected filters. I figured I could do something like:
const activeFilters = [{type: 'make.keyword, value: 'SAMSUNG'}, {type: 'moo.keyword', value: 'moo'}]
if (activeFilters) {
activeFilters.map(item => {
addFilter(item.type, item.value)
}
}
//OR
bodybuilder()
activeFilters.map(item => addFilter(item.type, item.value)
.aggregation('terms' , 'listingType.keyword', 'Type')
.build()
Something along those lines. Any recommendations?
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
How to dynamically add conditions or filters to aggregate ...
Hi, I would like to add or remove conditions or filters based on the input to the function. For ex, if a subcategory...
Read more >View filter effects on dynamic aggregation
View filter effects on dynamic aggregation. Dynamic aggregation occurs when an attribute is moved between the report layout and the Report Objects pane....
Read more >Elasticsearch Filter Dynamically Aggregated Fields
Save this question. Show activity on this post. I am trying to serach/filter results based on front-end selections in available acategories:
Read more >How to dynamically filter on Aggregate Values
I have got transactional data of names and prices. I like to create a filter on the names whose TOTAL PRICE is above...
Read more >Filter over dynamic nested fields with aggregation
I have products with dynamic attributes (filters). I need to get dynamically counts for each value for the filter according to the searchĀ ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
it would be
You should use
forEach
instead ofmap
. Map is really mutation iterator vs forEach which just loops through.ok np š