• 基于ElasticSearch+Vue实现简易搜索


    基于ElasticSearch+Vue实现简易搜索

    一、模拟数据

    产品名称描述价格库存数量品牌名称
    智能手表智能手表,具有健康跟踪和通知功能。199.991000TechWatch
    4K智能电视4K分辨率智能电视,提供出色的画质。699.99500VisionTech
    无线耳机降噪无线耳机,提供高品质音频体验。149.99800AudioMasters
    笔记本电脑高性能笔记本电脑,配备快速处理器。999.99300TechLaptops
    数码相机高分辨率数码相机,支持多种拍摄模式。449.99200PhotoPro
    便携式充电器便携式充电器,为移动设备提供电力。29.992000PowerBoost
    无线路由器高速无线路由器,适用于大型网络。79.99400NetSpeed
    游戏机游戏机,支持多种游戏和娱乐功能。399.99100GameZone
    手机壳手机壳,适用于各种手机型号。19.991500PhoneGuard
    运动鞋高性能运动鞋,适用于各种运动。79.99800SportsTech
    4K超高清显示器4K超高清显示器,提供卓越的图像质量。599.99150UltraView
    智能家居设备智能家居设备,实现智能化家居控制。249.99300SmartLiving

    二、python导入脚本

    # coding=gbk
    import pandas as pd
    from elasticsearch import Elasticsearch
    from elasticsearch.helpers import streaming_bulk
    
    # 连接到Elasticsearch
    es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
    
    # 检查是否成功连接
    if es.ping():
        print("Connected to Elasticsearch")
    else:
        print("Failed to connect to Elasticsearch")
    
    # 读取Excel文件
    data = pd.read_excel('demoData.xls')
    
    # 将DataFrame转换为字典格式
    documents = data.to_dict(orient='records')
    
    # 逐个文档导入数据到Elasticsearch
    success, failed = 0, 0
    total_documents = len(documents)
    for doc in documents:
        index_action = {
            '_index': 'ecommerce',  # 修改为你的索引名称
            '_id': doc['产品名称'],  # 使用产品名称作为文档ID
            '_source': doc
        }
        try:
            result = next(streaming_bulk(es, [index_action], index=index_action['_index']))
            success += 1
        except Exception as e:
            print(f"Failed to index document {index_action['_id']}: {e}")
            failed += 1
    
    print(f'Successfully indexed {success} documents, failed to index {failed} documents.')
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    三、vue代码

    
    
    
    
      
      
      
      
    
    
    
      

    基于ElasticSearch+Vue实现简易搜索




    产品名称: {{ result.productName }}
    描述: {{ result.productDescription }}
    价格: {{ result.productPrice }}
    库存数量: {{ result.productStock }}
    品牌名称: {{ result.productBrand }}
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132

    四、效果图

    在这里插入图片描述
    在这里插入图片描述

  • 相关阅读:
    实现声明式锁,支持分布式锁自定义锁、SpEL和结合事务
    python虚拟环境创建问题:You will need to adjust your conda configuration to proceed.
    【每日一题】买卖股票的最佳时机 III
    Docker部署深度学习模型
    修改hosts 不生效? 三种方法解决
    文心一言 VS 讯飞星火 VS chatgpt (137)-- 算法导论11.3 3题
    优雅的操作文件:java.nio.file 库介绍
    5款冷门但是非常好用的Windows软件推荐
    qt.qpa.plugin:找不到Qt平台插件“wayland“|| (下载插件)Ubuntu上解决方案
    ECK安装elasticsearch集群及es配置x-pack
  • 原文地址:https://blog.csdn.net/weixin_52236586/article/details/133974893