Skip to content

Commit

Permalink
Fixing get_hits_count for es 7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffAshton committed Jul 7, 2021
1 parent 3df7643 commit 16549c7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "elastalert.elastalert",
"args": [
"--config",
"../elastalert_config/opensearch/config.yaml"
],
"env": {
"AWS_ACCESS_KEY_ID": "A",
"AWS_SECRET_ACCESS_KEY": "K"
}
}
]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true
}
15 changes: 14 additions & 1 deletion elastalert/elastalert.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,21 @@ def get_hits_count(self, rule, starttime, endtime, index):
five=rule['five']
)

es_client = self.thread_data.current_es
try:
res = self.thread_data.current_es.count(index=index, doc_type=rule['doc_type'], body=query, ignore_unavailable=True)
if es_client.is_atleastsixsix():
res = es_client.count(
index=index,
body=query,
ignore_unavailable=True
)
else:
res = es_client.count(
index=index,
doc_type=rule['doc_type'],
body=query,
ignore_unavailable=True
)
except ElasticsearchException as e:
# Elasticsearch sometimes gives us GIGANTIC error messages
# (so big that they will fill the entire terminal buffer)
Expand Down

0 comments on commit 16549c7

Please sign in to comment.