ElasticSearchDB

This class a wrapper around elasticsearch-py. It is used to query Elasticsearch database.

class DIRAC.Core.Utilities.ElasticSearchDB.ElasticSearchDB(host, port, user=None, password=None, indexPrefix='', useSSL=True)

Bases: object

class ElasticSearchDB
Parameters:
  • url (str) – the url to the database for example: el.cern.ch:9200
  • gDebugFile (str) – is used to save the debug information to a file
  • timeout (int) – the default time out to Elasticsearch
  • RESULT_SIZE (int) – The number of data points which will be returned by the query.
RESULT_SIZE = 10000
__init__(host, port, user=None, password=None, indexPrefix='', useSSL=True)

c’tor :param self: self reference :param str host: name of the database for example: MonitoringDB :param str port: The full name of the database for example: ‘Monitoring/MonitoringDB’ :param str user: user name to access the db :param str password: if the db is password protected we need to provide a password :param str indexPrefix: it is the indexPrefix used to get all indexes :param bool useSSL: We can disable using secure connection. By default we use secure connection.

bulk_index(indexprefix, doc_type, data, mapping=None, period=None)
Parameters:
  • indexPrefix (str) – index name.
  • doc_type (str) – the type of the document
  • data (list) – contains a list of dictionary
  • period (str) – We can specify which kind of indices will be created. Currently only daily and monthly indexes are supported.
Paran dict mapping:
 

the mapping used by elasticsearch

clusterName = ''
createIndex(indexPrefix, mapping, period=None)
Parameters:
  • indexPrefix (str) – it is the index name.
  • mapping (dict) – the configuration of the index.
  • period (str) – We can specify, which kind of index will be created. Currently only daily and monthly indexes are supported.
deleteIndex(indexName)

:param str indexName the name of the index to be deleted…

exists(indexName)

it checks the existance of an index :param str indexName: the name of the index

getDocTypes(indexName)

:param str indexName is the name of the index… :return S_OK or S_ERROR

getIndexPrefix()

It returns the DIRAC setup.

getIndexes()

It returns the available indexes…

getUniqueValue(indexName, key, orderBy=False)

:param str indexName the name of the index which will be used for the query :param dict orderBy it is a dictionary in case we want to order the result {key:’desc’} or {key:’asc’} It returns a list of unique value for a certain key from the dictionary.

index(indexName, doc_type, body)
Parameters:
  • indexName (str) – the name of the index to be used…
  • doc_type (str) – the type of the document
  • body (dict) – the data which will be indexed
Returns:

the index name in case of success.

pingDB()

Try to connect to the database :return: S_OK(TRUE/FALSE)

query(index, query)

Executes a query and returns its result (uses ES DSL language).

Parameters:
  • self – self reference
  • index (basestring) – index name
  • query (dict) – It is the query in ElasticSearch DSL language
DIRAC.Core.Utilities.ElasticSearchDB.generateFullIndexName(indexName, period=None)

Given an index prefix we create the actual index name. Each day an index is created. :param str indexName: it is the name of the index :param str period: We can specify, which kind of indexes will be created.

Currently only daily and monthly indexes are supported.