Closed Hmastery closed 3 years ago
Are you sure you have formed your query right? Your 2 "bool" keys are at the same level so the last one will alway 'win'.
"should" => [
[
"bool"=> [
"must"=> [
[ "match" => [ "product_type" => "product" ] ],
[ "range"=>['price'=>['gt'=>0]]],
]
],
],
[
"bool"=> [
"must"=> [
[ "match" => [ "product_type" => "product_variation" ] ],
['range'=>['price'=>['lte'=>0]]]
]
]
]
]
I am not, but I posted this example on both stackoverflow, elasticsearch forum and this github and you're the first to mention that there might be an issue in its form. The documentation is pretty bad when it comes to not straightforward things, could you give me a hand so that I close this ticket ?
Thanks !!
On Wed, Jul 14, 2021 at 12:21 AM Gold @.***> wrote:
Are you sure you have formed your query right? Your 2 "bool" keys are at the same level so the last one will alway 'win'.
"should" => [ [ "bool"=> [ "must"=> [ [ "match" => [ "product_type" => "product" ] ], [ "range"=>['price'=>['gt'=>0]]], ] ], ], [ "bool"=> [ "must"=> [ [ "match" => [ "product_type" => "product_variation" ] ], ['range'=>['price'=>['lte'=>0]]] ] ] ] ]
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/elastic/elasticsearch-php/issues/1152#issuecomment-879444825, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGZP33HMPYGD45JJBW3OS3TXS36ZANCNFSM5AFUMTGQ .
The documentation is pretty bad when it comes to not straightforward
I've been struggling with this too. :/ Don't get me started on mapping. I can rant for ages on that... ;)
could you give me a hand so that I close this ticket ?
This is the edit above in the context of your query.
"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 ]
],
]
]
]
@Unifex Thank you very much man... Damn, they should put more complex examples like this one. An issue in one bracket and there is no error sent back, just weird search results.
Testing queries is a hell of a job ^^.
You rock!
This is one of the reasons I'm using https://github.com/ruflin/Elastica -> not necessary for accessing ES but I use it's builder capabilities, which can prevent the stupid errors I would otherwise also create more often 😄
Summary of problem or feature request
I would like to achieve the following query with ElasticSearch : product_shipper = $shipper AND ((product_type = product and price>0) OR (product_type = product_variation and price=0))
Code snippet of problem
So here is my query:
The issue is that the second bool/must overwrite the first one and the first one is ignored, if I revert there order the results change, in the pasted code I only have results where product_shipper = $shipper and product_type = product_variation and price > 0
System details