python中的Elasticsearch操作汇总
2019-10-31 07:05
1556 查看
这篇文章主要介绍了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)
以上就是本文的全部内容,希望对大家的学习有所帮助
您可能感兴趣的文章:
相关文章推荐
- Python 操作 ElasticSearch的完整代码
- Selenium+python操作浏览器问题汇总
- python 字符串常用操作汇总
- python文件操作汇总
- 第三百六十二节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)基本的索引和文档CRUD操作、增、删、改、查
- python的文件操作方法汇总
- python中os操作文件及文件路径实例汇总
- Python对ElasticSearch获取数据及操作
- Python字符串操作汇总
- Elasticsearch --- 3. ik中文分词器, python操作es
- python基础汇总(三)(补充)——字符串的27种常见操作
- python之string操作汇总
- python基础汇总(五)——文件读写、备份,批量修改文件夹,os模块操作
- 工作记录-Python操作Elasticsearch (安装篇)
- python中selenium操作下拉滚动条方法汇总
- 【问题汇总】python操作hbase脚本
- python中os操作文件及文件路径实例汇总
- 使用python操作elasticsearch实现监控数据及kibana分析
- python中os操作文件及文件路径实例汇总
- python操作Elasticsearch