删除记录

删除单条记录,代码如下:

# 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

查看所有标签

社交天性

社交天性

[美] 马修·利伯曼(Matthew D. Lieberman) / 贾拥民 / 浙江人民出版社 / 2016-6 / 69.90

[内容简介] ● 《社交天性》是社会心理学家马修·利伯曼解读人类“社会脑”的权威之作,它告诉我们为什么在充满合作与竞争的智慧社会中人们喜爱社交又相互连接,个人的社会影响力如何得以发挥,书中处处充满了令人惊喜的洞见。 ● 为什么有的人天生善于社交,而有的人总是充满障碍? 为什么智商越高的人越难相处? 心痛对人的伤害甚至超过头痛? 慈善组织如何激发人们的捐赠行为? ......一起来看看 《社交天性》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试