Skip to content

Commit 6e1c6cf

Browse files
committed
Fix: remove support for ES6 - resolves #5167
1 parent d34a039 commit 6e1c6cf

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

src/DIRAC/Core/Utilities/ElasticSearchDB.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
import functools
1212
import json
1313

14-
try:
14+
try:
1515
from opensearchpy import OpenSearch as Elasticsearch
1616
from opensearch_dsl import Search, Q, A
1717
from opensearchpy.exceptions import ConnectionError, TransportError, NotFoundError, RequestError
1818
from opensearchpy.helpers import BulkIndexError, bulk
19-
except ImportError:
20-
from elasticsearch import Elasticsearch
19+
except ImportError:
20+
from elasticsearch import Elasticsearch
2121
from elasticsearch_dsl import Search, Q, A
2222
from elasticsearch.exceptions import ConnectionError, TransportError, NotFoundError, RequestError
2323
from elasticsearch.helpers import BulkIndexError, bulk
@@ -53,8 +53,7 @@ def generateDocs(data, withTimeStamp=True):
5353
:return: doc
5454
"""
5555
for doc in copy.deepcopy(data):
56-
if "_type" not in doc:
57-
doc["_type"] = "_doc"
56+
5857
if withTimeStamp:
5958
if "timestamp" not in doc:
6059
sLog.warn("timestamp is not given")
@@ -231,7 +230,7 @@ def update(self, index, query=None, updateByQuery=True, id=None):
231230
if updateByQuery:
232231
esDSLQueryResult = self.client.update_by_query(index=index, body=query)
233232
else:
234-
esDSLQueryResult = self.client.index(index=index, doc_type="_doc", body=query, id=id)
233+
esDSLQueryResult = self.client.index(index=index, body=query, id=id)
235234
return S_OK(esDSLQueryResult)
236235
except RequestError as re:
237236
return S_ERROR(re)
@@ -343,11 +342,8 @@ def createIndex(self, indexPrefix, mapping=None, period="day"):
343342

344343
try:
345344
sLog.info("Create index: ", fullIndex + str(mapping))
346-
try:
347-
self.client.indices.create(index=fullIndex, body={"mappings": mapping}) # ES7
348-
except RequestError as re:
349-
if re.error == "mapper_parsing_exception":
350-
self.client.indices.create(index=fullIndex, body={"mappings": {"_doc": mapping}}) # ES6
345+
self.client.indices.create(index=fullIndex, body={"mappings": mapping}) # ES7
346+
351347
return S_OK(fullIndex)
352348
except Exception as e: # pylint: disable=broad-except
353349
sLog.error("Can not create the index:", repr(e))
@@ -388,7 +384,7 @@ def index(self, indexName, body=None, docID=None):
388384
return S_ERROR("Missing index or body")
389385

390386
try:
391-
res = self.client.index(index=indexName, doc_type="_doc", body=body, id=docID)
387+
res = self.client.index(index=indexName, body=body, id=docID)
392388
except (RequestError, TransportError) as e:
393389
sLog.exception()
394390
return S_ERROR(e)

src/DIRAC/MonitoringSystem/DB/MonitoringDB.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,7 @@ def getKeyValues(self, monitoringType):
138138
docs = retVal["Value"]
139139
self.log.debug("Doc types", docs)
140140
monfields = self.documentTypes[monitoringType]["monitoringFields"]
141-
142-
try:
143-
properties = docs[monitoringType]["properties"] # "old" way, with ES types == Monitoring types
144-
except KeyError:
145-
try:
146-
properties = docs["_doc"]["properties"] # "ES6" way, with ES types == '_doc'
147-
except KeyError:
148-
properties = docs["properties"] # "ES7" way, no types
141+
properties = docs["properties"] # "ES7" way, no types
149142

150143
for i in properties:
151144
if i not in monfields and not i.startswith("time") and i != "metric":

0 commit comments

Comments
 (0)