Use generic meta variable for returning more data about the search

This commit is contained in:
2023-01-16 07:20:37 +00:00
parent bea84ee2b6
commit 2eb090f088
3 changed files with 20 additions and 17 deletions

View File

@@ -309,20 +309,21 @@ class ElasticsearchBackend(StorageBackend):
if len(response["hits"]["hits"]) == 0:
# No results, skip
continue
aggs, response = self.parse(response, aggs=True)
meta, response = self.parse(response, meta=True)
print("Parsed response", response)
if "message" in response:
self.log.error(f"Error running scheduled search: {response['message']}")
continue
result_map[index] = (aggs, response)
result_map[index] = (meta, response)
# Average aggregation check
# Could probably do this in elasticsearch
for index, (aggs, result) in result_map.items():
for index, (meta, result) in result_map.items():
# Default to true, if no aggs are found, we still want to match
match = True
for agg_name, (operator, number) in rule_object.aggs.items():
if agg_name in aggs:
agg_value = aggs[agg_name]["value"]
if agg_name in meta:
agg_value = meta["aggs"][agg_name]["value"]
# TODO: simplify this, match is default to True
if operator == ">":
@@ -345,7 +346,7 @@ class ElasticsearchBackend(StorageBackend):
else:
# No aggregation found, but it is required
match = False
result_map[index][0][agg_name]["match"] = match
result_map[index][0]["aggs"][agg_name]["match"] = match
return result_map