美文网首页
ElasticSearch+egg打造搜房网

ElasticSearch+egg打造搜房网

作者: LeeYaMaster | 来源:发表于2021-03-26 10:49 被阅读0次
    使用技术:

    ElasticSearch搜索引擎+Kibana+Nginx负载均衡+Python爬虫+Redis实现热搜+Jquery实现Vue模版+Egg

    使用方法:
    1. 将Mysql的数据导入ElasticSearch
    2. 运行ElasticSearch
    3. 使用egg(主要是有链接ElasticSearch的架包,注意包的版本要和ES的版本对应)
    4. 前端使用Nginx,主要是为了跨域。
      不足:egg的ES部分增删查改那些因为加班的原因还未实现。
    参考文档:

    https://blog.csdn.net/Tyro_java/article/details/106565440

    参照视频:

    https://www.itying.com/goods-941.html

    码云地址:

    https://gitee.com/leeyamaster/room

    项目效果
    首页
    详情页
    ElasticSearch页面
    Mysql页面
    核心代码:

    配置文件:

    module.exports = appInfo => {
        const config = exports = {};
        config.keys = appInfo.name + '_1587648814940_7499';
        config.middleware = [];
        exports.elasticsearch = {
            host: 'localhost:9200',
            apiVersion: '6.6'
        };
        return config;
    };
    

    核心请求:

    async index() {
            const {
                ctx
            } = this;
            const req = ctx.request.body;
            ctx.body = req;return;
            var client = new elasticsearch.Client({
                host: 'localhost:9200',
                log: 'trace'
            })
            const result = await client.search({
                index: 'index',
                type: 'room',
                body: {
                    query: {
                        match: {
                            address: '青羊'
                        }
                    }
                }
            })
            ctx.body = result;
        }
    

    相关文章

      网友评论

          本文标题:ElasticSearch+egg打造搜房网

          本文链接:https://www.haomeiwen.com/subject/jxhjhltx.html