Iam using searchkick library as an elasticsearch client for Product searching. https://github.com/ankane/searchkick
It is possible to create 'OR' condition and 'AND' condition;
AND operation Product.search where: {price: {lte: 200}, in_stock: true}
OR operation Product.search where: {or: [[{in_stock: true}, {backordered: true}]]}
But Iam stuck with creating multiple 'AND' 'OR' conditions with searchkick.
I need something like
A OR B OR ( C AND D )
or I need like this,
A AND B AND ( C OR D )
Please guide me, how to achieve this
Thanks
How to write complex sql queries? 1.Use of Multiple AND OR operators : The queries which are using multiple AND OR operators are called as complex queries. 2.Use of subqueries and corelated subqueries : The subqueries are also the complex in nature. We require to use multiple... 3.Use of Joins The ...
I have tried to explain each and every query in detail so that everyone will get idea of how it is executed step-by-step. In SQL and PL SQL interviews we require to know the key and important complex sql queries in detail level. These are important Complex SQL Queries :
As you can see, we have a complex query and 2 rows in the result. Without any comments, we can’t easily say what does this query does and how it works. Let’s change that now.
Still, you can check it. I always advise that you test parts of your queries. While they won’t be displayed in the final results, they will be used in the background.
A OR B OR ( C AND D )
Product.search where: {or: [[{brand: 'nike'}, {in-stock: true}, {price: {lte: 12}, color: 'red'}]]}
A AND B AND ( C OR D )
Product.search where: {brand: 'nike', in-stock: true, or: [ [{price: {lte: 12}}, {color: 'red'}] ]}
Update
(A OR B) AND (C OR D)
Product.search where: {or: [[ {or: [[{brand: "nike"}, {in-stock: "true"}]]}], [{or: [[{price: 100}, {color: "red"}]]}]]}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With