使用Elasticsearch php实现多个OR和and条件



我想用ElasticSearch实现以下查询:

product_shipper=1 AND((product_type=产品和价格>0(OR(product_type=产品变量和价格=0((

我已经构建了以下查询,但它不起作用,向我发送了一个空结果:

"query"=> [
"bool"=> [
"must"=> [
[
"bool"=> [
"should" => [
"bool"=> [
"must"=> [
[ "match" => [ "product_type" => "product" ] ],
[ 
'range'=>['price'=>['gt'=>0]]
],
]
],
"bool"=> [
"must"=> [
[ "match" => [ "product_type" => "product_variation" ] ],
[ "match" => [ "price" => 0 ] ]
]
]
]
]
],
[ 'match' => [ 'product_shipper' => $shipper ] ],
]
]
]

我做错了什么?

我在should子句级别的语法中遇到了一个小问题,这里是工作代码示例,希望它能帮助很多刚开始使用Elasticsearch的人。

"query"=> [
"bool"=> [
"must"=> [
[
"bool"=> [
"should" => [
[
"bool"=> [
"must"=> [
[ "match" => [ "product_type" => "product" ] ],
[ "range"=>['price'=>['gt'=>0]]],
]
],
],
[
"bool"=> [
"must"=> [
[ "match" => [ "product_type" => "product_variation" ] ],
['range'=>['price'=>['lte'=>0]]]
]
]
]
]
]
],
[
'match' => [ 'product_shipper' => $shipper ]
],
]
]
]

最新更新