我正在使用 laravel 4.2、mongodb 和 elasticsearch。下面是一个工作代码,我正在尝试将此高级 where 查询转换为 elasticsearch 查询:
$products = Product::where(function ($query) {
$query->where (function($subquery1){
$subquery1->where('status', '=', 'discontinued')->where('inventory', '>', 0);
});
$query->orWhere (function($subquery2){
$subquery2->where('status', '<>', 'discontinued');
});
})->get();
到目前为止,我所能得到的只是退回停产的产品,下面的代码有效,但这不是我需要的:
$must = [
['bool' =>
['should' =>
['term' =>
['status' => 'discontinued']
]
]
]
];
你能告诉我如何在弹性搜索中实现我上面第一次描述的相同查询吗?我想退回discontinued
带有 的产品inventory
,然后也退回带有 的产品not equal to discontinued
。