基于python操作ES实例详解
作者:太虚真人 时间:2021-01-06 05:08:28
这篇文章主要介绍了基于python操作ES实例详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
安装
pip install elasticsearch5 # 安装对应版本的模块
创建ES对象
from elasticsearch5 import Elasticsearch
# elasticsearch集群服务器的地址
ES = [
'127.0.0.1:9200'
]
# 创建elasticsearch客户端
es = Elasticsearch(
ES,
# 启动前嗅探es集群服务器
sniff_on_start=True,
# es集群服务器结点连接异常时是否刷新es节点信息
sniff_on_connection_fail=True,
# 每60秒刷新节点信息
sniffer_timeout=60
)
搜索数据
query = {
'query': {
'bool': {
'must': [
{'match': {'_all': 'python web'}}
],
'filter': [
{'term': {'status': 2}}
]
}
}
}
ret = es.search(index='articles', doc_type='article', body=query)
添加数据
doc = {
'article_id': article.id,
'user_id': article.user_id,
'title': article.title
}
es.index(index='articles', doc_type='article', body=doc, id=article.id)
来源:https://www.cnblogs.com/oklizz/p/11448389.html
标签:python,操作,ES
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
设计师的幸福
2009-05-21 11:59:00
批处理与python代码混合编程的方法
2023-08-26 10:45:32
Python文件与文件夹常见基本操作总结
2023-08-08 16:56:09
Python地图四色原理的遗传算法着色实现
2022-10-07 20:57:45
![](https://img.aspxhome.com/file/2023/5/75955_0s.jpg)
对学好网页设计很有价值的一句话
2007-10-28 16:04:00
![](https://img.aspxhome.com/file/UploadPic/200710/28/2007102816649948s.jpg)
Python文件处理
2022-08-08 10:22:01
Python math库 ln(x)运算的实现及原理
2023-09-11 18:12:28
![](https://img.aspxhome.com/file/2023/8/70228_0s.png)
Oracle客户端 NLS_LANG 的设置方法
2012-07-11 15:55:27
python实现滑雪游戏
2021-10-08 05:20:35
Laravel实现队列的示例代码
2023-05-28 04:39:21
Python实现多张图片合成一张马赛克图片
2022-02-15 21:09:46
![](https://img.aspxhome.com/file/2023/7/68287_0s.gif)
不能安装SQL Server 2005的问题及解决方法
2008-12-26 17:41:00
也谈谈DIV+CSS的牛角尖
2007-11-16 16:12:00
PyG搭建GCN模型实现节点分类GCNConv参数详解
2022-08-22 19:58:49
![](https://img.aspxhome.com/file/2023/2/97702_0s.png)
在MySQL数据库中如何修改密码及访问限制
2008-11-27 16:36:00
深入研究WINDOW.EVENT对象
2012-04-26 16:31:58
浏览器针对单服务器连接数问题
2008-05-12 22:27:00
Python3导入自定义模块的三种方法详解
2021-06-05 18:49:27
![](https://img.aspxhome.com/file/2023/3/86533_0s.png)
基于Python实现自动扫雷详解
2023-09-07 23:31:20
![](https://img.aspxhome.com/file/2023/9/86389_0s.gif)
sql处理数据库锁的存储过程分享
2023-07-05 18:03:25