删除记录
Python 操作 ElasticSearch 简明教程
· 2019-01-22 18:07:50
删除单条记录,代码如下:
# 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 Delete(self, id):
print self.es.delete(index=self.index_name, doc_type=self.index_type, id=id)
if __name__ == "__main__":
obj =ElasticObj("test", "test_type", ip ="127.0.0.1")
obj.Delete(1)
执行结果:
{u'_type': u'test_type', u'_seq_no': 2, u'_shards': {u'successful': 1, u'failed': 0, u'total': 2}, u'_index': u'test', u'_version': 3, u'_primary_term': 1, u'result': u'deleted', u'_id': u'1'}
查看数据:
[root@centos7php7 elasticsearch-6.4.2]# curl -X GET 'localhost:9200/test/test_type/1?pretty'
{
"_index" : "test",
"_type" : "test_type",
"_id" : "1",
"found" : false
}
可以看到 ID=1 的记录已经被成功删除。
点击查看所有 Python 操作 ElasticSearch 简明教程 文章: https://codercto.com/courses/l/6.html
30天自制操作系统
[日] 川合秀实 / 周自恒、李黎明、曾祥江、张文旭 / 人民邮电出版社 / 2012-8 / 99.00元
自己编写一个操作系统,是许多程序员的梦想。也许有人曾经挑战过,但因为太难而放弃了。其实你错了,你的失败并不是因为编写操作系统太难,而是因为没有人告诉你那其实是一件很简单的事。那么,你想不想再挑战一次呢? 这是一本兼具趣味性、实用性与学习性的书籍。作者从计算机的构造、汇编语言、C语言开始解说,让你在实践中掌握算法。在这本书的指导下,从零编写所有代码,30天后就可以制作出一个具有窗口系统的32位......一起来看看 《30天自制操作系统》 这本书的介绍吧!