How to execute a complex query using logical operations using searchkick

Iam using the searchkick library as an elasticsearch client to search for a product. https://github.com/ankane/searchkick

You can create an OR condition and an AND condition;

And the operation Product.search, where: {price: {lte: 200}, in_stock: true}

OR operation Product.search where: {or: [[{in_stock: true}, {backordered: true}]]}

But Iam is stuck in creating multiple 'AND' 'OR' conditions with searchkick.

I need something like

A OR B OR (C AND D)

or do i need it

A AND B AND (C OR D)

Please tell us how to achieve this.

thanks

+5
source share
1 answer

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'}] ]} 

Refresh

(A OR B) AND (C OR D)

  Product.search where: {or: [[ {or: [[{brand: "nike"}, {in-stock: "true"}]]}], [{or: [[{price: 100}, {color: "red"}]]}]]} 
+15
source

Source: https://habr.com/ru/post/1210633/


All Articles