03-用户画像+Elasticsearch

优点

  • es支持海量数据的写入和更新
  • es可以和hadoop,hive及spark进行集成
  • es支持hivesql的操作,可以通过hivesql将数据导入es
  • es的在进行数据检索查询是速度比较快
  • es是分布式存储

应用

全文检索

全文检索流程:

1-对文档数据(文本数据)进行分词

2-将分词数据建立索引

3-根据分词查询数据

官网 https://www.elastic.co/cn/

ES 分布式搜索服务 文本数据存储

  • 存储单元 shard 分片
  • 副本 默认 2
    • 主分片 副本分片
  • 索引 相同类型数据 先创建索引,然后存储数据
  • 元数据
    • 分片信息,datanode信息
      • 被master管理
  • 自己内部有选举算法实现master选举

es启动命令

python 复制代码
su es
cd
elasticsearch -d

es客户端工具使用

启动

在浏览器输入网址

Pycharm的客户端插件


python 复制代码
# 创建索引
PUT itcast


# 写入 数据
POST itcast/_doc
{
  "name": "张飒",
  "age": 20
}

# 查询数据
GET itcast/_search

# 删除索引
DELETE itcast

# 查看索引配置
GET itcast/_settings

# 修改索引配置
PUT itcast/_settings
{
  "number_of_replicas": "0"
}

elasticsearch 模块安装

python 复制代码
pip install elasticsearch==7.17.3 -i https://mirrors.aliyun.com/pypi/simple

开发

python 复制代码
# 导入模块
# Elasticsearch类封装了操作es的方法
from elasticsearch import Elasticsearch
# 1、创建索引库
es = Elasticsearch(hosts=['192.168.88.166:9200'])
# index='itheima' 指定索引库名
# id=1 指定数据id
# document 指定数据内容
# res = es.index(index='itheima',id=1,document={'name':'张三','age':20,'gender':'男性'})
res = es.index(index='itheima',id=2,document='{"name":"李四","age":22,"gender":"男性"}')
# 查看创建后的信息
# print(res)

# 2、查询创建的数据
# 返回的结果是字典类型,可以按照字典方式进行取值
# 查询所有数据
res = es.search(index='itheima')
print(res["hits"]['hits'][0]['_source'])

# 2-1 按照指定一个字段查询
res = es.search(index='itheima',query={'match':{'name':"李四"}})
print(res["hits"]['hits'][0]['_source'])

# 2-2 按照指定多个字段查询
res = es.search(index='itheima',query={'multi_match':{'query':"李四",'fields':["name",'gender']}})
print(res["hits"]['hits'][0]['_source'])

# 2-3 指定id查询
res = es.get(index='itheima',id=1)
print(res['_source'])
相关推荐
-今昭-15 分钟前
AnsibleVault加密配置及zabbix部署
大数据·elasticsearch·搜索引擎
瑞通软件源头厂家1 小时前
酒店管理软件如何实现动态定价:功能解析与运作机制
大数据·创业创新
我一定会有钱1 小时前
打造完美工作流:Git 配置”一次推送,三端同步”(Gitee/GitCode/GitHub)
开发语言·windows·vscode·搜索引擎·gitlab·github·visual studio code
hzxpaipai2 小时前
杭州GEO网站建设哪家好:面向搜索引擎与AI推荐的
搜索引擎
OceanBase数据库官方博客2 小时前
OceanBase Harness Engineering?AI 产品真正的瓶(技术解析与实践)
大数据·人工智能·oceanbase
IT学长编程2 小时前
计算机毕业设计 基于用户评论主题挖掘的旅游景点推荐系统 Python 大数据毕业设计 Hadoop毕业设计选题【附源码+文档报告+安装调试】
大数据·python·django·毕业设计·数据可视化分析·旅游景点推荐系统·基于用户评论主题挖掘
才聚PMP2 小时前
深陷技术内卷难突围?AI+项目管理开辟增值新赛道!
大数据·人工智能
飞飞传输2 小时前
机器人行业数据流转深度研究:内外网数据摆渡平台应用现状与趋势
大数据·运维·安全
长谷深风1113 小时前
Agent 何时该 Replan:五个关键判断
java·大数据·开发语言·ai agent·ai智能体·agent设计·clarify机制
兴趣使然黄小黄3 小时前
【AI-agent】让 AI 输出可依赖:LLM 工程化的四道防线
大数据·人工智能