How to do complex querying with logical operations by using searchkick

被刻印的时光 ゝ 提交于 2020-01-01 05:30:08

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/27833849/how-to-do-complex-querying-with-logical-operations-by-using-searchkick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!