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

前言

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

过程

数据准备

1、我们准备为我们需要做查找的数据做好一张视图,方便我们分析数据查找维度,与查找场景需求。附加代码,对于Mysql 创建视图不清楚的,可以自行查找具体的文档了解,在我们完成视图创建后,我们就已经有了一张视图表,供我们数据使用。


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、创建查询索引,在创建这块的时候,需要主要创建过程中的类型的选择,方便您在查询过程中可以应用的更准确与方便。

PUT /products{ "settings": {   "number_of_shards": 5,   "number_of_replicas": 1 }, "mappings": {     "properties": {       "goods_id":{         "type": "text"       },       "publisher_sn":{           "type": "text"       },       "goods_name": {           "type": "text",           "analyzer": "ik_smart"       },       "keywords": {           "type": "text",           "analyzer": "ik_smart"       },       "weight":{           "type":"keyword"       },       "goods_desc": {           "type": "text",           "analyzer": "ik_smart"       },       "author": {           "type": "text",           "analyzer": "ik_smart"       },       "publisher": {           "type": "text",           "analyzer": "ik_smart"       },       "yiname": {           "type": "text",           "analyzer": "ik_smart"       },       "fineness":{           "type": "text"       },       "look":{           "type": "text"       },       "isbn":{           "type": "text"       },       "age":{           "type": "text"       },       "press_intro": {           "type": "text",           "analyzer": "ik_smart"       },       "author_info": {           "type": "text",           "analyzer": "ik_smart"       },       "media_intro": {           "type": "text",           "analyzer": "ik_smart"       },       "positive": {           "type": "text",           "analyzer": "ik_smart"       },       "negative": {           "type": "text",           "analyzer": "ik_smart"       },       "series_name": {           "type": "text",           "analyzer": "ik_smart"       },       "series_name_cn": {           "type": "text",           "analyzer": "ik_smart"       },       "v_title":{           "type": "text",           "analyzer": "ik_smart"       },       "v_article":{           "type": "text",           "analyzer": "ik_smart"       }     } }}

3、索引数据的添加,数据的添加方式更多的看具体的团队的情况,我们这边主要是使用Canal 来帮助我们完成数据的添加与新增数据的添加,在使用Canal的时候,需要有JAVA经验,会更好的解决一些同步过程中的问题。

4、对于未使用现成数据同步工具的,自己也是可以根据具体场景写Hook 来完成数据的添加,对于有不清楚的地方,可以联系我们了解。

5、对于 Elasticsearch 的部署搭建不熟悉的同步,可以参考我们的 Docker-composer 快速部署方式。

Leave a Reply