Elasticsearch php 的多个 OR 和 AND 条件
Multiple OR and AND conditions with Elasticsearch php
我想用 ElasticSearch 实现以下查询:
product_shipper = 1 AND ((product_type = 产品和价格>0) 或 (product_type = product_variation 和价格=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 ]
],
]
]
]
我想用 ElasticSearch 实现以下查询:
product_shipper = 1 AND ((product_type = 产品和价格>0) 或 (product_type = product_variation 和价格=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 ]
],
]
]
]