Python创建ES索引
2023-09-27 14:28:13 时间
# pip install elasticsearch from datetime import datetime from elasticsearch import Elasticsearch es_servers = [{ "host": "10.10.6.225", "port": "9200" }] es = Elasticsearch(es_servers) doc = { 'author': 'kimchy', 'text': 'Elasticsearch: cool. bonsai cool.', 'timestamp': datetime.now(), } res = es.index(index="test-index", doc_type='tweet', id=1, body=doc) print(res) res = es.get(index="test-index", doc_type='tweet', id=1) print(res['_source']) es.indices.refresh(index="test-index") res = es.search(index="test-index", body={"query": {"match_all": {}}}) print("Got %d Hits:" % res['hits']['total']) for hit in res['hits']['hits']: print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])
相关文章
- 四、OCR-docker部署最新版PaddleServing和PaddleOCR,服务端,客户端,dockerfile部署-pipeline python部署,GPU运行
- 使用python生成大量数据写入es数据库并查询操作(聚合)
- python中静态方法staticmethod用法详解
- Python: stack
- 使用 Python 实现电梯调度的核心算法【100010451】
- Andrew Ng-机器学习基础笔记(上)-Python实现代码
- Sublime Text 3 插件安装、搭建Python、Java开发环境
- python使用列表实现移动平均
- Python模块_import语句_from...import 函数名_from ... import *
- caffe添加自己编写的Python层
- 感知哈希算法——Python实现