"query": { "filtered": { "filter": { "type": { "value": type_ } } } } }) ids = [x["_id"] for x in response["hits"]["hits"]] bulk_body = [ '{{"delete": {{"_index": "{}", "_type": "{}", "_id": "{}"}}}}'. format(index, type_, x) for x in ids ] es.bulk('\n'.join(bulk_body)) # es.indices.flush_synced([index]) except elasticsearch.ElasticsearchException as ex: print("Elasticsearch error: " + ex.error) raise ex if __name__ == '__main__': print 'Current records:' listAll(es, 'bpnm') #listAll(es, 'filebeat-2016.12.06') print '--------' #insertTestData(es, 'test1', 'testDocType') # delete_es_type(es, 'test1', 'testType') print es.exists_type(index='bpnm', doc_type='BPStats')