基于Elasticsearch 为电商提供商品数据大数据查询

打印 上一主题 下一主题

主题 552|帖子 552|积分 1656

基于Elasticsearch 为电商提供商品数据大数据查询

前言

对于现代电商的产品,维度的多员花,与一套强大的搜索引擎,那是非常必要的。今天我们主要是描述我们在从事电商搜索引擎过程中的遇到的一些问题和经验分享。
过程

数据准备

1、我们准备为我们需要做查找的数据做好一张视图,方便我们分析数据查找维度,与查找场景需求。附加代码,对于Mysql 创建视图不清楚的,可以自行查找具体的文档了解,在我们完成视图创建后,我们就已经有了一张视图表,供我们数据使用。
  1. select `g`.`goods_id` AS `goods_id`,`g`.`publisher_sn` AS `publisher_sn`,`g`.`add_time` AS `add_time`,`g`.`last_update` AS `last_update`,`g`.`goods_name` AS `goods_name`,`g`.`fineness` AS `fineness`,`g`.`look` AS `look`,`g`.`cat_path` AS `cat_path`,`g`.`goods_number` AS `goods_number`,`g`.`shop_price` AS `shop_price`,`g`.`goods_weight` AS `weight`,`g`.`keywords` AS `keywords`,`g`.`goods_desc` AS `goods_desc`,`g`.`isbn` AS `isbn`,`a`.`attr_value` AS `author`,`b`.`attr_value` AS `publisher`,`c`.`attr_value` AS `yiname`,`m`.`age` AS `age`,`m`.`press_intro` AS `press_intro`,`m`.`author_info` AS `author_info`,`m`.`media_intro` AS `media_intro`,`m`.`catalog` AS `catalog`,`m`.`prologue` AS `prologue`,`m`.`selling_point_1` AS `selling_point_1`,`m`.`selling_point_2` AS `selling_point_2`,`m`.`selling_point_3` AS `selling_point_3`,`m`.`detail_intro_1` AS `detail_intro_1`,`m`.`detail_intro_2` AS `detail_intro_2`,`m`.`detail_intro_3` AS `detail_intro_3`,`m`.`wtao_intro` AS `wtao_intro`,`m`.`video_intro` AS `video_intro`,`co`.`positive` AS `positive`,`co`.`negative` AS `negative`,`s`.`name` AS `series_name`,`s`.`name_cn` AS `series_name_cn`,`v`.`title` AS `v_title`,`v`.`article` AS `v_article`,`k`.`bunch_no` AS `bunch_no` from ((((((((`sd_goods` `g` left join `sd_goods_attr` `c` on((`g`.`goods_id` = `c`.`goods_id`))) left join `sd_goods_attr` `a` on((`g`.`goods_id` = `a`.`goods_id`))) left join `sd_goods_attr` `b` on((`g`.`goods_id` = `b`.`goods_id`))) left join `sd_goods_more` `m` on((`g`.`goods_id` = `m`.`goods_id`))) left join `sd_cover_text` `co` on((`g`.`isbn` = `co`.`isbn`))) left join `sd_series_name` `s` on((`g`.`isbn` = `s`.`isbn`))) left join `nosql`.`video_words_result` `v` on((`g`.`isbn` = `v`.`isbn`))) left join `sd_bunch` `k` on((`g`.`isbn` = `k`.`isbn`))) where ((`c`.`attr_id` = 1) and (`a`.`attr_id` = 2) and (`b`.`attr_id` = 3))
复制代码

2、创建查询索引,在创建这块的时候,需要主要创建过程中的类型的选择,方便您在查询过程中可以应用的更准确与方便。
  1. PUT /products
  2. {
  3. "settings": {
  4.    "number_of_shards": 5,
  5.    "number_of_replicas": 1
  6. },
  7. "mappings": {
  8.      "properties": {
  9.        "goods_id":{
  10.          "type": "text"
  11.        },
  12.        "publisher_sn":{
  13.            "type": "text"
  14.        },
  15.        "goods_name": {
  16.            "type": "text",
  17.            "analyzer": "ik_smart"
  18.        },
  19.        "keywords": {
  20.            "type": "text",
  21.            "analyzer": "ik_smart"
  22.        },
  23.        "weight":{
  24.            "type":"keyword"
  25.        },
  26.        "goods_desc": {
  27.            "type": "text",
  28.            "analyzer": "ik_smart"
  29.        },
  30.        "author": {
  31.            "type": "text",
  32.            "analyzer": "ik_smart"
  33.        },
  34.        "publisher": {
  35.            "type": "text",
  36.            "analyzer": "ik_smart"
  37.        },
  38.        "yiname": {
  39.            "type": "text",
  40.            "analyzer": "ik_smart"
  41.        },
  42.        "fineness":{
  43.            "type": "text"
  44.        },
  45.        "look":{
  46.            "type": "text"
  47.        },
  48.        "isbn":{
  49.            "type": "text"
  50.        },
  51.        "age":{
  52.            "type": "text"
  53.        },
  54.        "press_intro": {
  55.            "type": "text",
  56.            "analyzer": "ik_smart"
  57.        },
  58.        "author_info": {
  59.            "type": "text",
  60.            "analyzer": "ik_smart"
  61.        },
  62.        "media_intro": {
  63.            "type": "text",
  64.            "analyzer": "ik_smart"
  65.        },
  66.        "positive": {
  67.            "type": "text",
  68.            "analyzer": "ik_smart"
  69.        },
  70.        "negative": {
  71.            "type": "text",
  72.            "analyzer": "ik_smart"
  73.        },
  74.        "series_name": {
  75.            "type": "text",
  76.            "analyzer": "ik_smart"
  77.        },
  78.        "series_name_cn": {
  79.            "type": "text",
  80.            "analyzer": "ik_smart"
  81.        },
  82.        "v_title":{
  83.            "type": "text",
  84.            "analyzer": "ik_smart"
  85.        },
  86.        "v_article":{
  87.            "type": "text",
  88.            "analyzer": "ik_smart"
  89.        }
  90.      }
  91. }
  92. }
复制代码
3、索引数据的添加,数据的添加方式更多的看具体的团队的情况,我们这边主要是使用Canal 来帮助我们完成数据的添加与新增数据的添加,在使用Canal的时候,需要有JAVA经验,会更好的解决一些同步过程中的问题。
4、对于未使用现成数据同步工具的,自己也是可以根据具体场景写Hook 来完成数据的添加,对于有不清楚的地方,可以联系我们了解。
5、对于 Elasticsearch 的部署搭建不熟悉的同步,可以参考我们的 Docker-composer 快速部署方式。
数据使用

数据查找应用,基于 SDK 查找, 对于 Query DSL 不熟悉的同步可以基于我们前面的 How to build a OR condition in Elasticsearch Query DSL 了解更多



免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

正序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

美食家大橙子

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表