gpt4 book ai didi

mysql - 如何在eShop中使用ElasticSearch进行产品搜索(过滤)?

转载 作者:行者123 更新时间:2023-12-02 22:47:28 26 4
gpt4 key购买 nike

我是ElasticSearch的新手!
我有一个eShop(使用Laravel),具有超过1,000,000种产品,每种产品在product表中都有一些属性,例如名称,描述,价格... ...,以及其他表中的其他一些属性,例如categoriesoptionstagsaddressesratingbrands,...位于单独的表中,它们将通过many-to-many关系加入产品!
因此,我想非常快速,可靠地搜索带有许多过滤器的产品!像安宗!例如,用户将能够找到具有特殊类别,标签,选项...的产品!正如您现在在mysql中一样,我必须多次使用WHERE EXISTSINNER JOIN和...之类的东西,并且由于产品数量太大,因此这些查询非常昂贵且缓慢!因此我发现 flex 搜索可以解决这种情况!它喜欢处理大数据!
我已经读过了!现在我有一个主意,但我不确定这是正确的方法吗?
我说我们可以在laravel应用程序中的每个 UPDATE / STORE 事件上,将每个categoriesoptionstagsaddressesratingbrands作为json对象存储在 flex 搜索中!在mysql中,他们已经分离了表及其多对多关系!但是我们不必为它们(表)中的每一个都定义一个索引,并重复使用mysql的方式再次以 flex 方式连接它们!
在 flex 搜索中,我们将针对商品使用以下模式:

"id" : 782,
"title" : "dmorar",
"price" : "11000.00",
"options" : [ the ids of the product's tags ],
"categories" : [ the ids of the product's categories],
"tags" : [ the ids of the product's tags ],
"addresses" : [ the ids of the product's addresses]
这是一个例子:
  {
"_index" : "so_product",
"_type" : "_doc",
"_id" : "1099",
"_score" : 1.0,
"_source" : {
"id" : 782,
"title" : "dmorar",
"price" : "11000.00",
"created_at" : "2020-07-30T14:01:09.000000Z",
"updated_at" : "2020-07-30T14:01:09.000000Z",
"options" : [
75,
955,
480,
351,
285
],
"categories" : [
944,
421
],
"tags" : [
210,
198,
648,
976,
10,
553,
624,
967,
726,
121,
797
],
"addresses" : [
119,
43,
140,
1713,
855,
1515,
958
]
}
},
{
"_index" : "so_product",
"_type" : "_doc",
"_id" : "1344",
"_score" : 1.0,
"_source" : {
"id" : 429,
"title" : "ethyl.wehner",
"price" : "89000.00",
"created_at" : "2020-07-30T13:59:02.000000Z",
"updated_at" : "2020-07-30T13:59:02.000000Z",
"options" : [
121,
195,
348
],
"categories" : [
372,
315,
869,
544,
645,
803,
564
],
"tags" : [
347,
797
],
"addresses" : [
609,
1477,
187,
1479
]
}
},
{
"_index" : "so_product",
"_type" : "_doc",
"_id" : "1370",
"_score" : 1.0,
"_source" : {
"id" : 358,
"title" : "cicero.casper",
"price" : "67000.00",
"created_at" : "2020-07-30T13:58:37.000000Z",
"updated_at" : "2020-07-30T13:58:37.000000Z",
"options" : [
665,
28,
488,
384,
547,
877
],
"categories" : [
508,
201
],
"tags" : [
325,
472,
595,
797,
943,
948,
803,
136,
288,
275,
574,
390
],
"addresses" : [
691,
1637,
534,
770,
499,
1086,
430,
1365,
1325
]
}
}
通过这种方式购买,这样的搜索查询可以完全控制用户使用他想要的每个过滤器,而且速度很快:
GET so_product/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"options": 5
}
},
{
"term": {
"options": 695
}
} ,
{
"term": {
"categories": 523
}
}
,
{
"term": {
"addresses": 116
}
}
,
{
"term": {
"tags": 797
}
}
]
}
}
}
但是正如我之前所说,我不确定这是否正确吗?如果不正确,标准方法是什么?亚马逊如何实现此搜索过滤器?

最佳答案

您的ES模式是可以的,但是您可以通过用其实际值替换ID(例如标签ID,类别ID等)来改进它。通过这种方式,您可以根据输入的查询从ElasticSearch获取侧边栏过滤器和构面,而且与从MySQL中获取它们相比,可以更快地进行检索。
由于您使用的是Laravel,因此可以在产品创建,更新或向产品添加任何属性(例如类别,标签和...)时使用事件,以反射(reflect) flex 搜索的更改。

关于mysql - 如何在eShop中使用ElasticSearch进行产品搜索(过滤)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63204157/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com