0

我想用 ElasticSearch 实现以下查询:

product_shipper = 1 AND ((product_type = product and price>0) OR (product_type = product_variation and price=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 ] ],
                     ]
                  ]
               ]

我究竟做错了什么?

4

1 回答 1

0

我在 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 ]
        ],
    ]
]
]
于 2021-07-14T08:39:22.770 回答