【发布时间】:2016-05-12 19:53:27
【问题描述】:
我在 mysql 中有一个条件查询,我想在 elasticsearch 查询中转换它:
查询:
我有带有价格范围搜索的产品列表页面。如果用户使用该搜索,我想检查产品是否有销售,那么它应该考虑销售价格或者销售价格。 (检查销售:我正在检查销售开始和销售结束日期之间的当前日期。)
MySql 查询:
SELECT *
FROM `product_sku`
WHERE
((sale_start < '2016-05-12 15:23:53' AND sale_end > '2016-05-12 15:23:53' AND sale_price between 600 AND 1800)
OR (sale_end < '2016-05-12 15:23:53' AND selling_price between 600 AND 1800)
)
Elasticsearch 查询:
$params = [
'index' => 'index',
'type' => 'product-list',
'body' => [
"query" => [
"filtered" => [
"query" => [
"match_all" => [],
],
'query' => $query,
"filter" => [
"nested" => [
"path" => "default_product_low_price_with_seller",
"filter" => [
"bool" => [
"should" => [
[
"range" => [
"default_product_low_price_with_seller.sale_price" => [
"gte" => $_GET['filter']['price']['from'],
"lte" => $_GET['filter']['price']['to'],
],
],
],
[
"range" => [
"default_product_low_price_with_seller.sale_end" => [
"gte" => $now,
],
],
],
[
"range" => [
"default_product_low_price_with_seller.sale_start" => [
"lte" => $now,
],
],
],
],
],
],
"filter" => [
"bool" => [
"should" => [
[
"range" => [
"default_product_low_price_with_seller.selling_price" => [
"gte" => $_GET['filter']['price']['from'],
"lte" => $_GET['filter']['price']['to'],
],
],
],
[
"range" => [
"default_product_low_price_with_seller.sale_end" => [
"lte" => $now,
],
],
],
[
"range" => [
"default_product_low_price_with_seller.sale_start" => [
"gte" => $now,
],
],
],
],
],
],
],
],
],
],
"aggs" => [
"brand_name" => ["terms" => ["field" => "brand_name"]],
"category_with_in_title" => [
"nested" => [
"path" => "category_with_in_title.parent_cat",
],
"aggs" => [
"category_with_in_title.title" => ["terms" => ["field" => "category_with_in_title.parent_cat.title"]],
],
],
],
],
];
【问题讨论】:
-
你的mysql查询在哪里?
-
我已经更新了我的问题......
标签: php laravel elasticsearch