from elasticsearch import Elasticsearch, helpers
es = Elasticsearch()
def mybulk_delete(q, index, doc_type):
res = helpers.scan(es,
query={"query": q},
index=index, doc_type= doc_type)
for r in res:
yield {"delete" : { "_index" : r["_index"], "_type" : r["_type"], "_id" : r["_id"] } }
q = {"query":{"term":{"user":"kimchy"}}}
k = (i for i in mybulk_delete(q,"myindex", "mytype"))
helpers.bulk(es, k, refresh = True)
>>> set([1,2,3,4,5,6,7]) - set([1,2,3,4,5])
set([6, 7])
>>>
select ID from mytable
MacBook-Pro:~ leah$ python -m timeit 'set(range(1,1000022)) - set(range(1,1000000))'
10 loops, best of 3: 166 msec per loop
MacBook-Pro:~ leah$
MacBook-Pro:~ leah$ host habrahabr.ru
habrahabr.ru has address 178.248.237.68
habrahabr.ru mail is handled by 10 mxs.habramail.net.
MacBook-Pro:~ leah$ host toster.ru
toster.ru has address 178.248.232.5
toster.ru mail is handled by 10 mxs.habramail.net.
MacBook-Pro:~ leah$ whois 178.248.232.5
% IANA WHOIS server
% for more information on IANA, visit http://www.iana.org
% This query returned 1 object
refer: whois.ripe.net
inetnum: 178.0.0.0 - 178.255.255.255
organisation: RIPE NCC
status: ALLOCATED
whois: whois.ripe.net
changed: 2009-01
source: IANA
% This is the RIPE Database query service.
% The objects are in RPSL format.
%
% The RIPE Database is subject to Terms and Conditions.
% See http://www.ripe.net/db/support/db-terms-conditions.pdf
% Note: this output has been filtered.
% To receive output for a database update, use the "-B" flag.
% Information related to '178.248.232.5 - 178.248.232.5'
% Abuse contact for '178.248.232.5 - 178.248.232.5' is 'abuse@qrator.net'
inetnum: 178.248.232.5 - 178.248.232.5
netname: QRATOR-903
descr: 0
descr: 0
country: RU
admin-c: LA27-RIPE
tech-c: AA8879-RIPE
status: ASSIGNED PA
mnt-by: MNT-QRATOR
created: 2012-11-09T15:11:32Z
last-modified: 2012-11-09T15:11:32Z
source: RIPE # Filtered
person: Alexander Asimov
address: 1-y Magistralnyy tupik 5A, Suite D/304
address: Moscow 123290
address: Russian Federation
mnt-by: MNT-QRATOR
phone: +7-499-241-81-92
nic-hdl: AA8879-RIPE
created: 2010-06-17T17:01:11Z
last-modified: 2017-05-12T11:55:33Z
source: RIPE # Filtered
person: Lyamin Alex
address: 1-y Magistralnyy tupik 5A, Suite D/304
address: Moscow 123290
address: Russian Federation
phone: +7-499-241-8192
nic-hdl: LA27-RIPE
mnt-by: MNT-QRATOR
created: 1970-01-01T00:00:00Z
last-modified: 2017-05-12T11:58:17Z
source: RIPE # Filtered
% Information related to '178.248.232.5/32AS197068'
route: 178.248.232.5/32
descr: "HLL" LLC
origin: AS197068
mnt-by: MNT-QRATOR
created: 2011-07-28T10:43:55Z
last-modified: 2011-07-28T10:43:55Z
source: RIPE
% This query was served by the RIPE Database Query Service version 1.90 (WAGYU)
MacBook-Pro:~ leah$