从零开始实施推荐系统的落地部署——19.推荐系统案例(九)使用elasticsearch搭建一个电影推荐系统遇到的问题和解决方法

举报
wuyicom 发表于 2020/11/24 02:56:46 2020/11/24
【摘要】 1. 配置问题 1.1启动出现下面的情况:根据https://blog.csdn.net/qq_38636133/article/details/105621876,编辑 /etc/security/limits.conf,追加以下内容;* soft nofile 65536* hard nofile 65536此文件修改后需要重新登录用户,才会生效 1.2出现max v...

    1. 配置问题

    1.1启动出现下面的情况:

image.png

根据https://blog.csdn.net/qq_38636133/article/details/105621876

编辑 /etc/security/limits.conf,追加以下内容;

* soft nofile 65536

* hard nofile 65536

此文件修改后需要重新登录用户,才会生效

    1.2出现max virtual memory areas vm.maxmapcount [xxxxx] is too low

编辑 /etc/sysctl.conf

vm.max_map_count=262144

然后sysctl -p生效

    2.当有虚拟机安装pip install tmdbsimple是出现这种情况:

image.png

其他的虚拟机安装正常,根据正常的下载软件提示:

image.png

https://pypi.org/project/tmdbsimple/网站上找到Download files 下载tmdbsimple-2.6.6-py3-none-any.whl/opt/spark-elk/tmdbsimple-2.6.6-py3-none-any.whl。再使用pip install  /opt/spark-elk/tmdbsimple-2.6.6-py3-none-any.whl完成本地安装。

image.png

    3.运行oa = OriginArticleData()这个命令出现这种情况:

image.png

是因为我把elasticsearch-hadoop-7.6.2的关于spark相关的jar包都放进sparkjars目录里面,运行无法自动识别elasticsearch-spark-20_2.11-7.6.2.jar,导致出现异常。只需要把elasticsearch-hadoop-7.6.2elasticsearch-spark-20_2.11-7.6.2.jar在放进sparkjars目录里面,千万别放其他相关的sparkjar包就正常运行。

    4.https://github.com/IBM/elasticsearch-spark-recommender下载一个案例,运行的是elasticsearch7.1.0,使用代码创建索引:

# set the factor vector dimension for the recommendation model  设置推荐模型的因子向量维度

VECTOR_DIM = 20

 

create_ratings = {

    # this mapping definition sets up the fields for the rating events

    "mappings": {

        "properties": {

            "timestamp": {

                "type": "date"

            },

            "userId": {

                "type": "integer"

            },

            "movieId": {

                "type": "integer"

            },

            "rating": {

                "type": "double"

            }

        } 

    }

}

 

create_users = {

    # this mapping definition sets up the metadata fields for the users

    "mappings": {

        "properties": {

            "userId": {

                "type": "integer"

            },

            # the following fields define our model factor vectors and metadata

            "model_factor": {

                "type": "dense_vector",

                "dims" : VECTOR_DIM

            },

            "model_version": {

                "type": "keyword"

            },

            "model_timestamp": {

                "type": "date"

            }

        }

    }

}

能创建ratings的索引,在创建users出现下面的报错情况:

image.png

找了好久,也没有找到是什么原因,原本想在github上提交问题。看了https://github.com/IBM/elasticsearch-spark-recommender/issues/52,是关于Getting error in running code,虽然跟我这个问题没关系,但是作者的回答:Can you try the latest master branch with ES 7.6.x? 给我新的启发,打算更换elasticsearch7.6.2版本,运行elasticsearch7.6.2版本后,运行创建索引代码,能正常创建索引。

image.png

  

    5.出现下面的情况:

image.png

需要在所有hadoop服务器安装pip install tmdbsimple

   6. 运行ratings.write.format("es").save("ratings")出现下面情况:

image.png

image.png

之前以为是版本的问题,使用过spark2.2.2spark2.3.4spark2.4.5elasticsearch:7.6.2lasticsearch:7.9.1lasticsearch:7.10.0都测试过,还是这个问题。

image.png


再测试修改docker-compose.yml,在environment里添加- es_nodes_wan_only=true,运行docker-compose没有问题,但是在运行ratings.write.format("es").save("ratings")还是会出现这个问题。

image.png


接着在es添加es_nodes_wan_only=True的选项,在执行测试能打印出正确的相关信息,说明能远程连接elasticsearch。但是执行ratings.write.format("es").save("ratings")这个命令还是报错。最后这个命令添加option('es.nodes', '192.168.56.102')运行成功。能通过pyspark把数据写入到elasticsearch

image.png

如果想删除ratings 的索引及其数据,可以使用这个命令es.indices.delete(index="ratings")


image.png

    

    7.要在推荐演示中显示图像,需要访问 [The Movie Database API](https://www.themoviedb.org/documentation/api)按照[操作说明](https://developers.themoviedb.org/3/getting-started) 获取 API 密钥。但是因网络问题无法使用。

 

    通过这个电影的推荐系统的案例,学到如何使用pyspark如何把数据写入到Elasticsearch,通过搜索功能来查询相关数据。使用SparkALS来训练Elasticsearch的评分数据模型,将模型因子向量、模型版本和模型时间戳写入Elasticsearch。给定一部电影,使用此查询查找与之最相似的电影。或者给用户推荐一个使用该查询的最高级别的电影。


【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

举报
请填写举报理由
0/200