如何使用searchkick通过逻辑操作进行复杂查询 [英] How to do complex querying with logical operations by using searchkick

查看:169
本文介绍了如何使用searchkick通过逻辑操作进行复杂查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 searchkick 库作为Elasticsearch客户进行产品搜索. https://github.com/ankane/searchkick

Iam using searchkick library as an elasticsearch client for Product searching. https://github.com/ankane/searchkick

可以创建"OR"条件和"AND"条件;

It is possible to create 'OR' condition and 'AND' condition;

AND操作 Product.search其中:{price:{lte:200},in_stock:true}

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

或操作 Product.search其中:{或:[[[{in_stock:true},{backordered:true}]]}

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

但是Iam坚持使用searchkick创建多个"AND","OR" 条件.

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

我需要类似的东西

A OR B OR(C AND D)

A OR B OR ( C AND D )

或者我需要这样,

A AND B AND(C OR D)

A AND B AND ( C OR D )

请指导我,如何实现这一目标

Please guide me, how to achieve this

谢谢

推荐答案

A OR B OR(C AND D)

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)

A AND B AND ( C OR D )

Product.search where: {brand: 'nike', in-stock: true, or: [ [{price: {lte: 12}}, {color: 'red'}] ]}

更新

(A或B)AND(C或D)

(A OR B) AND (C OR D)

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

这篇关于如何使用searchkick通过逻辑操作进行复杂查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆