Static filters in ReactiveSearch
Clash Royale CLAN TAG#URR8PPP
Static filters in ReactiveSearch
In my application I'm using the excellent ReactiveSearch.
There are some constants which need to be filtered on every query. For example, to pass a list of ids which would always be filtered and then the user's filtering applied over the top.
There is a similar question here, but this is focused more on removing fields.
How can a pass an array of IDs to be filtered against a specific field in ElasticSearch? I'm happy to use any kind of hacky approach, such as making a custom component to house the IDs, and then hiding it with CSS, but if there is a cleaner approach please let me know.
1 Answer
1
One of the ways of solving this is using the prop defaultQuery
in your result component. For example, ReactiveList
supports this prop (docs). You can use this to run any query of your choice that would get applied along with other queries. For example:
defaultQuery
ReactiveList
<ReactiveList
...
defaultQuery=() => (
bool:
must_not:
term:
"original_title.raw": "The Last Guardian"
)
/>
This would filter out all the original_title.raw
fields matching The Last Guardian
. See demo.
original_title.raw
The Last Guardian
Absolutely perfect, thank you very much!
– ardochhigh
Aug 13 at 9:23
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Not sure of reactivesearch but in elasticsearch you can use terms query inside a filter clause to achieve this.
– Technocrat Sid
Aug 13 at 3:30