ElasticDB

ElasticDB is a base class used to connect an Elasticsearch database and manages queries.

class DIRAC.Core.Base.ElasticDB.ElasticDB(dbname, fullName, indexPrefix='')

Bases: DIRAC.Core.Utilities.ElasticSearchDB.ElasticSearchDB

class ElasticDB
Parameters:
  • __dbHost (str) – the host name of the Elasticsearch database
  • __dbPort (str) – The port where the Elasticsearch database is listening
  • clusterName (str) – The name of the cluster.
RESULT_SIZE = 10000
__init__(dbname, fullName, indexPrefix='')

c’tor

Parameters:
  • self – self reference
  • dbName (str) – name of the database for example: MonitoringDB
  • fullName (str) – The full name of the database for example: ‘Monitoring/MonitoringDB’

:param str indexPrefix it is the indexPrefix used to get all indexes

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

getDbHost()

It returns the elasticsearch database host

getDbPort()
It returns the database port
Parameters:self – self reference
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
setDbHost(hostName)
It is used to set the cluster host
Parameters:hostname (str) – it is the host name of the elasticsearch
setDbPort(port)

It is used to set the cluster port

param self:self reference
param str port:the port of the elasticsearch.