索引新增记录
Python 操作 ElasticSearch 简明教程
· 2019-01-22 17:40:16
索引新增单条记录,代码如下:
# encoding:utf-8
#!/usr/bin/python
from elasticsearch import Elasticsearch
class ElasticObj:
def __init__(self, index_name, index_type, ip ="127.0.0.1"):
'''
:param index_name: 索引名称
:param index_type: 索引类型
'''
self.index_name =index_name
self.index_type = index_type
# 无用户名密码状态
self.es = Elasticsearch([ip])
#用户名密码状态
# self.es = Elasticsearch([ip],http_auth=('elastic', 'password'),port=9200)
'''
索引数据
'''
def Index_Data(self):
list = [
{
"id":1,
"url":'https://www.codercto.com/courses/d/61.html',
"title": "Eloquent: 入门"
},
{
"id":2,
"url":'https://www.codercto.com/courses/d/62.html',
"title": "Eloquent: 模型关联"
},
]
for item in list:
res = self.es.index(index=self.index_name, doc_type=self.index_type, body=item, id=item['id'])
print(res)
if __name__ == "__main__":
obj =ElasticObj("test", "test_type", ip ="127.0.0.1")
obj.Index_Data()
执行结果:
{u'_type': u'test_type', u'_seq_no': 0, u'_shards': {u'successful': 1, u'failed': 0, u'total': 2}, u'_index': u'test', u'_version': 1, u'_primary_term': 1, u'result': u'created', u'_id': u'1'}
{u'_type': u'test_type', u'_seq_no': 0, u'_shards': {u'successful': 1, u'failed': 0, u'total': 2}, u'_index': u'test', u'_version': 1, u'_primary_term': 1, u'result': u'created', u'_id': u'2'}
点击查看所有 Python 操作 ElasticSearch 简明教程 文章: https://codercto.com/courses/l/6.html
计算机程序设计艺术(第3卷)-排序和查找(英文影印版)
(美)Donald E.Knuth / 清华大学出版社 / 2002-9 / 85.00元
《计算机程序设计艺术排序和查找(第3卷)(第2版)》内容简介:这是对第3卷的头一次修订,不仅是对经典计算机排序和查找技术的最全面介绍,而且还对第1卷中的数据结构处理技术作了进一步的扩充,通盘考虑了将大小型数据库和内外存储器。它遴选了一些经过反复检验的计算机方法,并对其效率做了定量分析。第3卷的突出特点是对“最优排序”一节作了修订,对排列论原理与通用散列法作了全新讨论。一起来看看 《计算机程序设计艺术(第3卷)-排序和查找(英文影印版)》 这本书的介绍吧!
MD5 加密
MD5 加密工具
HSV CMYK 转换工具
HSV CMYK互换工具