python中的Elasticsearch操作汇总
作者:simpleknight 时间:2022-01-29 10:44:45
这篇文章主要介绍了python中的Elasticsearch操作汇总,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
导入包
from elasticsearch import Elasticsearch
本地连接
es = Elasticsearch(['127.0.0.1:9200'])
创建索引
es.indices.create(index="python_es01",ignore=400)
ingore=400 ingore是忽略的意思,400是未找到
删除索引
es.indices.delete(index="python_es01")
检查索引是否存在
es.indices.exists(index="python_es01")
插入数据
es.index(index="python_es01",doc_type="doc",id=1,body={"name":"kitty","age":50})
同时也可以不加id,即
es.index(index="python_es01",doc_type="doc",body={"name":"kitty","age":10})
查询操作
按id查询
result = es.get(index="python_es01",doc_type="doc",id=1)
会有一个返回值
全查
body= {
"query":{
"match_all":{}
}
}
result = es.search(index="python_es01",body=body)
使用id的用GET,其他search
删除操作
result = es.delete(index="goods",doc_type="type1",id=2)
按查询结果删除
result = es.delete_by_query(index="goods",body=body)
建立mapping
body = {
"mappings": {
"properties": {
"name": {
"type": "text"
},
"price": {
"type": "long"
}
}
}
}
result = es.indices.create(index="shang",body=body)
来源:https://www.cnblogs.com/simplekinght/p/11726314.html
标签:python,elasticsearch,操作
0
投稿
猜你喜欢
快速掌握ASP+Access数据库的18条安全法则
2008-11-28 15:08:00
网页设计标准尺寸
2008-06-15 15:21:00
Python机器学习算法库scikit-learn学习之决策树实现方法详解
2023-07-26 20:44:28
php调用快递鸟接口实例代码
2023-11-17 13:48:49
Python+OpenCV实现信用卡数字识别的方法详解
2022-01-15 14:25:41
形成视觉冲击的几种方式
2008-08-03 15:57:00
Python编程产生非均匀随机数的几种方法代码分享
2023-02-10 02:00:19
Django搭建项目实战与避坑细节详解
2021-04-30 06:46:46
python 爬取英雄联盟皮肤并下载的示例
2023-07-22 09:57:45
网页中的平衡、对比、连贯和留白
2008-11-24 12:11:00
ASP网站数据采集经验谈
2008-03-09 15:30:00
关于递归运算的顺序测试代码
2023-08-24 13:04:16
asp如何直接调用后台存储过程?
2010-06-28 18:27:00
Python获取航线信息并且制作成图的讲解
2023-08-28 18:18:56
利用Python批量生成任意尺寸的图片
2021-02-14 11:20:12
python实现的B站直播录制工具
2023-05-29 00:51:48
网页中空格的烦恼
2011-04-28 09:26:00
python运行其他程序的实现方法
2022-11-15 05:18:09
在ASP中使用SQL语句之11:记录统计
2007-08-11 13:27:00
如何做一个文本搜索?
2010-07-12 19:00:00