ElasticSearchDB¶
This class a wrapper around elasticsearch-py. It is used to query Elasticsearch instances.
- class DIRAC.Core.Utilities.ElasticSearchDB.ElasticSearchDB(host, port, user=None, password=None, indexPrefix='', useSSL=True, useCRT=False, ca_certs=None, client_key=None, client_cert=None)¶
Bases:
object
- class ElasticSearchDB¶
- Parameters
- RESULT_SIZE = 10000¶
- __init__(host, port, user=None, password=None, indexPrefix='', useSSL=True, useCRT=False, ca_certs=None, client_key=None, client_cert=None)¶
c’tor
- Parameters
self – self reference
host (str) – name of the database for example: MonitoringDB
port (str) – The full name of the database for example: ‘Monitoring/MonitoringDB’
user (str) – user name to access the db
password (str) – if the db is password protected we need to provide a password
indexPrefix (str) – it is the indexPrefix used to get all indexes
useSSL (bool) – We can disable using secure connection. By default we use secure connection.
useCRT (bool) – Use certificates.
ca_certs (str) – CA certificates bundle.
client_key (str) – Client key.
client_cert (str) – Client certificate.
- bulk_index(indexPrefix, data=None, mapping=None, period='day', withTimeStamp=True)¶
- Parameters
- Returns
S_OK/S_ERROR
- clusterName = ''¶
- createIndex(indexPrefix, mapping=None, period='day')¶
- deleteByQuery(indexName, query)¶
Delete data by query (careful!)
- existingIndex(indexName)¶
Checks the existance of an index, by its name
- Parameters
indexName (str) – the name of the index
- Returns
S_OK/S_ERROR if the request is successful
- static generateFullIndexName(indexName, period)¶
Given an index prefix we create the actual index name.
- getDocTypes(indexName)¶
Returns mappings, by index.
- Parameters
indexName (str) – is the name of the index…
- Returns
S_OK or S_ERROR
- getIndexPrefix()¶
It returns the DIRAC setup.
- getIndexes(indexName=None)¶
It returns the available indexes…
- getUniqueValue(indexName, key, orderBy=False)¶
- index(indexName, body=None, docID=None, op_type='index')¶
- pingDB()¶
Try to connect to the database
- Returns
S_OK(TRUE/FALSE)
- query(index, query)¶
Executes a query and returns its result (uses ES DSL language).
- update(index, query=None, updateByQuery=True, id=None)¶
Executes an update of a document, and returns S_OK/S_ERROR
- DIRAC.Core.Utilities.ElasticSearchDB.generateDocs(data, withTimeStamp=True)¶
Generator for fast bulk indexing, yields docs
- DIRAC.Core.Utilities.ElasticSearchDB.ifConnected(method)¶
Decorator for checking that the connection is established.