Note: May need to place the notebook into the idb-backend to run properly.
In [1]:
from __future__ import division, absolute_import, print_function
from pytz import timezone
import elasticsearch
import elasticsearch.helpers
from idb import config
from idb.helpers.logging import idblogger
from idb.helpers.conversions import fields, custom_mappings
In [2]:
# u = "4dce41dc-2af6-448c-99e1-abfd3a9cc3e5"
u = "db4bb0df-8539-4617-ab5f-eb118aa3126b"
In [3]:
serverlist = config.config["elasticsearch"]["servers"]
In [4]:
def get_connection(**kwargs):
kwargs.setdefault('hosts', config.config["elasticsearch"]["servers"])
kwargs.setdefault('retry_on_timeout', True) # this isn't valid until >=1.3
kwargs.setdefault('sniff_on_start', False)
kwargs.setdefault('sniff_on_connection_fail', False)
kwargs.setdefault('max_retries', 10)
kwargs.setdefault('timeout', 30)
return elasticsearch.Elasticsearch(**kwargs)
In [5]:
conn = get_connection(hosts=serverlist)
In [6]:
r = conn.search(index="idigbio", doc_type="recordsets", _source=["etag"], body={
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field": "_id",
"query": u
}
}
],
"must_not": [],
"should": []
}
},
"from": 0,
"size": 10,
"sort": [],
"aggs": {}
})
In [7]:
r['hits']
Out[7]:
This from Nathan's example of deleting a mediarecord where we need the parent record:
In [8]:
# parent = r['hits']['hits'][0]['_parent']
# conn.delete(index='idigbio', id=u, parent=parent, doc_type='mediarecords')
In [34]:
conn.delete(index='idigbio', id=u, doc_type='recordsets')
In [ ]: