-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Experiment: Generic ElasticSearch query #20
Conversation
Signed-off-by: Raul Sevilla <[email protected]>
@@ -7,12 +7,12 @@ | |||
import logging | |||
|
|||
# pylint: disable=import-error | |||
from elasticsearch import Elasticsearch | |||
from elasticsearch7 import Elasticsearch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious about this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think elasticsearch7
can be installed using elasticsearch==7.x.x
, this has been a previous issue for me too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, if you don't specify the module version, the python interpreter just picks the latest one available
else: | ||
q = q & Q("match", **query) | ||
s.query = q | ||
x = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x = None | |
x = None | |
for bucket in buckets: | |
a = A("terms", field=bucket) | |
if x is None: | |
x = s.aggs.bucket(bucket, a) | |
else: | |
x = x.bucket(bucket, a) | |
x.bucket(metric_name, A(agg_type, field=field)) |
@@ -38,6 +38,39 @@ def __init__( | |||
self.es = Elasticsearch([self.es_url], timeout=30) | |||
self.data = None | |||
|
|||
def generic_search(self, queries: list, buckets: list, metric_name: str, agg_type: str, field: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I like this idea. Should be useful in reducing multiple queries to one on a single ES index atleast.
Type of change
Description
Adding a new
generic_search
method to retrieve data from arbitrary queries, arbitrary buckets and arbitrary aggregations. Example of result after running a testing script against our aws dev instancehttps://gist.github.com/rsevilla87/ea63357d1243e1614a2c276eb09c032c
Some benefits:
metadata.ocpMajorVersion.keyword
It's major downside can be the format of the data returned, it's a single JSON document with lots of nested fields, (one per term/metric aggregation. Good thing is that the value of the metric aggregation is returned at the lowest level and the key names are predictable, in this case:
Thoughts??